Class: ShEx::Algebra::Stem

Inherits:
Operator::Unary show all
Defined in:
lib/shex/algebra/stem.rb

Direct Known Subclasses

IriStem, LanguageStem, LiteralStem

Constant Summary collapse

NAME =
:stem

Constants inherited from Operator::Unary

Operator::Unary::ARITY

Constants inherited from Operator

Operator::ARITY

Instance Attribute Summary

Attributes inherited from Operator

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operator::Unary

#initialize

Methods inherited from Operator

#base_uri, #closed?, #dup, #each_descendant, #eql?, #expression, #expressions, #find, #focus, #focus=, #initialize, #inspect, #iri, iri, #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

Constructor Details

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

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
# File 'lib/shex/algebra/stem.rb', line 10

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

Instance Method Details

#json_typeObject



30
31
32
33
34
# File 'lib/shex/algebra/stem.rb', line 30

def json_type
  # FIXME: This is funky, due to oddities in normative shexj
  t = self.class.name.split('::').last
  #parent.is_a?(Value) ? "#{t}Range" : t
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 Stem with stem st and nodeIn(n, st).

Returns:

  • (Boolean)


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

def match?(value, depth: 0)
  if value.start_with?(operands.first)
    status "matched #{value}", depth: depth
    true
  else
    status "not matched #{value}", depth: depth
    false
  end
end