Class: SPARQL::Algebra::Operator::LangMatches

Inherits:
Binary show all
Includes:
Evaluatable
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/lang_matches.rb

Overview

The SPARQL langMatches operator.

[121] BuiltInCall ::= ... | 'LANGMATCHES' '(' Expression ',' Expression ')'

Examples:

SPARQL Grammar

PREFIX : <http://example.org/#>

SELECT *
{ :x ?p ?v . FILTER langMatches(lang(?v), "en-GB") . }

SSE

(prefix ((: <http://example.org/#>))
  (filter (langMatches (lang ?v) "en-GB")
    (bgp (triple :x ?p ?v))))

See Also:

Constant Summary collapse

NAME =
:langMatches

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Constants included from Expression

Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Evaluatable

#evaluate, #memoize, #replace_aggregate!, #replace_vars!

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, base_uri, #base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #formulae, #initialize, #inspect, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

#apply(language_tag, language_range, **options) ⇒ RDF::Literal::Boolean

Returns true if the language tag (the first operand) matches the language range (the second operand).

Parameters:

Returns:

Raises:

  • (TypeError)

    if either operand is unbound

  • (TypeError)

    if either operand is not a simple literal



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/lang_matches.rb', line 38

def apply(language_tag, language_range, **options)
  raise TypeError, "expected a plain RDF::Literal for language_tag, but got #{language_tag.inspect}" unless language_tag.is_a?(RDF::Literal) && language_tag.simple?
  language_tag = language_tag.to_s.downcase

  raise TypeError, "expected a plain RDF::Literal for language_range, but got #{language_range.inspect}" unless language_range.is_a?(RDF::Literal) && language_range.simple?
  language_range = language_range.to_s.downcase

  case
    # A language range of "*" matches any non-empty language tag.
    when language_range.eql?('*')
      RDF::Literal(!(language_tag.empty?))
    # A language range matches a particular language tag if, in a
    # case-insensitive comparison, it exactly equals the tag, ...
    when language_tag.eql?(language_range)
      RDF::Literal::TRUE
    # ... or if it exactly equals a prefix of the tag such that the
    # first character following the prefix is "-".
    else
      RDF::Literal(language_tag.start_with?(language_range + '-'))
  end
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:



65
66
67
68
69
70
71
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/lang_matches.rb', line 65

def to_sparql(**options)
  "langMatches(" +
    operands.first.to_sparql(**options) +
    ", " +
    operands.last.to_sparql(**options) +
    ")"
end