Class: ShEx::Algebra::Operator Abstract

Inherits:
Object
  • Object
show all
Extended by:
SPARQL::Algebra::Expression
Includes:
RDF::Util::Logger
Defined in:
lib/shex/algebra/operator.rb

Overview

This class is abstract.

The ShEx operator.

Defined Under Namespace

Classes: Binary, Unary

Constant Summary collapse

ARITY =

variable arity

-1 # variable arity

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*operands) ⇒ Operator #initialize(*operands, options) ⇒ Operator

Initializes a new operator instance.

Overloads:

  • #initialize(*operands) ⇒ Operator

    Parameters:

    • operands (Array<RDF::Term>)
  • #initialize(*operands, options) ⇒ Operator

    Parameters:

    • operands (Array<RDF::Term>)
    • options (Hash{Symbol => Object})

      any additional options

    Options Hash (options):

    • :memoize (Boolean) — default: false

      whether to memoize results for particular operands

    • :label (RDF::Resource)

      Identifier of the operator

Raises:

  • (TypeError)

    if any operand is invalid



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/shex/algebra/operator.rb', line 38

def initialize(*operands)
  @options  = operands.last.is_a?(Hash) ? operands.pop.dup : {}
  @operands = operands.map! do |operand|
    case operand
      when Array
        operand.each do |op|
          op.parent = self if op.respond_to?(:parent=)
        end
        operand
      when Operator, RDF::Term, RDF::Query, RDF::Query::Pattern, Array, Symbol
        operand.parent = self if operand.respond_to?(:parent=)
        operand
      when TrueClass, FalseClass, Numeric, String, DateTime, Date, Time
        RDF::Literal(operand)
      when NilClass
        raise ArgumentError, "Found nil operand for #{self.class.name}"
      else raise TypeError, "invalid ShEx::Algebra::Operator operand: #{operand.inspect}"
    end
  end

  @label = options[:label]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (protected)

Implement ‘to_hash` only if accessed; otherwise, it becomes an _Implicit Accessor_ which will cause problems with splat arguments, which causes the last to be turned into a hash for extracting keyword aruments.



610
611
612
613
# File 'lib/shex/algebra/operator.rb', line 610

def method_missing(method, *args)
  return to_h(*args) if method == :hash
  super
end

Instance Attribute Details

#labelRDF::Resource

The label (or subject) of this operand

Returns:

  • (RDF::Resource)


201
202
203
# File 'lib/shex/algebra/operator.rb', line 201

def label
  @label
end

#logger=(value) ⇒ Logger (writeonly)

Logging support (reader is in RDF::Util::Logger)

Returns:

  • (Logger)


206
207
208
# File 'lib/shex/algebra/operator.rb', line 206

def logger=(value)
  @logger = value
end

#operandsArray (readonly)

The operands to this operator.

Returns:

  • (Array)


196
197
198
# File 'lib/shex/algebra/operator.rb', line 196

def operands
  @operands
end

#optionsObject

Initialization options



19
20
21
# File 'lib/shex/algebra/operator.rb', line 19

def options
  @options
end

#schemaObject

Location of schema including this operator



16
17
18
# File 'lib/shex/algebra/operator.rb', line 16

def schema
  @schema
end

Class Method Details

.from_shexj(operator, options = {}) ⇒ Operator

Creates an operator instance from a parsed ShExJ representation

Parameters:

  • operator (Hash)
  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :base (RDF::URI)
  • :prefixes (Hash{String => RDF::URI})

Returns:



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/shex/algebra/operator.rb', line 251

def self.from_shexj(operator, options = {})
  options[:context] ||= JSON::LD::Context.parse(ShEx::CONTEXT)
  operands = []
  label = nil

  operator.each do |k, v|
    case k
    when /length|pattern|clusive/          then operands << [k.to_sym, v]
    when 'label'                           then label = iri(v, options)
    when 'min', 'max', 'inverse', 'closed' then operands << [k.to_sym, v]
    when 'nodeKind'                        then operands << v.to_sym
    when 'object'                          then operands << value(v, options)
    when 'start'                           then operands << Start.new(ShEx::Algebra.from_shexj(v, options))
    when '@context'                        then
      options[:context] = JSON::LD::Context.parse(v)
      options[:base_uri] = options[:context].base
    when 'shapes'
      operands << case v
      when Array
        [:shapes] + v.map {|vv| ShEx::Algebra.from_shexj(vv, options)}
      else
        raise "Expected value of shapes #{v.inspect}"
      end
    when 'reference', 'include', 'stem', 'name'
      # Value may be :wildcard for stem
      operands << (v.is_a?(Symbol) ? v : iri(v, options))
    when 'predicate' then operands << iri(v, options)
    when 'extra', 'datatype'
      v = [v] unless v.is_a?(Array)
      operands << (v.map {|op| iri(op, options)}).unshift(k.to_sym)
    when 'exclusions'
      v = [v] unless v.is_a?(Array)
      operands << v.map do |op|
        op.is_a?(Hash) ?
          ShEx::Algebra.from_shexj(op, options) :
          value(op, options)
      end.unshift(:exclusions)
    when 'min', 'max', 'inverse', 'closed', 'valueExpr', 'semActs',
         'shapeExpr', 'shapeExprs', 'startActs', 'expression',
         'expressions', 'annotations'
      v = [v] unless v.is_a?(Array)
      operands += v.map {|op| ShEx::Algebra.from_shexj(op, options)}
    when 'code'
      operands << v
    when 'values'
      v = [v] unless v.is_a?(Array)
      operands += v.map do |op|
        Value.new(value(op, options))
      end
    end
  end

  new(*operands, label: label)
end

.iri(value, options) ⇒ RDF::Value

Create URIs

Parameters:

  • value (RDF::Value, String)
  • options (Hash{Symbol => Object})

Options Hash (options):

  • :base_uri (RDF::URI)
  • :prefixes (Hash{String => RDF::URI})
  • :context (JSON::LD::Context)

Returns:

  • (RDF::Value)


433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/shex/algebra/operator.rb', line 433

def self.iri(value, options)
  # If we have a base URI, use that when constructing a new URI
  base_uri = options[:base_uri]

  case value
  when Hash
    # A JSON-LD node reference
    v = options[:context].expand_value(value)
    raise "Expected #{value.inspect} to be a JSON-LD Node Reference" unless JSON::LD::Utils.node_reference?(v)
    self.iri(v['@id'], options)
  when RDF::URI
    if base_uri && value.relative?
      base_uri.join(value)
    else
      value
    end
  when RDF::Value then value
  when /^_:/ then
    id = value[2..-1].to_s
    RDF::Node.intern(id)
  when /^(\w+):(\S+)$/
    prefixes = options.fetch(:prefixes, {})
    if prefixes.has_key?($1)
      prefixes[$1].join($2)
    elsif RDF.type == value
      a = RDF.type.dup; a.lexical = 'a'; a
    elsif options[:context]
      options[:context].expand_iri(value, vocab: true)
    else
      RDF::URI(value)
    end
  else
    if options[:context]
      options[:context].expand_iri(value, document: true)
    elsif base_uri
      base_uri.join(value)
    elsif base_uri
      base_uri.join(value)
    else
      RDF::URI(value)
    end
  end
end

.value(value, options) ⇒ RDF::Value

Create Values, with “clever” matching to see if it might be a value, IRI or BNode.

Parameters:

  • value (RDF::Value, String)
  • options (Hash{Symbol => Object})

Options Hash (options):

  • :base_uri (RDF::URI)
  • :prefixes (Hash{String => RDF::URI})

Returns:

  • (RDF::Value)


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/shex/algebra/operator.rb', line 491

def self.value(value, options)
  # If we have a base URI, use that when constructing a new URI
  case value
  when Hash
    # Either a value object or a node reference
    if value['uri']
      iri(value['uri'], options)
    elsif value['value']
      RDF::Literal(value['value'], datatype: value['type'], language: value['language'])
    else
      ShEx::Algebra.from_shexj(value, options)
    end
  else iri(value, options)
  end
end

Instance Method Details

#base_uriHRDF::URI

Returns the Base URI defined for the parser, as specified or when parsing a BASE prologue element.

Examples:

base  #=> RDF::URI('http://example.com/')

Returns:

  • (HRDF::URI)


414
415
416
# File 'lib/shex/algebra/operator.rb', line 414

def base_uri
  @options[:base_uri]
end

#closed?Boolean

Is this shape closed?

Returns:

  • (Boolean)


64
65
66
# File 'lib/shex/algebra/operator.rb', line 64

def closed?
  operands.include?(:closed)
end

#each_descendant(depth = 0) {|operator| ... } ⇒ Enumerator Also known as: descendants, each

Enumerate via depth-first recursive descent over operands, yielding each operator

Parameters:

  • depth (Integer) (defaults to: 0)

    incrementeded for each depth of operator, and provided to block if Arity is 2

Yields:

  • operator

Yield Parameters:

  • operator (Object)

Returns:

  • (Enumerator)


546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/shex/algebra/operator.rb', line 546

def each_descendant(depth = 0, &block)
  if block_given?

    case block.arity
    when 1 then block.call(self)
    else block.call(depth, self)
    end

    operands.each do |operand|
      case operand
      when Array
        operand.each do |op|
          op.each_descendant(depth + 1, &block) if op.respond_to?(:each_descendant)
        end
      else
        operand.each_descendant(depth + 1, &block) if operand.respond_to?(:each_descendant)
      end
    end
  end
  enum_for(:each_descendant)
end

#eql?(other) ⇒ Boolean Also known as: ==

Parameters:

  • other (Statement)

Returns:

  • (Boolean)


535
536
537
# File 'lib/shex/algebra/operator.rb', line 535

def eql?(other)
  other.class == self.class && other.operands == self.operands
end

#first_ancestor(klass) ⇒ Operator

First ancestor operator of type ‘klass`

Parameters:

  • klass (Class)

Returns:



589
590
591
# File 'lib/shex/algebra/operator.rb', line 589

def first_ancestor(klass)
  parent.is_a?(klass) ? parent : parent.first_ancestor(klass) if parent
end

#focusObject

On a result instance, the focus of the expression



86
87
88
# File 'lib/shex/algebra/operator.rb', line 86

def focus
  Array(operands.detect {|op| op.is_a?(Array) && op[0] == :focus} || [:focus])[1]
end

#focus=(node) ⇒ Object



89
90
91
92
# File 'lib/shex/algebra/operator.rb', line 89

def focus=(node)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :focus}
  operands << [:focus, node]
end

#inspectString

Returns a developer-friendly representation of this operator.

Returns:

  • (String)


528
529
530
# File 'lib/shex/algebra/operator.rb', line 528

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, operands.to_sse.gsub(/\s+/m, ' '))
end

#iri(value, options = @options) ⇒ RDF::Value

Create URIs

Parameters:

  • value (RDF::Value, String)
  • options (Hash{Symbol => Object}) (defaults to: @options)

Options Hash (options):

  • :base_uri (RDF::URI)
  • :prefixes (Hash{String => RDF::URI})
  • :context (JSON::LD::Context)

Returns:

  • (RDF::Value)


425
426
427
# File 'lib/shex/algebra/operator.rb', line 425

def iri(value, options = @options)
  self.class.iri(value, options)
end

#json_typeObject



306
307
308
# File 'lib/shex/algebra/operator.rb', line 306

def json_type
  self.class.name.split('::').last
end

#matchedArray<Statement>

On a result instance, the statements that matched this expression.

Returns:

  • (Array<Statement>)


97
98
99
# File 'lib/shex/algebra/operator.rb', line 97

def matched
  Array((operands.detect {|op| op.is_a?(Array) && op[0] == :matched} || [:matched])[1..-1])
end

#matched=(statements) ⇒ Object



100
101
102
103
# File 'lib/shex/algebra/operator.rb', line 100

def matched=(statements)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :matched}
  operands << statements.unshift(:matched) unless (statements || []).empty?
end

#messageString

On a result instance, the failure message. (failure only).

Returns:

  • (String)


141
142
143
# File 'lib/shex/algebra/operator.rb', line 141

def message
  (operands.detect {|op| op.is_a?(Array) && op[0] == :message} || [:message])[1..-1]
end

#message=(str) ⇒ Object



144
145
146
147
# File 'lib/shex/algebra/operator.rb', line 144

def message=(str)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :message}
  operands << [:message, str]
end

#not_matched(message, **opts, &block) ⇒ Object

Exception handling

Raises:

  • (exception)


167
168
169
170
171
172
# File 'lib/shex/algebra/operator.rb', line 167

def not_matched(message, **opts, &block)
  expression = opts.fetch(:expression, self).satisfy(message: message, **opts)
  exception = opts.fetch(:exception, ShEx::NotMatched)
  status(message, **opts) {(block_given? ? block.call : "") + "expression: #{expression.to_sxp}"}
  raise exception.new(message, expression: expression)
end

#not_satisfied(message, **opts) ⇒ Object

Raises:

  • (exception)


174
175
176
177
178
179
# File 'lib/shex/algebra/operator.rb', line 174

def not_satisfied(message, **opts)
  expression = opts.fetch(:expression, self).satisfy(message: message, **opts)
  exception = opts.fetch(:exception, ShEx::NotSatisfied)
  status(message, **opts) {(block_given? ? block.call : "") + "expression: #{expression.to_sxp}"}
  raise exception.new(message, expression: expression)
end

#operand(index = 0) ⇒ RDF::Term

Returns the operand at the given ‘index`.

Parameters:

  • index (Integer) (defaults to: 0)

    an operand index in the range ‘(0…(operands.count))`

Returns:

  • (RDF::Term)


214
215
216
# File 'lib/shex/algebra/operator.rb', line 214

def operand(index = 0)
  operands[index]
end

#parentOperator

Parent expression, if any

Returns:



574
# File 'lib/shex/algebra/operator.rb', line 574

def parent; @options[:parent]; end

#parent=(operator) ⇒ Operator

Parent operator, if any

Returns:



580
581
582
# File 'lib/shex/algebra/operator.rb', line 580

def parent=(operator)
  @options[:parent]= operator
end

#satisfiable?Boolean

Does this operator include Satisfiable?

Returns:

  • (Boolean)


76
# File 'lib/shex/algebra/operator.rb', line 76

def satisfiable?; false; end

#satisfiedArray<Operator>

On a result instance, the sub-expressions which were matched.

Returns:



119
120
121
# File 'lib/shex/algebra/operator.rb', line 119

def satisfied
  Array((operands.detect {|op| op.is_a?(Array) && op[0] == :satisfied} || [:satisfied])[1..-1])
end

#satisfied=(ops) ⇒ Object



122
123
124
125
# File 'lib/shex/algebra/operator.rb', line 122

def satisfied=(ops)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :satisfied}
  operands << ops.unshift(:satisfied) unless (ops || []).empty?
end

#satisfy(focus: nil, matched: nil, unmatched: nil, satisfied: nil, unsatisfied: nil, message: nil, **opts) ⇒ Operand

Duplication this operand, and add ‘matched`, `unmatched`, `satisfied`, and `unsatisfied` operands for accessing downstream.

Returns:

  • (Operand)


153
154
155
156
157
158
159
160
161
162
163
# File 'lib/shex/algebra/operator.rb', line 153

def satisfy(focus: nil, matched: nil, unmatched: nil, satisfied: nil, unsatisfied: nil, message: nil, **opts)
  log_debug(self.class.const_get(:NAME), "satisfied", **opts) unless message
  expression = self.dup
  expression.message = message if message
  expression.focus = focus if focus
  expression.matched = Array(matched) if matched
  expression.unmatched = Array(unmatched) if unmatched
  expression.satisfied = Array(satisfied) if satisfied
  expression.unsatisfied = Array(unsatisfied) if unsatisfied
  expression
end

#semact?Boolean

Does this operator a SemAct?

Returns:

  • (Boolean)


82
# File 'lib/shex/algebra/operator.rb', line 82

def semact?; false; end

#semantic_actionsArray<SemAct>

Semantic Actions

Returns:



71
72
73
# File 'lib/shex/algebra/operator.rb', line 71

def semantic_actions
  operands.select {|o| o.is_a?(SemAct)}
end

#serialize_value(value) ⇒ String

Serialize a value, either as JSON, or as modififed N-Triples

Parameters:

Returns:

  • (String)


512
513
514
515
516
517
518
519
520
521
522
# File 'lib/shex/algebra/operator.rb', line 512

def serialize_value(value)
  case value
    when RDF::Literal
      {'value' => value.to_s}.
      merge(value.has_datatype? ? {'type' => value.datatype.to_s} : {}).
      merge(value.has_language? ? {'language' => value.language.to_s} : {})
    when RDF::Resource
      value.to_s
    else value.to_h
  end
end

#status(message, **opts, &block) ⇒ Object



187
188
189
190
# File 'lib/shex/algebra/operator.rb', line 187

def status(message, **opts, &block)
  log_debug(self.class.const_get(:NAME).to_s + (@label ? "(#{@label})" : ""), message, **opts, &block)
  true
end

#structure_error(message, **opts) ⇒ Object



181
182
183
184
185
# File 'lib/shex/algebra/operator.rb', line 181

def structure_error(message, **opts)
  expression = opts.fetch(:expression, self)
  exception = opts.fetch(:exception, ShEx::StructureError)
  log_error(message, depth: options.fetch(:depth, 0), exception: exception) {"expression: #{expression.to_sxp}"}
end

#to_hHash

Create a hash version of the operator, suitable for turning into JSON.

Returns:

  • (Hash)


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/shex/algebra/operator.rb', line 317

def to_h
  obj = json_type == 'Schema' ?
    {'@context' => ShEx::CONTEXT, 'type' => json_type} : 
    {'type' => json_type}
  obj['label'] = label.to_s if label
  operands.each do |op|
    case op
    when Array
      # First element should be a symbol
      case sym = op.first
      when :datatype,
           :pattern         then obj[op.first.to_s] = op.last.to_s
      when :exclusions      then obj['exclusions'] = Array(op[1..-1]).map {|v| serialize_value(v)}
      when :extra           then (obj['extra'] ||= []).concat Array(op[1..-1]).map(&:to_s)
        # FIXME Shapes should be an array, not a hash
      when :shapes          then obj['shapes'] = Array(op[1..-1]).map {|v| v.to_h}
      when :minlength,
           :maxlength,
           :length,
           :mininclusive,
           :maxinclusive,
           :minexclusive,
           :maxexclusive,
           :totaldigits,
           :fractiondigits  then obj[op.first.to_s] = op.last.object
      when :min, :max       then obj[op.first.to_s] = op.last
      when :base, :prefix
        # Ignore base and prefix
      when Symbol           then obj[sym.to_s] = Array(op[1..-1]).map(&:to_h)
      else
        raise "Expected array to start with a symbol for #{self}"
      end
    when :wildcard  then obj['stem'] = {'type' => 'Wildcard'}
    when Annotation then (obj['annotations'] ||= []) << op.to_h
    when SemAct     then (obj[is_a?(Schema) ? 'startActs' : 'semActs'] ||= []) << op.to_h
    when Start      then obj['start'] = op.operands.first.to_h
    when RDF::Value
      case self
      when TripleConstraint then obj['predicate'] = op.to_s
      when Stem, StemRange  then obj['stem'] = op.to_s
      when Inclusion        then obj['include'] = op.to_s
      when ShapeRef         then obj['reference'] = op.to_s
      when SemAct           then obj[op.is_a?(RDF::URI) ? 'name' : 'code'] = op.to_s
      else
        raise "How to serialize Value #{op.inspect} to json for #{self}"
      end
    when Symbol
      case self
      when NodeConstraint   then obj['nodeKind'] = op.to_s
      when Shape            then obj['closed'] = true
      when TripleConstraint then obj['inverse'] = true
      else
        raise "How to serialize Symbol #{op.inspect} to json for #{self}"
      end
    when TripleConstraint, EachOf, OneOf, Inclusion
      case self
      when EachOf, OneOf
        (obj['expressions'] ||= []) << op.to_h
      else
        obj['expression'] = op.to_h
      end
    when NodeConstraint
      case self
      when And, Or
        (obj['shapeExprs'] ||= []) << op.to_h
      else
        obj['valueExpr'] = op.to_h
      end
    when And, Or, Shape, Not, ShapeRef
      case self
      when And, Or
        (obj['shapeExprs'] ||= []) << op.to_h
      when TripleConstraint
        obj['valueExpr'] = op.to_h
      else
        obj['shapeExpr'] = op.to_h
      end
    when Value
      obj['values'] ||= []
      Array(op).map {|o| o.operands}.flatten.each do |oo|
        obj['values'] << serialize_value(oo)
      end
    else
      raise "How to serialize #{op.inspect} to json for #{self}"
    end
  end
  obj
end

#to_json(options = nil) ⇒ Object



310
311
312
# File 'lib/shex/algebra/operator.rb', line 310

def to_json(options = nil)
  self.to_h.to_json(options)
end

#to_sxpString

Returns an S-Expression (SXP) representation of this operator

Returns:

  • (String)


233
234
235
236
237
238
239
240
241
242
# File 'lib/shex/algebra/operator.rb', line 233

def to_sxp
  begin
    require 'sxp' # @see http://rubygems.org/gems/sxp
  rescue LoadError
    abort "SPARQL::Algebra::Operator#to_sxp requires the SXP gem (hint: `gem install sxp')."
  end
  require 'sparql/algebra/sxp_extensions'

  to_sxp_bin.to_sxp
end

#to_sxp_binArray

Returns the binary S-Expression (SXP) representation of this operator.

Returns:

  • (Array)

See Also:



223
224
225
226
227
# File 'lib/shex/algebra/operator.rb', line 223

def to_sxp_bin
  [self.class.const_get(:NAME)] +
  (label ? [[:label, label]] : []) +
  (operands || []).map(&:to_sxp_bin)
end

#triple_expression?Boolean

Does this operator include TripleExpression?

Returns:

  • (Boolean)


79
# File 'lib/shex/algebra/operator.rb', line 79

def triple_expression?; false; end

#unmatchedArray<Statement>

On a result instance, the statements that did not match this expression (failure only).

Returns:

  • (Array<Statement>)


108
109
110
# File 'lib/shex/algebra/operator.rb', line 108

def unmatched
  Array((operands.detect {|op| op.is_a?(Array) && op[0] == :unmatched} || [:unmatched])[1..-1])
end

#unmatched=(statements) ⇒ Object



111
112
113
114
# File 'lib/shex/algebra/operator.rb', line 111

def unmatched=(statements)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :unmatched}
  operands << statements.unshift(:unmatched) unless (statements || []).empty?
end

#unsatisfiedArray<Operator>

On a result instance, the sub-satisfieables which were not satisfied. (failure only).

Returns:



130
131
132
# File 'lib/shex/algebra/operator.rb', line 130

def unsatisfied
  Array((operands.detect {|op| op.is_a?(Array) && op[0] == :unsatisfied} || [:unsatisfied])[1..-1])
end

#unsatisfied=(ops) ⇒ Object



133
134
135
136
# File 'lib/shex/algebra/operator.rb', line 133

def unsatisfied=(ops)
  operands.delete_if {|op| op.is_a?(Array) && op[0] == :unsatisfied}
  operands << ops.unshift(:unsatisfied) unless (ops || []).empty?
end

#validate!SPARQL::Algebra::Expression

Validate all operands, operator specific classes should override for operator-specific validation

Returns:

  • (SPARQL::Algebra::Expression)

    ‘self`

Raises:



597
598
599
600
# File 'lib/shex/algebra/operator.rb', line 597

def validate!
  operands.each {|op| op.validate! if op.respond_to?(:validate!)}
  self
end

#value(value, options = @options) ⇒ RDF::Value

Create Values, with “clever” matching to see if it might be a value, IRI or BNode.

Parameters:

  • value (RDF::Value, String)
  • options (Hash{Symbol => Object}) (defaults to: @options)

Options Hash (options):

  • :base_uri (RDF::URI)
  • :prefixes (Hash{String => RDF::URI})

Returns:

  • (RDF::Value)


483
484
485
# File 'lib/shex/algebra/operator.rb', line 483

def value(value, options = @options)
  self.class.value(value, options)
end