Class: ShEx::Algebra::TripleConstraint
- Includes:
- TripleExpression
- Defined in:
- lib/shex/algebra/triple_constraint.rb
Constant Summary collapse
- NAME =
:tripleConstraint
Constants inherited from Operator
Instance Attribute Summary
Attributes inherited from Operator
Instance Method Summary collapse
- #inverse? ⇒ Boolean
-
#matches(t) ⇒ Array<RDF::Statement>
In this case, we accept an array of statements, and match based on cardinality.
- #predicate ⇒ Object
- #shape ⇒ Object
- #shape_expr_satisfies?(shape, value) ⇒ Boolean
-
#triple_constraints ⇒ Array<TripleConstraints>
Included TripleConstraints.
Methods included from TripleExpression
#maximum, #minimum, #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
#inverse? ⇒ Boolean
64 65 66 |
# File 'lib/shex/algebra/triple_constraint.rb', line 64 def inverse? operands.include?(:inverse) end |
#matches(t) ⇒ Array<RDF::Statement>
In this case, we accept an array of statements, and match based on cardinality.
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 |
# File 'lib/shex/algebra/triple_constraint.rb', line 13 def matches(t) status "predicate #{predicate}" max = maximum results = t.select do |statement| if max > 0 value = inverse? ? statement.subject : statement.object if statement.predicate == predicate && shape_expr_satisfies?(shape, value) status "matched #{statement.to_sxp}" max -= 1 else status "no match #{statement.to_sxp}" false end else false # matched enough end end # Max violations handled in Shape not_matched "Minimum Cardinality Violation: #{results.length} < #{minimum}" if results.length < minimum # Last, evaluate semantic acts semantic_actions.all? do |op| op.satisfies?(results) end unless results.empty? results end |
#predicate ⇒ Object
52 53 54 |
# File 'lib/shex/algebra/triple_constraint.rb', line 52 def predicate operands.detect {|o| o.is_a?(RDF::URI)} end |
#shape ⇒ Object
68 69 70 |
# File 'lib/shex/algebra/triple_constraint.rb', line 68 def shape operands.detect {|o| o.is_a?(Satisfiable)} end |
#shape_expr_satisfies?(shape, value) ⇒ Boolean
44 45 46 47 48 49 50 |
# File 'lib/shex/algebra/triple_constraint.rb', line 44 def shape_expr_satisfies?(shape, value) shape.nil? || shape.satisfies?(value) rescue ShEx::NotSatisfied => e status "ignore error: #{e.}" logger.recovering = false false end |
#triple_constraints ⇒ Array<TripleConstraints>
Included TripleConstraints
60 61 62 |
# File 'lib/shex/algebra/triple_constraint.rb', line 60 def triple_constraints [self] end |