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
#label, #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
- #inverse? ⇒ Boolean
-
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
In this case, we accept an array of statements, and match based on cardinality.
- #predicate ⇒ Object
- #shape ⇒ Object
-
#triple_constraints ⇒ Array<TripleConstraints>
Included TripleConstraints.
Methods included from TripleExpression
#maximum, #minimum, #triple_expression?
Methods inherited from Operator
#base_uri, #closed?, #each_descendant, #eql?, #first_ancestor, #focus, #focus=, #initialize, #inspect, iri, #iri, #json_type, #matched, #matched=, #message, #message=, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfiable?, #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=, #validate!, #value, value
Constructor Details
This class inherits a constructor from ShEx::Algebra::Operator
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class 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 'lib/shex/algebra/triple_constraint.rb', line 11 def self.from_shexj(operator, = {}) raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == 'TripleConstraint' raise ArgumentError unless operator.has_key?('predicate') super end |
Instance Method Details
#inverse? ⇒ Boolean
83 84 85 |
# File 'lib/shex/algebra/triple_constraint.rb', line 83 def inverse? operands.include?(:inverse) end |
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
In this case, we accept an array of statements, and match based on cardinality.
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 66 67 68 69 70 |
# File 'lib/shex/algebra/triple_constraint.rb', line 23 def matches(arcs_in, arcs_out, depth: 0) status "predicate #{predicate}", depth: depth results, unmatched, satisfied, unsatisfied = [], [], [], [] num_iters, max = 0, maximum statements = inverse? ? arcs_in : arcs_out statements.select {|st| st.predicate == predicate}.each do |statement| break if num_iters == max # matched enough value = inverse? ? statement.subject : statement.object begin shape && (matched_shape = shape.satisfies?(value, depth: depth + 1)) status "matched #{statement.to_sxp}", depth: depth if matched_shape matched_shape.matched = [statement] statement = statement.dup.extend(ReferencedStatement) statement.referenced = matched_shape satisfied << matched_shape end results << statement num_iters += 1 rescue ShEx::NotSatisfied => e status "not satisfied: #{e.message}", depth: depth unsatisfied << e.expression statement = statement.dup.extend(ReferencedStatement) statement.referenced = shape unmatched << statement end end # Max violations handled in Shape if results.length < minimum raise ShEx::NotMatched, "Minimum Cardinality Violation: #{results.length} < #{minimum}" end # Last, evaluate semantic acts semantic_actions.each do |op| op.satisfies?(results, matched: results, depth: depth + 1) end unless results.empty? satisfy matched: results, unmatched: unmatched, satisfied: satisfied, unsatisfied: unsatisfied, depth: depth rescue ShEx::NotMatched, ShEx::NotSatisfied => e not_matched e., matched: results, unmatched: unmatched, satisfied: satisfied, unsatisfied: unsatisfied, depth: depth end |
#predicate ⇒ Object
72 73 74 |
# File 'lib/shex/algebra/triple_constraint.rb', line 72 def predicate operands.detect {|o| o.is_a?(RDF::URI)} end |
#shape ⇒ Object
87 88 89 |
# File 'lib/shex/algebra/triple_constraint.rb', line 87 def shape operands.detect {|o| o.is_a?(Satisfiable)} end |
#triple_constraints ⇒ Array<TripleConstraints>
Included TripleConstraints
79 80 81 |
# File 'lib/shex/algebra/triple_constraint.rb', line 79 def triple_constraints [self] end |