Class: SPARQL::Algebra::Operator::StrAfter
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::StrAfter
- Includes:
- Evaluatable
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/strafter.rb
Overview
A SPARQL strafter
operator.
[121] BuiltInCall ::= ... | 'STRAFTER' '(' Expression ',' Expression ')'
Constant Summary collapse
- NAME =
:strafter
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#apply(left, right, **options) ⇒ RDF::Literal
The STRAFTER function corresponds to the XPath fn:substring-after function.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#evaluate, #memoize, #replace_aggregate!, #replace_vars!
Methods inherited from Binary
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, #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(left, right, **options) ⇒ RDF::Literal
The STRAFTER function corresponds to the XPath fn:substring-after function. The arguments must be argument compatible otherwise an error is raised.
For compatible arguments, if the lexical part of the second argument occurs as a substring of the lexical part of the first argument, the function returns a literal of the same kind as the first argument arg1 (simple literal, plain literal same language tag, xsd:string). The lexical form of the result is the substring of the lexcial form of arg1 that follows the first occurrence of the lexical form of arg2. If the lexical form of arg2 is the empty string, this is considered to be a match and the lexical form of the result is the lexical form of arg1.
If there is no such occurrence, an empty simple literal is returned.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/strafter.rb', line 54 def apply(left, right, **) case when !left.compatible?(right) raise TypeError, "expected two RDF::Literal operands, but got #{left.inspect} and #{right.inspect}" when right.to_s.empty? # If the lexical form of arg2 is the empty string, this is considered to be a match and the lexical form of the result is the lexical form of arg1. left when !left.to_s.include?(right.to_s) # If the lexical form of arg2 is the empty string, this is considered to be a match and the lexical form of the result is is the empty string. RDF::Literal("") else parts = left.to_s.split(right.to_s) RDF::Literal(parts.last, datatype: left.datatype, language: left.language) end end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
75 76 77 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/strafter.rb', line 75 def to_sparql(**) "STRAFTER(" + operands.to_sparql(delimiter: ', ', **) + ")" end |