Class: SPARQL::Algebra::Operator::Dataset

Inherits:
Binary show all
Includes:
Query
Defined in:
lib/sparql/algebra/operator/dataset.rb

Overview

The SPARQL GraphPattern dataset operator.

Instintiated with two operands, the first being an array of data source URIs, either bare, indicating a default dataset, or expressed as an array [:named, ], indicating that it represents a named data source.

Examples:

(prefix ((: <http://example/>))
  (dataset (<data-g1.ttl> (named <data-g2.ttl>))
    (bgp (triple ?s ?p ?o))))

See Also:

Constant Summary

NAME =
[:dataset]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Query

#context=, #each_solution, #failed?, #matched?, #unshift, #variables

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Evaluatable

#apply, #evaluate, #memoize

Methods included from Expression

cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

#execute(queryable, options = {}) ⇒ RDF::Query::Solutions

Executes this query on the given queryable graph or repository. Reads specified data sources into queryable. Named data sources are added using a context of the data source URI.

Datasets are specified in operand(1), which is an array of default or named graph URIs.



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

def execute(queryable, options = {})
  debug("Dataset", options)
  operand(0).each do |ds|
    load_opts = {}
    case ds
    when Array
      uri = if self.base_uri
        u = self.base_uri.join(ds.last)
        u.lexical = "<#{ds.last}>" unless u.to_s == ds.last.to_s
        u
      else
        ds.last
      end
      uri = self.base_uri ? self.base_uri.join(ds.last) : ds.last
      uri.lexical = ds.last
      load_opts[:context] = uri
      debug("=> read named data source #{uri}", options)
    else
      uri = self.base_uri ? self.base_uri.join(ds) : ds
      debug("=> read default data source #{uri}", options)
    end
    queryable.load(uri.to_s, load_opts)
  end

  @solutions = operands.last.execute(queryable, options.merge(:depth => options[:depth].to_i + 1))
end

#optimizeUnion, RDF::Query

Returns an optimized version of this query.

If optimize operands, and if the first two operands are both Queries, replace with the unique sum of the query elements



69
70
71
# File 'lib/sparql/algebra/operator/dataset.rb', line 69

def optimize
  operands.last.optimize
end