Class: SPARQL::Algebra::Operator::Regex
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Regex
- Includes:
- Evaluatable
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/regex.rb
Overview
The SPARQL regex
operator.
[122] RegexExpression ::= 'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
Constant Summary collapse
- NAME =
:regex
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(text, pattern, flags = RDF::Literal(''), **options) ⇒ RDF::Literal::Boolean
Matches
text
against a regular expressionpattern
. -
#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 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
Instance Method Details
#apply(text, pattern, flags = RDF::Literal(''), **options) ⇒ RDF::Literal::Boolean
Matches text
against a regular expression pattern
.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/regex.rb', line 43 def apply(text, pattern, flags = RDF::Literal(''), **) # @see https://www.w3.org/TR/xpath-functions/#regex-syntax raise TypeError, "expected a plain RDF::Literal, but got #{text.inspect}" unless text.is_a?(RDF::Literal) && text.plain? text = text.to_s # TODO: validate text syntax # @see https://www.w3.org/TR/xpath-functions/#regex-syntax raise TypeError, "expected a plain RDF::Literal, but got #{pattern.inspect}" unless pattern.is_a?(RDF::Literal) && pattern.plain? pattern = pattern.to_s # TODO: validate pattern syntax # @see https://www.w3.org/TR/xpath-functions/#flags raise TypeError, "expected a plain RDF::Literal, but got #{flags.inspect}" unless flags.is_a?(RDF::Literal) && flags.plain? flags = flags.to_s # TODO: validate flag syntax = 0 raise NotImplementedError, "unsupported regular expression flag: /s" if flags.include?(?s) # FIXME |= Regexp::MULTILINE if flags.include?(?m) |= Regexp::IGNORECASE if flags.include?(?i) |= Regexp::EXTENDED if flags.include?(?x) RDF::Literal(Regexp.new(pattern, ) === text) end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
72 73 74 75 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/regex.rb', line 72 def to_sparql(**) ops = operands.last.to_s.empty? ? operands[0..-2] : operands "regex(" + ops.to_sparql(delimiter: ', ', **) + ")" end |