Sha256: db1650c4602884b7bb1032a0a8ee8fd11bf1623ba27c7c317fa4f240f1c21957

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

require 'sparql/algebra'

module ShEx::Algebra
  # Implements `satisfies?` and `not_satisfies?`
  module ShapeExpression
    ##
    # Satisfies method
    # @param [RDF::Resource] focus
    # @param [Integer] depth for logging
    # @param [Hash{Symbol => Object}] options
    #   Other, operand-specific options
    # @return [ShapeExpression] with `matched` and `satisfied` accessors for matched triples and sub-expressions
    # @raise [ShEx::NotMatched] with `expression` accessor to access `matched` and `unmatched` statements along with `satisfied` and `unsatisfied` operations.
    # @see [http://shex.io/shex-semantics/#shape-expression-semantics]
    def satisfies?(focus, depth: 0, **options)
      raise NotImplementedError, "#satisfies? Not implemented in #{self.class}"
    end

    ##
    # expressions must be ShapeExpressions or references.
    #
    # @raise  [ShEx::StructureError] if the value is invalid
    def validate_expressions!
      expressions.each do |op|
        case op
        when ShapeExpression
        when RDF::Resource
          ref = schema.find(op)
          ref.is_a?(ShapeExpression) ||
          structure_error("#{json_type} must reference a ShapeExpression: #{ref}")
        else
          structure_error("#{json_type} must be a ShapeExpression or reference: #{op.to_sxp}")
        end
      end
    end

    ##
    # An Operator with a label must contain a reference to itself.
    #
    # @raise  [ShEx::StructureError] if the shape is invalid
    def validate_self_references!
      return # FIXME: needs to stop at a TripleConstraint
      each_descendant do |op|
        structure_error("#{json_type} must not reference itself (#{id}): #{op.to_sxp}") if op.references.include?(id)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shex-0.8.0 lib/shex/algebra/shape_expression.rb
shex-0.7.1 lib/shex/algebra/shape_expression.rb
shex-0.7.0 lib/shex/algebra/shape_expression.rb
shex-0.6.4 lib/shex/algebra/shape_expression.rb