Class: ShEx::Algebra::And
- Includes:
- Satisfiable
- Defined in:
- lib/shex/algebra/and.rb
Constant Summary collapse
- NAME =
:and
Constants inherited from Operator
Instance Attribute Summary
Attributes inherited from Operator
#label, #logger, #operands, #options, #schema
Class Method Summary collapse
-
.from_shexj(operator, options = {}) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation.
Instance Method Summary collapse
-
#initialize(*args, **options) ⇒ And
constructor
A new instance of And.
- #json_type ⇒ Object
-
#satisfies?(focus, depth: 0) ⇒ Boolean, Operator
S is a ShapeAnd and for every shape expression se2 in shapeExprs, satisfies(n, se2, G, m).
Methods included from Satisfiable
Methods inherited from Operator
#base_uri, #closed?, #each_descendant, #eql?, #first_ancestor, #focus, #focus=, #inspect, iri, #iri, #matched, #matched=, #message, #message=, #not_matched, #not_satisfied, #operand, #parent, #parent=, #satisfiable?, #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
#initialize(*args, **options) ⇒ And
Returns a new instance of And.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/shex/algebra/and.rb', line 7 def initialize(*args, **) case when args.length < 2 raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 2..)" end # All arguments must be Satisfiable raise ArgumentError, "All operands must be Shape operands" unless args.all? {|o| o.is_a?(Satisfiable)} super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ShEx::Algebra::Operator
Class Method Details
.from_shexj(operator, options = {}) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation
22 23 24 25 26 |
# File 'lib/shex/algebra/and.rb', line 22 def self.from_shexj(operator, = {}) raise ArgumentError unless operator.is_a?(Hash) && operator['type'] == 'ShapeAnd' raise ArgumentError, "missing shapeExprs in #{operator.inspect}" unless operator.has_key?('shapeExprs') super end |
Instance Method Details
#json_type ⇒ Object
53 54 55 |
# File 'lib/shex/algebra/and.rb', line 53 def json_type "ShapeAnd" end |
#satisfies?(focus, depth: 0) ⇒ Boolean, Operator
S is a ShapeAnd and for every shape expression se2 in shapeExprs, satisfies(n, se2, G, m).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shex/algebra/and.rb', line 33 def satisfies?(focus, depth: 0) status "" expressions = operands.select {|o| o.is_a?(Satisfiable)} satisfied = [] unsatisfied = expressions.dup # Operand raises NotSatisfied, so no need to check here. expressions.each do |op| satisfied << op.satisfies?(focus, depth: depth) unsatisfied.shift end satisfy focus: focus, satisfied: satisfied, depth: depth rescue ShEx::NotSatisfied => e not_satisfied e., focus: focus, satisfied: satisfied, unsatisfied: unsatisfied, depth: depth end |