lib/shex/algebra/each_of.rb in shex-0.1.0 vs lib/shex/algebra/each_of.rb in shex-0.2.0
- old
+ new
@@ -5,49 +5,57 @@
NAME = :eachOf
##
# 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)...
#
- # @param [Array<RDF::Statement>] t
+ # @param [Array<RDF::Statement>] statements
# @return [Array<RDF::Statement>]
- # @raise NotMatched, ShEx::NotSatisfied
- def matches(t)
+ # @raise [ShEx::NotMatched]
+ def matches(statements)
status ""
- results = []
- statements = t.dup
- num_iters = 0
- max = maximum
+ results, satisfied, unsatisfied = [], [], []
+ num_iters, max = 0, 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
+ begin
+ matched_op = op.matches(statements - matched_this_iter)
+ satisfied << matched_op
+ matched_this_iter += matched_op.matched
+ rescue ShEx::NotMatched => e
+ status "not matched: #{e.message}"
+ op = op.dup
+ op.unmatched = statements - matched_this_iter
+ unsatisfied << op
+ raise
+ end
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))
+ rescue ShEx::NotMatched => e
+ status "no match after #{num_iters} iterations (ignored)"
break
end
end
# Max violations handled in Shape
- not_matched "Minimum Cardinality Violation: #{num_iters} < #{minimum}" if
- num_iters < minimum
+ if num_iters < minimum
+ raise ShEx::NotMatched, "Minimum Cardinality Violation: #{results.length} < #{minimum}"
+ end
# 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
+ satisfy matched: results, satisfied: satisfied
+ rescue ShEx::NotMatched, ShEx::NotSatisfied => e
+ not_matched e.message,
+ matched: results, unmatched: (statements - results),
+ satisfied: satisfied, unsatisfied: unsatisfied
end
end
end