Class: ShEx::Algebra::EachOf

Inherits:
Operator show all
Includes:
TripleExpression
Defined in:
lib/shex/algebra/each_of.rb

Constant Summary collapse

NAME =
:eachOf

Constants inherited from Operator

Operator::ARITY

Instance Attribute Summary

Attributes inherited from Operator

#operands, #options, #schema

Instance Method Summary collapse

Methods included from TripleExpression

#maximum, #minimum, #triple_constraints, #triple_expression?

Methods inherited from Operator

#closed?, #each_descendant, #eql?, #first_ancestor, #initialize, #inspect, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfiable?, #semact?, #semantic_actions, #status, #structure_error, #to_sxp, #to_sxp_bin, #triple_expression?, #validate!

Constructor Details

This class inherits a constructor from ShEx::Algebra::Operator

Instance Method Details

#matches(t) ⇒ Array<RDF::Statement>

expr is an EachOf and there is some partition of T into T1, T2,… such that for every expression expr1, expr2,… in shapeExprs, matches(Tn, exprn, m)…

Parameters:

  • t (Array<RDF::Statement>)

Returns:

  • (Array<RDF::Statement>)

Raises:

  • NotMatched, ShEx::NotSatisfied



13
14
15
16
17
18
19
20
21
22
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
# File 'lib/shex/algebra/each_of.rb', line 13

def matches(t)
  status ""
  results = []
  statements = t.dup
  num_iters = 0
  max = maximum

  while num_iters < max
    begin
      matched_this_iter = []
      operands.select {|o| o.is_a?(TripleExpression)}.all? do |op|
        matched = op.matches(statements - matched_this_iter)
        matched_this_iter += matched
      end
      results += matched_this_iter
      statements -= matched_this_iter
      num_iters += 1
      status "matched #{results.length} statements after #{num_iters} iterations"
    rescue NotMatched => e
      log_recover("eachOf: ignore error: #{e.message}", depth: options.fetch(:depth, 0))
      break
    end
  end

  # Max violations handled in Shape
  not_matched "Minimum Cardinality Violation: #{num_iters} < #{minimum}" if
    num_iters < minimum

  # Last, evaluate semantic acts
  semantic_actions.all? do |op|
    op.satisfies?(results)
  end unless results.empty?

  status "each of satisfied"
  results
rescue NotMatched => e
  not_matched(e.message)
  raise
end