Class: ShEx::Algebra::Operator Abstract
- Inherits:
-
Object
- Object
- ShEx::Algebra::Operator
- Extended by:
- SPARQL::Algebra::Expression
- Includes:
- RDF::Util::Logger
- Defined in:
- lib/shex/algebra/operator.rb
Overview
The ShEx operator.
Direct Known Subclasses
And, Annotation, EachOf, External, NodeConstraint, OneOf, Binary, Unary, Or, Schema, SemAct, Shape, TripleConstraint
Defined Under Namespace
Constant Summary collapse
- ARITY =
variable arity
-1 # variable arity
Instance Attribute Summary collapse
-
#id ⇒ RDF::Resource
The id (or subject) of this operand.
-
#logger ⇒ Logger
writeonly
Logging support (reader is in RDF::Util::Logger).
-
#operands ⇒ Array
readonly
The operands to this operator.
-
#options ⇒ Object
Initialization options.
-
#schema ⇒ Object
Location of schema including this operator.
Class Method Summary collapse
-
.from_shexj(operator, **options) ⇒ Operator
Creates an operator instance from a parsed ShExJ representation.
-
.iri(value, **options) ⇒ RDF::Value
Create URIs.
-
.value(value, **options) ⇒ RDF::Value
Create Values, with “clever” matching to see if it might be a value, IRI or BNode.
Instance Method Summary collapse
-
#base_uri ⇒ HRDF::URI
Returns the Base URI defined for the parser, as specified or when parsing a BASE prologue element.
-
#closed? ⇒ Boolean
Is this shape closed?.
- #dup ⇒ Object
-
#each_descendant(include_self = false) {|operator| ... } ⇒ Enumerator
(also: #descendants, #each)
Enumerate via depth-first recursive descent over operands, yielding each operator.
-
#eql?(other) ⇒ Boolean
(also: #==)
Comparison does not consider operand order.
-
#expression ⇒ RDF::Resource, Operand
The first expression from #expressions.
-
#expressions ⇒ RDF::Resource, Operand
Expressions are all operands which are Operators or RDF::Resource.
-
#find(id) ⇒ TripleExpression, ShapeExpression
Find a ShapeExpression or TripleExpression by identifier.
-
#focus ⇒ Object
On a result instance, the focus of the expression.
- #focus=(node) ⇒ Object
-
#initialize(*operands, **options) ⇒ Operator
constructor
Initializes a new operator instance.
-
#inspect ⇒ String
Returns a developer-friendly representation of this operator.
-
#iri(value, options = @options) ⇒ RDF::Value
Create URIs.
- #json_type ⇒ Object
-
#matched ⇒ Array<Statement>
On a result instance, the statements that matched this expression.
- #matched=(statements) ⇒ Object
-
#message ⇒ String
On a result instance, the failure message.
- #message=(str) ⇒ Object
-
#not_matched(message, **opts, &block) ⇒ Object
Exception handling.
- #not_satisfied(message, **opts) ⇒ Object
-
#operand(index = 0) ⇒ RDF::Term
Returns the operand at the given
index
. -
#parent ⇒ Operator
Parent expression, if any.
-
#parent=(operator) ⇒ Operator
Parent operator, if any.
-
#references ⇒ RDF::Resource, Operand
References are all operands which are RDF::Resource.
-
#satisfied ⇒ Array<Operator>
On a result instance, the sub-expressions which were matched.
- #satisfied=(ops) ⇒ Object
-
#satisfy(focus: nil, matched: nil, unmatched: nil, satisfied: nil, unsatisfied: nil, message: nil, **opts) ⇒ Operand
Duplication this operand, and add
matched
,unmatched
,satisfied
, andunsatisfied
operands for accessing downstream. -
#semact? ⇒ Boolean
Does this operator a SemAct?.
-
#semantic_actions ⇒ Array<SemAct>
Semantic Actions.
-
#serialize_value(value) ⇒ String
Serialize a value, either as JSON, or as modififed N-Triples.
- #status(message, **opts, &block) ⇒ Object
- #structure_error(message, **opts) ⇒ Object
-
#to_h ⇒ Hash
Create a hash version of the operator, suitable for turning into JSON.
- #to_json(options = nil) ⇒ Object
-
#to_sxp(**options) ⇒ String
Returns an S-Expression (SXP) representation of this operator.
-
#to_sxp_bin ⇒ Array
Returns the binary S-Expression (SXP) representation of this operator.
-
#triple_expression? ⇒ Boolean
Does this operator include TripleExpression?.
-
#unmatched ⇒ Array<Statement>
On a result instance, the statements that did not match this expression (failure only).
- #unmatched=(statements) ⇒ Object
-
#unsatisfied ⇒ Array<Operator>
On a result instance, the sub-satisfieables which were not satisfied.
- #unsatisfied=(ops) ⇒ Object
-
#validate! ⇒ SPARQL::Algebra::Expression
Validate all operands, operator specific classes should override for operator-specific validation.
-
#value(value, options = @options) ⇒ RDF::Value
Create Values, with “clever” matching to see if it might be a value, IRI or BNode.
Constructor Details
#initialize(*operands) ⇒ Operator #initialize(*operands, **options) ⇒ Operator
Initializes a new operator instance.
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 = .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 @id = [:id] end |
Instance Attribute Details
#id ⇒ RDF::Resource
The id (or subject) of this operand
198 199 200 |
# File 'lib/shex/algebra/operator.rb', line 198 def id @id end |
#logger=(value) ⇒ Logger (writeonly)
Logging support (reader is in RDF::Util::Logger)
203 204 205 |
# File 'lib/shex/algebra/operator.rb', line 203 def logger=(value) @logger = value end |
#operands ⇒ Array (readonly)
The operands to this operator.
193 194 195 |
# File 'lib/shex/algebra/operator.rb', line 193 def operands @operands end |
#options ⇒ Object
Initialization options
19 20 21 |
# File 'lib/shex/algebra/operator.rb', line 19 def @options end |
#schema ⇒ Object
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
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 305 306 307 308 309 310 311 312 313 314 315 316 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 |
# File 'lib/shex/algebra/operator.rb', line 265 def self.from_shexj(operator, **) [:context] ||= JSON::LD::Context.parse(ShEx::CONTEXT) operands = [] id = nil operator.each do |k, v| case k when /length|clusive|digits/ then operands << [k.to_sym, RDF::Literal(v)] when 'id' then id = iri(v, **) when 'flags' then ; # consumed in pattern below when 'min', 'max' then operands << [k.to_sym, (v == -1 ? '*' : v)] when 'inverse', 'closed' then operands << k.to_sym when 'nodeKind' then operands << v.to_sym when 'object' then operands << value(v, **) when 'languageTag' then operands << v when 'pattern' # Include flags as well operands << [:pattern, RDF::Literal(v), operator['flags']].compact when 'start' if v.is_a?(String) operands << Start.new(iri(v, **)) else operands << Start.new(ShEx::Algebra.from_shexj(v, **)) end when '@context' then [:context] = JSON::LD::Context.parse(v) [:base_uri] ||= [:context].base when 'shapes' operands << case v when Array [:shapes] + v.map {|vv| ShEx::Algebra.from_shexj(vv, **)} else raise "Expected value of shapes #{v.inspect}" end when 'stem', 'name' # Value may be :wildcard for stem if [IriStem, IriStemRange, SemAct].include?(self) operands << (v.is_a?(Symbol) ? v : value(v, **)) else operands << v end when 'predicate' then operands << [:predicate, iri(v, **)] when 'extra', 'datatype' v = [v] unless v.is_a?(Array) operands << (v.map {|op| iri(op, **)}).unshift(k.to_sym) when 'exclusions' v = [v] unless v.is_a?(Array) operands << v.map do |op| if op.is_a?(Hash) && op.has_key?('type') ShEx::Algebra.from_shexj(op, **) elsif [IriStem, IriStemRange].include?(self) value(op, **) else RDF::Literal(op) end end.unshift(:exclusions) when 'semActs', 'startActs', 'annotations' v = [v] unless v.is_a?(Array) operands += v.map {|op| ShEx::Algebra.from_shexj(op, **)} when 'expression', 'expressions', 'shapeExpr', 'shapeExprs', 'valueExpr' v = [v] unless v.is_a?(Array) operands += v.map do |op| # It's a URI reference to a Shape op.is_a?(String) ? iri(op, **) : ShEx::Algebra.from_shexj(op, **) end when 'code' operands << v when 'values' v = [v] unless v.is_a?(Array) operands += v.map do |op| Value.new(value(op, **)) end end end new(*operands, **.merge(id: id)) end |
.iri(value, **options) ⇒ RDF::Value
Create URIs
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/shex/algebra/operator.rb', line 490 def self.iri(value, **) # If we have a base URI, use that when constructing a new URI base_uri = [:base_uri] case value when Hash # A JSON-LD node reference v = [:context].(value) raise "Expected #{value.inspect} to be a JSON-LD Node Reference" unless JSON::LD::Utils.node_reference?(v) self.iri(v['@id'], **) 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 = .fetch(:prefixes, {}) if prefixes.has_key?($1) prefixes[$1].join($2) elsif RDF.type == value a = RDF.type.dup; a.lexical = 'a'; a elsif [:context] [:context].(value, vocab: true) else RDF::URI(value) end else if 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.
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/shex/algebra/operator.rb', line 544 def self.value(value, **) # 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'] || value['@id'] iri(value['uri'] || value['@id'], **) elsif value['value'] || value['@value'] RDF::Literal(value['value'] || value['@value'], datatype: value['type'] || value['@type'], language: value['language'] || value['@language']) else ShEx::Algebra.from_shexj(value, **) end else iri(value, **) end end |
Instance Method Details
#base_uri ⇒ HRDF::URI
Returns the Base URI defined for the parser, as specified or when parsing a BASE prologue element.
471 472 473 |
# File 'lib/shex/algebra/operator.rb', line 471 def base_uri @options[:base_uri] end |
#closed? ⇒ Boolean
Is this shape closed?
64 65 66 |
# File 'lib/shex/algebra/operator.rb', line 64 def closed? operands.include?(:closed) end |
#dup ⇒ Object
676 677 678 679 |
# File 'lib/shex/algebra/operator.rb', line 676 def dup operands = @operands.map {|o| o.dup rescue o} self.class.new(*operands, id: @id) end |
#each_descendant(include_self = false) {|operator| ... } ⇒ Enumerator Also known as: descendants, each
Enumerate via depth-first recursive descent over operands, yielding each operator
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/shex/algebra/operator.rb', line 604 def each_descendant(include_self = false, &block) if block_given? block.call(self) if include_self operands.each do |operand| case operand when Array operand.each do |op| op.each_descendant(true, &block) if op.respond_to?(:each_descendant) end else operand.each_descendant(true, &block) if operand.respond_to?(:each_descendant) end end end enum_for(:each_descendant) end |
#eql?(other) ⇒ Boolean Also known as: ==
Comparison does not consider operand order
591 592 593 594 595 |
# File 'lib/shex/algebra/operator.rb', line 591 def eql?(other) other.class == self.class && other.id == self.id && other.operands.sort_by(&:to_s) == self.operands.sort_by(&:to_s) end |
#expression ⇒ RDF::Resource, Operand
The first expression from #expressions.
226 227 228 |
# File 'lib/shex/algebra/operator.rb', line 226 def expression expressions.first end |
#expressions ⇒ RDF::Resource, Operand
Expressions are all operands which are Operators or RDF::Resource
218 219 220 221 |
# File 'lib/shex/algebra/operator.rb', line 218 def expressions @expressions = operands. select {|op| op.is_a?(RDF::Resource) || op.is_a?(ShapeExpression) || op.is_a?(TripleExpression)} end |
#find(id) ⇒ TripleExpression, ShapeExpression
Find a ShapeExpression or TripleExpression by identifier
643 644 645 |
# File 'lib/shex/algebra/operator.rb', line 643 def find(id) each_descendant(false).detect {|op| op.id == id} end |
#focus ⇒ Object
On a result instance, the focus of the expression
83 84 85 |
# File 'lib/shex/algebra/operator.rb', line 83 def focus Array(operands.detect {|op| op.is_a?(Array) && op[0] == :focus} || [:focus])[1] end |
#focus=(node) ⇒ Object
86 87 88 89 |
# File 'lib/shex/algebra/operator.rb', line 86 def focus=(node) operands.delete_if {|op| op.is_a?(Array) && op[0] == :focus} operands << [:focus, node] end |
#inspect ⇒ String
Returns a developer-friendly representation of this operator.
583 584 585 |
# File 'lib/shex/algebra/operator.rb', line 583 def inspect sprintf("#<%s:%#0x(%s%s)>", self.class.name, __id__, ("id: #{id} " if id), operands.inspect) end |
#iri(value, options = @options) ⇒ RDF::Value
Create URIs
482 483 484 |
# File 'lib/shex/algebra/operator.rb', line 482 def iri(value, = @options) self.class.iri(value, **) end |
#json_type ⇒ Object
343 344 345 |
# File 'lib/shex/algebra/operator.rb', line 343 def json_type self.class.name.split('::').last end |
#matched ⇒ Array<Statement>
On a result instance, the statements that matched this expression.
94 95 96 |
# File 'lib/shex/algebra/operator.rb', line 94 def matched Array((operands.detect {|op| op.is_a?(Array) && op[0] == :matched} || [:matched])[1..-1]) end |
#matched=(statements) ⇒ Object
97 98 99 100 |
# File 'lib/shex/algebra/operator.rb', line 97 def matched=(statements) operands.delete_if {|op| op.is_a?(Array) && op[0] == :matched} operands << statements.unshift(:matched) unless (statements || []).empty? end |
#message ⇒ String
On a result instance, the failure message. (failure only).
138 139 140 |
# File 'lib/shex/algebra/operator.rb', line 138 def (operands.detect {|op| op.is_a?(Array) && op[0] == :message} || [:message])[1..-1] end |
#message=(str) ⇒ Object
141 142 143 144 |
# File 'lib/shex/algebra/operator.rb', line 141 def (str) operands.delete_if {|op| op.is_a?(Array) && op[0] == :message} operands << [:message, str] end |
#not_matched(message, **opts, &block) ⇒ Object
Exception handling
164 165 166 167 168 169 |
# File 'lib/shex/algebra/operator.rb', line 164 def not_matched(, **opts, &block) expression = opts.fetch(:expression, self).satisfy(message: , **opts) exception = opts.fetch(:exception, ShEx::NotMatched) status(, **opts) {(block_given? ? block.call : "") + "expression: #{expression.to_sxp}"} raise exception.new(, expression: expression) end |
#not_satisfied(message, **opts) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/shex/algebra/operator.rb', line 171 def not_satisfied(, **opts) expression = opts.fetch(:expression, self).satisfy(message: , **opts) exception = opts.fetch(:exception, ShEx::NotSatisfied) status(, **opts) {(block_given? ? block.call : "") + "expression: #{expression.to_sxp}"} raise exception.new(, expression: expression) end |
#operand(index = 0) ⇒ RDF::Term
Returns the operand at the given index
.
211 212 213 |
# File 'lib/shex/algebra/operator.rb', line 211 def operand(index = 0) operands[index] end |
#parent ⇒ Operator
Parent expression, if any
629 |
# File 'lib/shex/algebra/operator.rb', line 629 def parent; @options[:parent]; end |
#parent=(operator) ⇒ Operator
Parent operator, if any
635 636 637 |
# File 'lib/shex/algebra/operator.rb', line 635 def parent=(operator) @options[:parent]= operator end |
#references ⇒ RDF::Resource, Operand
References are all operands which are RDF::Resource
233 234 235 |
# File 'lib/shex/algebra/operator.rb', line 233 def references @references = operands.select {|op| op.is_a?(RDF::Resource)} end |
#satisfied ⇒ Array<Operator>
On a result instance, the sub-expressions which were matched.
116 117 118 |
# File 'lib/shex/algebra/operator.rb', line 116 def satisfied Array((operands.detect {|op| op.is_a?(Array) && op[0] == :satisfied} || [:satisfied])[1..-1]) end |
#satisfied=(ops) ⇒ Object
119 120 121 122 |
# File 'lib/shex/algebra/operator.rb', line 119 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.
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/shex/algebra/operator.rb', line 150 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 expression = self.dup expression. = if 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?
79 |
# File 'lib/shex/algebra/operator.rb', line 79 def semact?; false; end |
#semantic_actions ⇒ Array<SemAct>
Semantic Actions
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
565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/shex/algebra/operator.rb', line 565 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 when String {'value' => value} else value.to_h end end |
#status(message, **opts, &block) ⇒ Object
184 185 186 187 |
# File 'lib/shex/algebra/operator.rb', line 184 def status(, **opts, &block) log_debug(self.class.const_get(:NAME).to_s + (@id ? "(#{@id})" : ""), , **opts, &block) true end |
#structure_error(message, **opts) ⇒ Object
178 179 180 181 182 |
# File 'lib/shex/algebra/operator.rb', line 178 def structure_error(, **opts) expression = opts.fetch(:expression, self) exception = opts.fetch(:exception, ShEx::StructureError) log_error(, depth: .fetch(:depth, 0), exception: exception) {"expression: #{expression.to_sxp}"} end |
#to_h ⇒ Hash
Create a hash version of the operator, suitable for turning into JSON.
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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 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 |
# File 'lib/shex/algebra/operator.rb', line 354 def to_h obj = json_type == 'Schema' ? {'@context' => ShEx::CONTEXT} : {} obj['id'] = id.to_s if id obj['type'] = json_type operands.each do |op| case op when Array # First element should be a symbol case sym = op.first when :datatype then obj['datatype'] = op.last.to_s when :exclusions obj['exclusions'] = Array(op[1..-1]).map do |v| case v when Operator then v.to_h else v.to_s end end when :extra then (obj['extra'] ||= []).concat Array(op[1..-1]).map(&:to_s) when :pattern obj['pattern'] = op[1] obj['flags'] = op[2] if op[2] 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 == '*' ? -1 : op.last when :predicate then obj[op.first.to_s] = op.last.to_s 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 obj['start'] = case op.operands.first when RDF::Resource then op.operands.first.to_s else op.operands.first.to_h end when RDF::Value case self when Stem, StemRange obj['stem'] = case op when Operator then op.to_h else op.to_s end when SemAct then obj[op.is_a?(RDF::URI) ? 'name' : 'code'] = op.to_s when TripleConstraint then obj['valueExpr'] = op.to_s when Shape then obj['expression'] = op.to_s when EachOf, OneOf then (obj['expressions'] ||= []) << op.to_s when And, Or then (obj['shapeExprs'] ||= []) << op.to_s when Not then obj['shapeExpr'] = op.to_s when Language then obj['languageTag'] = 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 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 when Not obj['shapeExpr'] = op.to_h else obj['valueExpr'] = op.to_h end when And, Or, Shape, Not 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
347 348 349 |
# File 'lib/shex/algebra/operator.rb', line 347 def to_json( = nil) self.to_h.to_json() end |
#to_sxp(**options) ⇒ String
Returns an S-Expression (SXP) representation of this operator
252 253 254 255 256 |
# File 'lib/shex/algebra/operator.rb', line 252 def to_sxp(**) require 'sparql/algebra/sxp_extensions' to_sxp_bin.to_sxp(**) end |
#to_sxp_bin ⇒ Array
Returns the binary S-Expression (SXP) representation of this operator.
242 243 244 245 246 |
# File 'lib/shex/algebra/operator.rb', line 242 def to_sxp_bin [self.class.const_get(:NAME)] + (id ? [[:id, id]] : []) + (operands || []).map(&:to_sxp_bin) end |
#triple_expression? ⇒ Boolean
Does this operator include TripleExpression?
76 |
# File 'lib/shex/algebra/operator.rb', line 76 def triple_expression?; false; end |
#unmatched ⇒ Array<Statement>
On a result instance, the statements that did not match this expression (failure only).
105 106 107 |
# File 'lib/shex/algebra/operator.rb', line 105 def unmatched Array((operands.detect {|op| op.is_a?(Array) && op[0] == :unmatched} || [:unmatched])[1..-1]) end |
#unmatched=(statements) ⇒ Object
108 109 110 111 |
# File 'lib/shex/algebra/operator.rb', line 108 def unmatched=(statements) operands.delete_if {|op| op.is_a?(Array) && op[0] == :unmatched} operands << statements.unshift(:unmatched) unless (statements || []).empty? end |
#unsatisfied ⇒ Array<Operator>
On a result instance, the sub-satisfieables which were not satisfied. (failure only).
127 128 129 |
# File 'lib/shex/algebra/operator.rb', line 127 def unsatisfied Array((operands.detect {|op| op.is_a?(Array) && op[0] == :unsatisfied} || [:unsatisfied])[1..-1]) end |
#unsatisfied=(ops) ⇒ Object
130 131 132 133 |
# File 'lib/shex/algebra/operator.rb', line 130 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.
A schema must not contain any shape expression S
with negated references, either directly or transitively, to S
.
661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/shex/algebra/operator.rb', line 661 def validate! operands.each do |op| op.validate! if op.respond_to?(:validate!) if op.is_a?(RDF::Resource) && (is_a?(ShapeExpression) || is_a?(TripleExpression)) ref = schema.find(op) structure_error("Missing reference: #{op}") if ref.nil? #if ancestors.unshift(self).include?(ref) # structure_error("Self-recursive reference to #{op}") #end structure_error("Self referencing shape: #{operands.first}") if ref == self end end self end |
#value(value, options = @options) ⇒ RDF::Value
Create Values, with “clever” matching to see if it might be a value, IRI or BNode.
536 537 538 |
# File 'lib/shex/algebra/operator.rb', line 536 def value(value, = @options) self.class.value(value, **) end |