Class: ShEx::Algebra::Inclusion
- Includes:
- TripleExpression
- Defined in:
- lib/shex/algebra/inclusion.rb
Constant Summary collapse
- NAME =
:inclusion
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
-
#initialize(arg, **options) ⇒ Inclusion
constructor
A new instance of Inclusion.
-
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
In this case, we accept an array of statements, and match based on cardinality.
-
#referenced_shape ⇒ Operand
Returns the referenced shape.
-
#to_sxp_bin ⇒ Array
Returns the binary S-Expression (SXP) representation of this operator.
-
#validate! ⇒ Object
A Inclusion is valid if it’s ancestor schema has any shape with a lable the same as it’s reference.
Methods included from TripleExpression
#maximum, #minimum, #triple_constraints, #triple_expression?
Methods inherited from Operator
#base_uri, #closed?, #each_descendant, #eql?, #first_ancestor, #focus, #focus=, #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, #triple_expression?, #unmatched, #unmatched=, #unsatisfied, #unsatisfied=, value, #value
Constructor Details
#initialize(arg, **options) ⇒ Inclusion
Returns a new instance of Inclusion.
17 18 19 20 |
# File 'lib/shex/algebra/inclusion.rb', line 17 def initialize(arg, **) raise ArgumentError, "Shape inclusion must be an IRI or BNode: #{arg}" unless arg.is_a?(RDF::Resource) super end |
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/inclusion.rb', line 11 def self.from_shexj(operator, = {}) raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == "Inclusion" raise ArgumentError, "missing include in #{operator.inspect}" unless operator.has_key?('include') super end |
Instance Method Details
#matches(arcs_in, arcs_out, depth: 0) ⇒ TripleExpression
In this case, we accept an array of statements, and match based on cardinality.
28 29 30 31 32 33 34 35 36 |
# File 'lib/shex/algebra/inclusion.rb', line 28 def matches(arcs_in, arcs_out, depth: 0) status "referenced_shape: #{operands.first}" expression = referenced_shape.expression max = maximum matched_expression = expression.matches(arcs_in, arcs_out, depth: depth + 1) satisfy matched: matched_expression.matched, depth: depth rescue ShEx::NotMatched => e not_matched e., unsatisfied: e.expression, depth: depth end |
#referenced_shape ⇒ Operand
Returns the referenced shape
42 43 44 |
# File 'lib/shex/algebra/inclusion.rb', line 42 def referenced_shape @referenced_shape ||= schema.shapes.detect {|s| s.label == operands.first} end |
#to_sxp_bin ⇒ Array
Returns the binary S-Expression (SXP) representation of this operator.
63 64 65 |
# File 'lib/shex/algebra/inclusion.rb', line 63 def to_sxp_bin ([:inclusion, ([:label, @label] if @label)].compact + operands).to_sxp_bin end |
#validate! ⇒ Object
A Inclusion is valid if it’s ancestor schema has any shape with a lable the same as it’s reference.
An Inclusion object’s include property must appear in the schema’s shapes map and the corresponding triple expression must be a Shape with a tripleExpr. The function dereference(include) returns the shape’s tripleExpr.
51 52 53 54 55 56 |
# File 'lib/shex/algebra/inclusion.rb', line 51 def validate! structure_error("Missing included shape: #{operands.first}") if referenced_shape.nil? structure_error("Self included shape: #{operands.first}") if referenced_shape == first_ancestor(Shape) structure_error("Referenced shape must be a Shape: #{operands.first}") unless referenced_shape.is_a?(Shape) super end |