Class: ShEx::Algebra::Inclusion

Inherits:
Operator
  • Object
show all
Includes:
TripleExpression
Defined in:
lib/shex/algebra/inclusion.rb

Constant Summary collapse

NAME =
:inclusion

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, #inspect, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfiable?, #semact?, #semantic_actions, #status, #structure_error, #to_sxp, #to_sxp_bin, #triple_expression?

Constructor Details

#initialize(arg, **options) ⇒ Inclusion

Returns a new instance of Inclusion.

Raises:

  • (ArgumentError)


7
8
9
10
# File 'lib/shex/algebra/inclusion.rb', line 7

def initialize(arg, **options)
  raise ArgumentError, "Shape inclusion must be an IRI or BNode: #{arg}" unless arg.is_a?(RDF::Resource)
  super
end

Instance Method Details

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

In this case, we accept an array of statements, and match based on cardinality.

Parameters:

  • t (Array<RDF::Statement>)

Returns:

  • (Array<RDF::Statement>)

Raises:

  • NotMatched, ShEx::NotSatisfied



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shex/algebra/inclusion.rb', line 18

def matches(t)
  status "referenced_shape: #{operands.first}"
  expression = referenced_shape.triple_expressions.first
  max = maximum
  results = expression.matches(t)

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

  results
end

#referenced_shapeOperand

Returns the referenced shape

Returns:

  • (Operand)


35
36
37
# File 'lib/shex/algebra/inclusion.rb', line 35

def referenced_shape
  schema.shapes[operands.first.to_s]
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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shex/algebra/inclusion.rb', line 44

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)

  triple_expressions = referenced_shape.triple_expressions
  case triple_expressions.length
  when 0
    structure_error("Includes shape with no triple expressions")
  when 1
  else
    structure_error("Includes shape with multiple triple expressions")
  end
  super
end