Class: SPARQL::Algebra::Operator::Lang
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/lang.rb
Overview
The SPARQL lang operator.
[121] BuiltInCall ::= ... | 'LANG' '(' Expression ')'
Constant Summary collapse
- NAME =
:lang
Instance Method Summary collapse
-
#apply(literal, **options) ⇒ RDF::Literal
Returns the language tag of the operand, if it has one.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#evaluate, #memoize, #replace_aggregate!, #replace_vars!
Instance Method Details
#apply(literal, **options) ⇒ RDF::Literal
Returns the language tag of the operand, if it has one.
If the operand has no language tag, returns "".
37 38 39 40 41 42 |
# File 'lib/sparql/algebra/operator/lang.rb', line 37 def apply(literal, **) case literal when RDF::Literal then RDF::Literal(literal.language.to_s) else raise TypeError, "expected an RDF::Literal, but got #{literal.inspect}" end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
49 50 51 |
# File 'lib/sparql/algebra/operator/lang.rb', line 49 def to_sparql(**) "lang(" + operands.first.to_sparql(**) + ")" end |