Class: ShEx::Algebra::OneOf
- Includes:
- TripleExpression
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/one_of.rb
Constant Summary collapse
- NAME =
:oneOf
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
-
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
expr
is a OneOf and there is some shape expressionse2
in shapeExprs such that amatches(T, se2, m)
... -
#validate! ⇒ Operator
expressions must be TripleExpressions or references to TripleExpressions.
Methods included from TripleExpression
#maximum, #minimum, #triple_constraints, #triple_expression?, #validate_expressions!
Methods inherited from Operator
#base_uri, #closed?, #dup, #each_descendant, #eql?, #expression, #expressions, #find, #focus, #focus=, #initialize, #inspect, #iri, iri, #json_type, #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
This class inherits a constructor from ShEx::Algebra::Operator
Class Method Details
.from_shexj(operator, **options) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation
11 12 13 14 15 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/one_of.rb', line 11 def self.from_shexj(operator, **) raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == 'OneOf' raise ArgumentError, "missing expressions in #{operator.inspect}" unless operator.has_key?('expressions') super end |
Instance Method Details
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
expr
is a OneOf and there is some shape expression se2
in shapeExprs such that a matches(T, se2, m)
...
23 24 25 26 27 28 29 30 31 32 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 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/one_of.rb', line 23 def matches(arcs_in, arcs_out, depth: 0) results, satisfied, unsatisfied = [], [], [] num_iters, max = 0, maximum # OneOf is greedy, and consumes triples from every sub-expression, although only one is requred it succeed. Cardinality is somewhat complicated, as if two expressions match, this works for either a cardinality of one or two. Or two passes with just one match on each pass. status "" while num_iters < max matched_something = expressions.select {|o| o.is_a?(TripleExpression) || o.is_a?(RDF::Resource)}.any? do |op| begin op = schema.find(op) if op.is_a?(RDF::Resource) matched_op = op.matches(arcs_in, arcs_out, depth: depth + 1) satisfied << matched_op results += matched_op.matched arcs_in -= matched_op.matched arcs_out -= matched_op.matched status "matched #{matched_op.matched.to_sxp}", depth: depth rescue ShEx::NotMatched => e status "not matched: #{e.}", depth: depth unsatisfied << e.expression false end end break unless matched_something num_iters += 1 status "matched #{results.length} statements after #{num_iters} iterations", depth: depth end # Max violations handled in Shape if num_iters < minimum raise ShEx::NotMatched, "Minimum Cardinality Violation: #{results.length} < #{minimum}" end # Last, evaluate semantic acts semantic_actions.each do |op| op.satisfies?(matched: results, depth: depth + 1) end unless results.empty? satisfy matched: results, satisfied: satisfied, depth: depth rescue ShEx::NotMatched, ShEx::NotSatisfied => e not_matched e., matched: results, unmatched: ((arcs_in + arcs_out).uniq - results), satisfied: satisfied, unsatisfied: unsatisfied, depth: depth end |
#validate! ⇒ Operator
expressions must be TripleExpressions or references to TripleExpressions
72 73 74 75 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/one_of.rb', line 72 def validate! validate_expressions! super end |