Class: SPARQL::Algebra::Operator Abstract

Inherits:
Object
  • Object
show all
Includes:
Expression
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/seconds.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/base.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/uuid.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/compare.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/lcase.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/regex.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/greater_than_or_equal.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/path.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/seq.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/avg.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/if.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/replace.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/and.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/not_equal.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/project.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/count.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/bound.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/month.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/union.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/md5.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/drop.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strbefore.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/struuid.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/less_than.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sum.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/datatype.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/table.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/insert_data.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/timezone.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/asc.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/load.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/bnode.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/insert.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/notin.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/filter.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/construct.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/move.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sample.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/path_opt.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/notexists.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/left_join.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/modify.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/group.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/exprlist.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/is_iri.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/not.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/dataset.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/min.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/rand.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/is_numeric.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/notoneof.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/contains.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/desc.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/day.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/round.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/in.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/divide.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/now.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/delete_data.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/floor.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/encode_for_uri.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/copy.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/abs.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/lang_matches.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/using.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/join.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/alt.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/ucase.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/ceil.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/less_than_or_equal.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/substr.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/extend.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/multiply.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/ask.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sha384.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sequence.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strstarts.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/is_blank.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/reverse.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/bgp.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sha1.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/same_term.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/path_plus.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sha256.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/order.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/coalesce.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/graph.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/or.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/negate.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/equal.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strdt.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strlang.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/add.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/plus.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/year.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/str.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/concat.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/tz.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/create.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/clear.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/group_concat.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/subtract.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/reduced.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/slice.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/minus.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/lang.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/prefix.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/describe.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/delete_where.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strafter.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strends.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/update.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/exists.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/delete.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/sha512.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/is_literal.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/hours.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/iri.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/with.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/greater_than.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/strlen.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/distinct.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/max.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/path_star.rb,
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator/minutes.rb

Overview

This class is abstract.

A SPARQL operator.

Defined Under Namespace

Classes: Abs, Add, Alt, And, Asc, Ask, Avg, BGP, BNode, Base, Binary, Bound, Ceil, Clear, Coalesce, Compare, Concat, Construct, Contains, Copy, Count, Create, Dataset, Datatype, Day, Delete, DeleteData, DeleteWhere, Desc, Describe, Distinct, Divide, Drop, EncodeForURI, Equal, Exists, Exprlist, Extend, Filter, Floor, Graph, GreaterThan, GreaterThanOrEqual, Group, GroupConcat, Hours, IRI, If, In, Insert, InsertData, IsBlank, IsIRI, IsLiteral, IsNumeric, Join, LCase, Lang, LangMatches, LeftJoin, LessThan, LessThanOrEqual, Load, MD5, Max, Min, Minus, Minutes, Modify, Month, Move, Multiply, Negate, Not, NotEqual, NotExists, NotIn, NotOneOf, Now, Nullary, Or, Order, Path, PathOpt, PathPlus, PathStar, Plus, Prefix, Project, Quaternary, Rand, Reduced, Regex, Replace, Reverse, Round, SHA1, SHA256, SHA384, SHA512, SameTerm, Sample, Seconds, Seq, Sequence, Slice, Str, StrAfter, StrBefore, StrDT, StrEnds, StrLang, StrLen, StrStarts, StrUUID, SubStr, Subtract, Sum, TZ, Table, Ternary, Timezone, UCase, UUID, Unary, Union, Update, Using, With, Year

Constant Summary collapse

ARITY =

variable arity

-1 # variable arity
IsURI =
IsIRI
URI =
IRI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Expression

cast, #evaluate, extension, extensions, #invalid?, new, open, parse, register_extension, #valid?

Constructor Details

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

Initializes a new operator instance.

Overloads:

  • #initialize(*operands) ⇒ Operator

    Parameters:

  • #initialize(*operands, options) ⇒ Operator

    Parameters:

    Options Hash (options):

    • :memoize (Boolean) — default: false

      whether to memoize results for particular operands

Raises:

  • (TypeError)

    if any operand is invalid



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 341

def initialize(*operands)
  @options  = operands.last.is_a?(Hash) ? operands.pop.dup : {}
  @operands = operands.map! do |operand|
    case operand
      when Array
        operand.each {|op| op.parent = self if operand.respond_to?(:parent=)}
        operand
      when Operator, Variable, 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
        nil
      else raise TypeError, "invalid SPARQL::Algebra::Operator operand: #{operand.inspect}"
    end
  end
end

Instance Attribute Details

#operandsArray (readonly)

The operands to this operator.

Returns:



418
419
420
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 418

def operands
  @operands
end

Class Method Details

.arityInteger

Returns the arity of this operator class.

Examples:

Operator.arity           #=> -1
Operator::Nullary.arity  #=> 0
Operator::Unary.arity    #=> 1
Operator::Binary.arity   #=> 2
Operator::Ternary.arity  #=> 3

Returns:

  • (Integer)

    an integer in the range (-1..3)



322
323
324
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 322

def self.arity
  self.const_get(:ARITY)
end

.base_uriRDF::URI

Base URI used for reading data sources with relative URIs

Returns:



372
373
374
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 372

def self.base_uri
  @base_uri
end

.base_uri=(uri) ⇒ RDF::URI

Set Base URI associated with SPARQL document, typically done when reading SPARQL from a URI

Parameters:

Returns:



382
383
384
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 382

def self.base_uri=(uri)
  @base_uri = RDF::URI(uri)
end

.evaluate(*operands) ⇒ RDF::Term

Parameters:

Returns:

See Also:



307
308
309
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 307

def self.evaluate(*operands)
  self.new(*operands).evaluate(RDF::Query::Solution.new)
end

.for(name, arity = nil) ⇒ Class

Returns an operator class for the given operator name.

Parameters:

Returns:

  • (Class)

    an operator class, or nil if an operator was not found



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 157

def self.for(name, arity = nil)
  # TODO: refactor this to dynamically introspect loaded operator classes.
  case (name.to_s.downcase.to_sym rescue nil)
    when :'!='            then NotEqual
    when :'/'             then Divide
    when :'='             then Equal
    when :*               then Multiply
    when :+               then Plus
    when :-               then arity.eql?(1) ? Negate : Subtract
    when :<               then LessThan
    when :<=              then LessThanOrEqual
    when :<=>             then Compare # non-standard
    when :>               then GreaterThan
    when :>=              then GreaterThanOrEqual
    when :abs             then Abs
    when :add             then Add
    when :alt             then Alt
    when :and, :'&&'      then And
    when :avg             then Avg
    when :bnode           then BNode
    when :bound           then Bound
    when :coalesce        then Coalesce
    when :ceil            then Ceil
    when :concat          then Concat
    when :contains        then Contains
    when :count           then Count
    when :datatype        then Datatype
    when :day             then Day
    when :encode_for_uri  then EncodeForURI
    when :divide          then Divide
    when :exists          then Exists
    when :floor           then Floor
    when :group_concat    then GroupConcat
    when :hours           then Hours
    when :if              then If
    when :in              then In
    when :iri, :uri       then IRI
    when :isblank         then IsBlank
    when :isiri           then IsIRI
    when :isliteral       then IsLiteral
    when :isnumeric       then IsNumeric
    when :isuri           then IsIRI # alias
    when :lang            then Lang
    when :langmatches     then LangMatches
    when :lcase           then LCase
    when :md5             then MD5
    when :max             then Max
    when :min             then Min
    when :minus           then Minus
    when :minutes         then Minutes
    when :month           then Month
    when :multiply        then Multiply
    when :not, :'!'       then Not
    when :notexists       then NotExists
    when :notin           then NotIn
    when :notoneof        then NotOneOf
    when :now             then Now
    when :or, :'||'       then Or
    when :path            then Path
    when :path?           then PathOpt
    when :"path*"         then PathStar
    when :"path+"         then PathPlus
    when :plus            then Plus
    when :rand            then Rand
    when :regex           then Regex
    when :replace         then Replace
    when :reverse         then Reverse
    when :round           then Round
    when :sameterm        then SameTerm
    when :sample          then Sample
    when :seconds         then Seconds
    when :seq             then Seq
    when :sequence        then Sequence
    when :sha1            then SHA1
    when :sha256          then SHA256
    when :sha512          then SHA512
    when :str             then Str
    when :strafter        then StrAfter
    when :strbefore       then StrBefore
    when :strdt           then StrDT
    when :strends         then StrEnds
    when :strlang         then StrLang
    when :strlen          then StrLen
    when :strstarts       then StrStarts
    when :struuid         then StrUUID
    when :substr          then SubStr
    when :subtract        then Subtract
    when :sum             then Sum
    when :timezone        then Timezone
    when :tz              then TZ
    when :ucase           then UCase
    when :uuid            then UUID
    when :year            then Year

    # Miscellaneous
    when :asc             then Asc
    when :desc            then Desc
    when :exprlist        then Exprlist

    # Datasets
    when :dataset         then Dataset

    # Query forms
    when :ask             then Ask
    when :base            then Base
    when :bgp             then BGP
    when :construct       then Construct
    when :describe        then Describe
    when :distinct        then Distinct
    when :extend          then Extend
    when :filter          then Filter
    when :graph           then Graph
    when :group           then Group
    when :join            then Join
    when :leftjoin        then LeftJoin
    when :order           then Order
    when :minus           then Minus
    when :prefix          then Prefix
    when :project         then Project
    when :reduced         then Reduced
    when :slice           then Slice
    when :table           then Table
    when :triple          then RDF::Query::Pattern
    when :union           then Union

    # Update forms
    when :add             then Add
    when :clear           then Clear
    when :copy            then Copy
    when :create          then Create
    when :delete          then Delete
    when :deletedata      then DeleteData
    when :deletewhere     then DeleteWhere
    when :drop            then Drop
    when :insert          then Insert
    when :insertdata      then InsertData
    when :load            then Load
    when :modify          then Modify
    when :move            then Move
    when :update          then Update
    when :using           then Using
    when :with            then With
    else                       nil # not found
  end
end

.prefixesHash{Symbol => RDF::URI}

Prefixes useful for future serialization

Returns:



400
401
402
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 400

def self.prefixes
  @prefixes
end

.prefixes=(hash) ⇒ Hash{Symbol => RDF::URI}

Prefixes useful for future serialization

Parameters:

Returns:



410
411
412
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 410

def self.prefixes=(hash)
  @prefixes = hash
end

Instance Method Details

#aggregate?Boolean

Returns true if this is an aggregate

Overridden in evaluatables which are aggregates

Returns:

  • (Boolean)

    true or false



485
486
487
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 485

def aggregate?
  respond_to?(:aggregate)
end

#base_uriRDF::URI

Base URI used for reading data sources with relative URIs

Returns:



364
365
366
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 364

def base_uri
  Operator.base_uri
end

#boolean(literal) ⇒ RDF::Literal::Boolean (protected)

Returns the effective boolean value (EBV) of the given literal.

Parameters:

Returns:

Raises:

  • (TypeError)

    if the literal could not be coerced to an RDF::Literal::Boolean

See Also:



651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 651

def boolean(literal)
  case literal
    when FalseClass then RDF::Literal::FALSE
    when TrueClass  then RDF::Literal::TRUE
    when RDF::Literal::Boolean
      # If the argument is a typed literal with a datatype of
      # `xsd:boolean`, the EBV is the value of that argument.
      # However, the EBV of any literal whose type is `xsd:boolean` is
      # false if the lexical form is not valid for that datatype.
      RDF::Literal(literal.valid? && literal.true?)
    when RDF::Literal::Numeric
      # If the argument is a numeric type or a typed literal with a
      # datatype derived from a numeric type, the EBV is false if the
      # operand value is NaN or is numerically equal to zero; otherwise
      # the EBV is true.
      # However, the EBV of any literal whose type is numeric is
      # false if the lexical form is not valid for that datatype.
      RDF::Literal(literal.valid? && !(literal.zero?) && !(literal.respond_to?(:nan?) && literal.nan?))
    else case
      when literal.is_a?(RDF::Literal) && literal.plain?
        # If the argument is a plain literal or a typed literal with a
        # datatype of `xsd:string`, the EBV is false if the operand value
        # has zero length; otherwise the EBV is true.
        RDF::Literal(!(literal.value.empty?))
      else
        # All other arguments, including unbound arguments, produce a type error.
        raise TypeError, "could not coerce #{literal.inspect} to an RDF::Literal::Boolean"
    end
  end
end

#constant?Boolean

Returns true if none of the operands are variables, false otherwise.

Returns:

  • (Boolean)

    true or false

See Also:



475
476
477
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 475

def constant?
  !(variable?)
end

#each_descendant {|operator| ... } ⇒ Enumerator Also known as: descendants, each

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

Yields:

  • operator

Yield Parameters:

Returns:

  • (Enumerator)


591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 591

def each_descendant(&block)
  if block_given?
    operands.each do |operand|
      case operand
      when Array
        operand.each do |op|
          op.each_descendant(&block) if op.respond_to?(:each_descendant)
          block.call(op)
        end
      else
        operand.each_descendant(&block) if operand.respond_to?(:each_descendant)
      end
      block.call(operand)
    end
  end
  enum_for(:each_descendant)
end

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

Parameters:

Returns:

  • (Boolean)


567
568
569
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 567

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

#evaluatable?Boolean

Returns true if this is evaluatable (i.e., returns values for a binding), false otherwise.

Returns:

  • (Boolean)

    true or false



456
457
458
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 456

def evaluatable?
  respond_to?(:evaluate)
end

#executable?Boolean

Returns true if this is executable (i.e., contains a graph patterns), false otherwise.

Returns:

  • (Boolean)

    true or false



465
466
467
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 465

def executable?
  respond_to?(:execute)
end

#first_ancestor(klass) ⇒ Operator

First ancestor operator of type klass

Parameters:

  • klass (Class)

Returns:



630
631
632
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 630

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

#inspectString

Returns a developer-friendly representation of this operator.

Returns:



560
561
562
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 560

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

#ndvarsArray<RDF::Query::Variable>

Return the non-destinguished variables contained within this operator



575
576
577
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 575

def ndvars
  vars.reject(&:distinguished?)
end

#node?Boolean

Returns true if any of the operands are nodes, false otherwise.

Returns:

  • (Boolean)


445
446
447
448
449
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 445

def node?
  operands.any? do |operand|
    operand.respond_to?(:node?) ? operand.node? : operand.node?
  end
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:



426
427
428
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 426

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

#optimizeSPARQL::Algebra::Expression

Returns an optimized version of this expression.

For constant expressions containing no variables, returns the result of evaluating the expression with empty bindings; otherwise returns self.

Optimization is not possible if the expression raises an exception, such as a TypeError or ZeroDivisionError, which must be conserved at runtime.



501
502
503
504
505
506
507
508
509
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 501

def optimize
  if constant?
    # Note that if evaluation results in a `TypeError` or other error,
    # we must return `self` so that the error is conserved at runtime:
    evaluate(RDF::Query::Solution.new) rescue self
  else
    super # returns `self`
  end
end

#parentOperator

Parent expression, if any

Returns:



615
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 615

def parent; @options[:parent]; end

#parent=(operator) ⇒ Operator

Parent operator, if any

Returns:



621
622
623
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 621

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

#prefixesHash{Symbol => RDF::URI}

Prefixes useful for future serialization

Returns:



391
392
393
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 391

def prefixes
  Operator.prefixes
end

#rewrite {|[]| ... } ⇒ SPARQL::Algebra::Expression

Rewrite operands by yielding each operand. Recursively descends through operands implementing this method.

Yields:

  • operand

Yield Parameters:

  • []

    operand

Yield Returns:

Returns:



519
520
521
522
523
524
525
526
527
528
529
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 519

def rewrite(&block)
  @operands = @operands.map do |op|
    # Rewrite the operand
    unless new_op = block.call(op)
      # Not re-written, rewrite
      new_op = op.respond_to?(:rewrite) ? op.rewrite(&block) : op
    end
    new_op
  end
  self
end

#to_binary(klass, *expressions) ⇒ SPARQL::Algebra::Expression (protected)

Transform an array of expressions into a recursive set of binary operations e.g.: a || b || c => (|| a (|| b c))

Parameters:

Returns:



689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 689

def to_binary(klass, *expressions)
  case expressions.length
  when 0
    # Oops!
    raise "Operator#to_binary requires two or more expressions"
  when 1
    expressions.first
  when 2
    klass.new(*expressions)
  else
    klass.new(expressions.shift, to_binary(klass, *expressions))
  end
end

#to_sxpString

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

Returns:



545
546
547
548
549
550
551
552
553
554
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 545

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 SPARQL S-Expression (SSE) representation of this operator.

Returns:

See Also:



536
537
538
539
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 536

def to_sxp_bin
  operator = [self.class.const_get(:NAME)].flatten.first
  [operator, *(operands || []).map(&:to_sxp_bin)]
end

#validate!SPARQL::Algebra::Expression

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

Returns:

Raises:

  • (ArgumentError)

    if the value is invalid



638
639
640
641
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 638

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

#variable?Boolean

Returns true if any of the operands are variables, false otherwise.

Returns:

  • (Boolean)

    true or false

See Also:



436
437
438
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 436

def variable?
  operands.any?(&:variable?)
end

#varsArray<RDF::Query::Variable>

Return the variables contained within this operator



582
583
584
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/operator.rb', line 582

def vars
  operands.select {|o| o.respond_to?(:vars)}.map(&:vars).flatten
end