Class: ShEx::Algebra::ShapeRef

Inherits:
Operator::Unary show all
Includes:
Satisfiable
Defined in:
lib/shex/algebra/shape_ref.rb

Constant Summary collapse

NAME =
:shapeRef

Constants inherited from Operator::Unary

Operator::Unary::ARITY

Constants inherited from Operator

Operator::ARITY

Instance Attribute Summary

Attributes inherited from Operator

#operands, #options, #schema

Instance Method Summary collapse

Methods included from Satisfiable

#not_satisfies?, #satisfiable?, #triple_expressions

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) ⇒ ShapeRef

Returns a new instance of ShapeRef.



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

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

Instance Method Details

#referenced_shapeShape

Returns the referenced shape

Returns:



32
33
34
# File 'lib/shex/algebra/shape_ref.rb', line 32

def referenced_shape
  schema.shapes[operands.first.to_s]
end

#satisfies?(n) ⇒ Boolean

Satisfies method

Parameters:

  • n (RDF::Resource)

Returns:

  • (Boolean)

    ‘true` if satisfied

Raises:

See Also:



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

def satisfies?(n)
  status "ref #{operands.first.to_s}"
  referenced_shape.satisfies?(n)
  status "ref satisfied"
  true
rescue ShEx::NotSatisfied => e
  not_satisfied e.message
  raise
end

#validate!Object

A ShapeRef is valid if it’s ancestor schema has any shape with a lable the same as it’s reference.



39
40
41
42
43
44
# File 'lib/shex/algebra/shape_ref.rb', line 39

def validate!
  structure_error("Missing referenced shape: #{operands.first}") if referenced_shape.nil?
  # FIXME
  #raise ShEx::ParseError, "Self referencing shape: #{operands.first}" if referenced_shape == first_ancestor(Shape)
  super
end