Sha256: a240bc86201caa0d63c2cb28c10e0153f8d24580bd717bfa34906767bd37a927

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

# FIXME: This depends on an update to RDF::Query#execute to be able to pass the context as an option.
module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL GraphPattern `graph` operator.
    #
    # This is a wrapper to add a `context` to the query.
    #
    # @example
    #   (prefix ((: <http://example/>))
    #     (graph ?g
    #       (bgp (triple ?s ?p ?o))))
    #
    # @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
    class Graph < Operator::Binary
      include Query
      
      NAME = [:graph]

      ##
      # Executes this query on the given `queryable` graph or repository.
      # Applies the given `context` to the query, limiting the scope of the query to the specified `context`, which may be an `RDF::URI` or `RDF::Query::Variable`.
      #
      # @param  [RDF::Queryable] queryable
      #   the graph or repository to query
      # @param  [Hash{Symbol => Object}] options
      #   any additional keyword options
      # @return [RDF::Query::Solutions]
      #   the resulting solution sequence
      # @see    http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
      def execute(queryable, options = {})
        debug(options) {"Graph #{operands.first}"}
        context, query = operands.first, operands.last
        @solutions = query.execute(queryable, options.merge(:context => context))
        debug(options) {"=>(after) #{@solutions.map(&:to_hash).inspect}"}
        @solutions
      end
      
      ##
      # Returns an optimized version of this query.
      #
      # Return optimized query
      #
      # @return [Union, RDF::Query] `self`
      def optimize
        operands = operands.map(&:optimize)
      end
      
      ##
      # Don't do any more rewriting
      # @return [SPARQL::Algebra::Expression] `self`
      def rewrite(&block)
        self
      end
    end # Graph
  end # Operator
end; end # SPARQL::Algebra

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sparql-1.1.1 lib/sparql/algebra/operator/graph.rb
sparql-1.1.0 lib/sparql/algebra/operator/graph.rb
sparql-1.1.0p0 lib/sparql/algebra/operator/graph.rb
sparql-1.0.8 lib/sparql/algebra/operator/graph.rb
sparql-1.0.7 lib/sparql/algebra/operator/graph.rb
sparql-1.0.6 lib/sparql/algebra/operator/graph.rb
sparql-1.0.5 lib/sparql/algebra/operator/graph.rb
sparql-1.0.4 lib/sparql/algebra/operator/graph.rb
sparql-1.0.3 lib/sparql/algebra/operator/graph.rb
sparql-1.0.2 lib/sparql/algebra/operator/graph.rb