Class: ShEx::Algebra::StemRange

Inherits:
Operator::Binary show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/stem_range.rb

Direct Known Subclasses

IriStemRange, LanguageStemRange, LiteralStemRange

Constant Summary collapse

NAME =
:stemRange

Constants inherited from Operator::Binary

Operator::Binary::ARITY

Constants inherited from Operator

Operator::ARITY

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from Operator

#id, #logger, #operands, #options, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operator::Binary

#initialize

Methods inherited from Operator

#base_uri, #closed?, #dup, #each_descendant, #eql?, #expression, #expressions, #find, #focus, #focus=, #initialize, #inspect, iri, #iri, #json_type, #matched, #matched=, #message, #message=, #not_matched, #not_satisfied, #operand, #parent, #parent=, #references, #satisfied, #satisfied=, #satisfy, #semact?, #semantic_actions, #serialize_value, #status, #structure_error, #to_h, #to_json, #to_sxp, #to_sxp_bin, #triple_expression?, #unmatched, #unmatched=, #unsatisfied, #unsatisfied=, #validate!, value, #value

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from RDF::Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Constructor Details

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

Class Method Details

.from_shexj(operator, **options) ⇒ Operator

Creates an operator instance from a parsed ShExJ representation

Returns:

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/stem_range.rb', line 10

def self.from_shexj(operator, **options)
  raise ArgumentError unless operator.is_a?(Hash) && %w(IriStemRange LiteralStemRange LanguageStemRange).include?(operator['type'])
  raise ArgumentError, "missing stem in #{operator.inspect}" unless operator.has_key?('stem')

  # Normalize wildcard representation
  operator['stem'] = :wildcard if operator['stem'] =={'type' => 'Wildcard'}

  # Note that the type may be StemRange, but if there's no exclusions, it's really just a Stem
  if operator.has_key?('exclusions')
    super
  else
    # Remove "Range" from type
    case operator['type']
    when 'IriStemRange'
      IriStem.from_shexj(operator.merge('type' => 'IriStem'), **options)
    when 'LiteralStemRange'
      LiteralStem.from_shexj(operator.merge('type' => 'LiteralStem'), **options)
    when 'LanguageStemRange'
      LanguageStem.from_shexj(operator.merge('type' => 'LanguageStem'), **options)
    end
  end
end

Instance Method Details

#exclusionsObject



65
66
67
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/stem_range.rb', line 65

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

#match?(value, depth: 0) ⇒ 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)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/shex-f64040a493d0/lib/shex/algebra/stem_range.rb', line 38

def match?(value, depth: 0)
  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}", depth: depth
    return false
  end

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

  status "matched #{value}", depth: depth
  true
end