Class: ShEx::Algebra::Or
- Includes:
- ShapeExpression
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb
Constant Summary collapse
- NAME =
:or
Constants inherited from Operator
ShEx::Algebra::Operator::ARITY
Constants included from SPARQL::Algebra::Expression
SPARQL::Algebra::Expression::PATTERN_PARENTS
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes inherited from Operator
#id, #logger, #operands, #options, #schema
Class Method Summary collapse
-
.from_shexj(operator, **options) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation.
Instance Method Summary collapse
-
#initialize(*args, **options) ⇒ Or
constructor
A new instance of Or.
- #json_type ⇒ Object
-
#satisfies?(focus, depth: 0) ⇒ Boolean, ShapeExpression
S is a ShapeOr and there is some shape expression se2 in shapeExprs such that satisfies(n, se2, G, m).
-
#validate! ⇒ Operator
expressions must be ShapeExpressions or references to ShapeExpressions.
Methods included from ShapeExpression
#validate_expressions!, #validate_self_references!
Methods inherited from Operator
#base_uri, #closed?, #dup, #each_descendant, #eql?, #expression, #expressions, #find, #focus, #focus=, #inspect, #iri, iri, #matched, #matched=, #message, #message=, #not_matched, #not_satisfied, #operand, #parent, #parent=, #references, #satisfied, #satisfied=, #satisfy, #semact?, #semantic_actions, #serialize_value, #status, #structure_error, #to_h, #to_json, #to_sxp, #to_sxp_bin, #triple_expression?, #unmatched, #unmatched=, #unsatisfied, #unsatisfied=, value, #value
Methods included from SPARQL::Algebra::Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #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
#initialize(*args, **options) ⇒ Or
Returns a new instance of Or.
7 8 9 10 11 12 13 14 15 16 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb', line 7 def initialize(*args, **) case when args.length < 2 raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 2..)" end # All arguments must be ShapeExpression raise ArgumentError, "All operands must be Shape operands or resource" unless args.all? {|o| o.is_a?(ShapeExpression) || o.is_a?(RDF::Resource)} super end |
Class Method Details
.from_shexj(operator, **options) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation
22 23 24 25 26 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb', line 22 def self.from_shexj(operator, **) raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == 'ShapeOr' raise ArgumentError, "missing shapeExprs in #{operator.inspect}" unless operator.is_a?(Hash) && operator.has_key?('shapeExprs') super end |
Instance Method Details
#json_type ⇒ Object
80 81 82 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb', line 80 def json_type "ShapeOr" end |
#satisfies?(focus, depth: 0) ⇒ Boolean, ShapeExpression
S is a ShapeOr and there is some shape expression se2 in shapeExprs such that satisfies(n, se2, G, m).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb', line 33 def satisfies?(focus, depth: 0) status "", depth: depth unsatisfied = [] expressions.any? do |op| begin matched_op = case op when RDF::Resource schema.enter_shape(op, focus) do |shape| if shape shape.satisfies?(focus, depth: depth + 1) else status "Satisfy as #{op} was re-entered for #{focus}", depth: depth shape end end when ShapeExpression op.satisfies?(focus, depth: depth + 1) end return satisfy focus: focus, satisfied: matched_op, depth: depth rescue ShEx::NotSatisfied => e status "unsatisfied #{focus}", depth: depth op = op.dup if op.respond_to?(:satisfied) op.satisfied = e.expression.satisfied op.unsatisfied = e.expression.unsatisfied end unsatisfied << op status "unsatisfied: #{e.}", depth: depth false end end not_satisfied "Expected some expression to be satisfied", focus: focus, unsatisfied: unsatisfied, depth: depth end |
#validate! ⇒ Operator
expressions must be ShapeExpressions or references to ShapeExpressions
74 75 76 77 78 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/or.rb', line 74 def validate! validate_expressions! validate_self_references! super end |