Class: ShEx::Algebra::SemAct

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

Constant Summary collapse

NAME =
:semact

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

#base_uri, #closed?, #dup, #each_descendant, #eql?, #expression, #expressions, #focus, #focus=, #initialize, #inspect, iri, #iri, #json_type, #matched, #matched=, #message, #message=, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfied, #satisfied=, #satisfy, #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

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

def self.from_shexj(operator, options = {})
  raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == "SemAct"
  raise ArgumentError, "missing name in #{operator.inspect}" unless operator.has_key?('name')
  code = operator.delete('code')
  operator['code'] = code if code # Reorders operands appropriately
  super
end

Instance Method Details

#enter(**options) ⇒ Boolean

Called on entry

Parameters:

  • code (String)
  • arcs_in (Array<RDF::Statement>)

    available statements to be matched having focus as an object

  • arcs_out (Array<RDF::Statement>)

    available statements to be matched having focus as a subject

  • depth (Integer)

    for logging

  • options (Hash{Symbol => Object})

    Other, operand-specific options

Returns:

  • (Boolean)

    Returning false results in NotSatisfied exception


28
29
30
31
32
# File 'lib/shex/algebra/semact.rb', line 28

def enter(**options)
  if implementation = schema.extensions[operands.first.to_s]
    implementation.enter(code: operands[0], expression: parent, **options)
  end
end

#exit(code: nil, matched: [], unmatched: [], depth: 0, **options)

This method returns an undefined value.

Called on exit from containing TripleExpression

Parameters:

  • code (String) (defaults to: nil)
  • matched (Array<RDF::Statement>) (defaults to: [])

    statements matched by this expression

  • unmatched (Array<RDF::Statement>) (defaults to: [])

    statements considered, but not matched by this expression

  • expression (ShEx::Algebra::TripleExpression)

    containing this semantic act

  • depth (Integer) (defaults to: 0)

    for logging

  • options (Hash{Symbol => Object})

    Other, operand-specific options


75
76
77
78
79
80
81
82
83
# File 'lib/shex/algebra/semact.rb', line 75

def exit(code: nil, matched: [], unmatched: [], depth: 0, **options)
  if implementation = schema.extensions[operands.first.to_s]
    implementation.exit(code: operands[1],
                     matched: matched,
                   unmatched: unmatched,
                 expresssion: parent,
                       depth: depth)
  end
end

#satisfies?(focus, matched: [], unmatched: [], depth: 0) ⇒ Boolean

The evaluation semActsSatisfied on a list of SemActs returns success or failure. The evaluation of an individual SemAct is implementation-dependent.

In addition to standard arguments satsisfies arguments, the current matched and unmatched statements may be passed. Additionally, all sub-classes of Operator have available parent, and schema accessors, which allows access to the operands of the parent, for example.

Parameters:

  • focus (Object)

    (ignored)

  • matched (Array<RDF::Statement>) (defaults to: [])

    matched statements

  • unmatched (Array<RDF::Statement>) (defaults to: [])

    unmatched statements

Returns:

  • (Boolean)

    true if satisfied, false if it does not apply

Raises:


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shex/algebra/semact.rb', line 44

def satisfies?(focus, matched: [], unmatched: [], depth: 0)
  if implementation = schema.extensions[operands.first.to_s]
    if matched.empty?
      implementation.visit(code: operands[1],
                     expression: parent,
                          depth: depth) ||
        not_satisfied("SemAct failed", unmatched: unmatched)
    end
    matched.all? do |statement|
      implementation.visit(code: operands[1],
                        matched: statement,
                     expression: parent,
                          depth: depth)
    end || not_satisfied("SemAct failed", matched: matched, unmatched: unmatched)
  else
    status("unknown SemAct name #{operands.first}", depth: depth) {"expression: #{self.to_sxp}"}
    false
  end
end

#semact?Boolean

Does This operator is SemAct

Returns:

  • (Boolean)

86
# File 'lib/shex/algebra/semact.rb', line 86

def semact?; true; end