Class: ShEx::Algebra::StemRange

Inherits:
Operator::Binary show all
Defined in:
lib/shex/algebra/stem_range.rb

Constant Summary collapse

NAME =
:stemRange

Constants inherited from Operator::Binary

Operator::Binary::ARITY

Constants inherited from Operator

Operator::ARITY

Instance Attribute Summary

Attributes inherited from Operator

#operands, #options, #schema

Instance Method Summary collapse

Methods inherited from Operator::Binary

#initialize

Methods inherited from Operator

#closed?, #each_descendant, #eql?, #first_ancestor, #initialize, #inspect, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfiable?, #semact?, #semantic_actions, #status, #structure_error, #to_sxp, #to_sxp_bin, #triple_expression?, #validate!

Constructor Details

This class inherits a constructor from ShEx::Algebra::Operator::Binary

Instance Method Details

#exclusionsObject



38
39
40
# File 'lib/shex/algebra/stem_range.rb', line 38

def exclusions
  (operands.last.is_a?(Array) && operands.last.first == :exclusions) ? operands.last[1..-1] : []
end

#match?(value) ⇒ Boolean

For a node n and constraint value v, nodeSatisfies(n, v) if n matches some valueSetValue vsv in v. A term matches a valueSetValue if:

  • vsv is a StemRange with stem st and exclusions excls and nodeIn(n, st) and there is no x in excls such that nodeIn(n, excl).

  • vsv is a Wildcard with exclusions excls and there is no x in excls such that nodeIn(n, excl).

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shex/algebra/stem_range.rb', line 11

def match?(value)
  initial_match = case operands.first
  when :wildcard then true
  when RDF::Value then value.start_with?(operands.first)
  else false
  end

  unless initial_match
    status "#{value} does not match #{operands.first}"
    return false
  end

  if exclusions.any? do |exclusion|
      case exclusion
      when RDF::Value then value == exclusion
      when Stem       then exclusion.match?(value)
      else                 false
      end
    end
    status "#{value} excluded"
    return false
  end

  status "matched #{value}"
  true
end