Skip to content
This repository has been archived by the owner on Dec 29, 2017. It is now read-only.

Commit

Permalink
Implement operator/bgp instead of using RDF::Query directly, set cont…
Browse files Browse the repository at this point in the history
…ext = false.

Don't set context = false for graphs with a nil context, as this was modifying behavior of other packages that include sparql..
  • Loading branch information
gkellogg committed Aug 31, 2011
1 parent 058b98a commit ae5c1a8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 52 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.0.8
0.0.9
49 changes: 0 additions & 49 deletions lib/sparql/algebra/extensions.rb
Expand Up @@ -177,55 +177,6 @@ def concise_bounded_description(*terms, &block)
end

class RDF::Query
alias_method :initialize_without_expression, :initialize
##
# Initializes a new basic graph pattern query.
#
# @overload initialize(patterns = [], options = {})
# @param [Array<RDF::Query::Pattern>] patterns
# ...
# @param [Hash{Symbol => Object}] options
# any additional keyword options
# @option options [RDF::Query::Solutions] :solutions (Solutions.new)
# @option options [RDF::Term, RDF::Query::Variable, Boolean] :context (false)
# Default context for matching against queryable.
# Named queries either match against a specifically named
# contexts if the name is an RDF::Term or bound RDF::Query::Variable.
# Names that are against unbound variables match either detault
# or named contexts.
# The name of `false' will only match against the default context.
# @yield [query]
# @yieldparam [RDF::Query] query
# @yieldreturn [void] ignored
#
# @overload initialize(patterns, options = {})
# @param [Hash{Object => Object}] patterns
# ...
# @param [Hash{Symbol => Object}] options
# any additional keyword options
# @option options [RDF::Query::Solutions] :solutions (Solutions.new)
# @option options [RDF::Term, RDF::Query::Variable, Boolean] :context (false)
# Default context for matching against queryable.
# Named queries either match against a specifically named
# contexts if the name is an RDF::Term or bound RDF::Query::Variable.
# Names that are against unbound variables match either detault
# or named contexts.
# @yield [query]
# @yieldparam [RDF::Query] query
# @yieldreturn [void] ignored
def initialize(*patterns, &block)
initialize_without_expression(*patterns) do
self.context = false if self.context.nil?

if block_given?
case block.arity
when 0 then instance_eval(&block)
else block.call(self)
end
end
end
end

# Equivalence for Queries:
# Same Patterns
# Same Context
Expand Down
3 changes: 2 additions & 1 deletion lib/sparql/algebra/operator.rb
Expand Up @@ -45,6 +45,7 @@ class Operator
# Query operators
autoload :Ask, 'sparql/algebra/operator/ask'
autoload :Base, 'sparql/algebra/operator/base'
autoload :BGP, 'sparql/algebra/operator/bgp'
autoload :Construct, 'sparql/algebra/operator/construct'
autoload :Dataset, 'sparql/algebra/operator/dataset'
autoload :Describe, 'sparql/algebra/operator/describe'
Expand Down Expand Up @@ -112,7 +113,7 @@ def self.for(name, arity = nil)
# Query forms
when :ask then Ask
when :base then Base
when :bgp then RDF::Query
when :bgp then BGP
when :construct then Construct
when :describe then Describe
when :distinct then Distinct
Expand Down
26 changes: 26 additions & 0 deletions lib/sparql/algebra/operator/bgp.rb
@@ -0,0 +1,26 @@
module SPARQL; module Algebra
class Operator
##
# The SPARQL GraphPattern `bgp` operator.
#
# Query with `context` set to false.
#
# @example
# (prefix ((: <http://example/>))
# (bgp (triple ?s ?p ?o)))
#
# @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
class BGP < Operator
NAME = [:bgp]
##
# A `graph` is an RDF::Query with a context.
#
# @param [RDF::URI, RDF::Query::Variable] context
# @param [RDF::Query] bgp
# @return [RDF::Query]
def self.new(*patterns)
RDF::Query.new(*patterns, :context => false)
end
end # BGP
end # Operator
end; end # SPARQL::Algebra
2 changes: 1 addition & 1 deletion spec/query_spec.rb
Expand Up @@ -830,7 +830,7 @@
query.execute(queryable)
end

it "raises error when loading into non-mutable queryable", :focus => true do
it "raises error when loading into non-mutable queryable" do
queryable = RDF::Repository.new
query = SPARQL::Algebra::Expression.parse(%q((dataset (<data-g1.ttl>) (bgp))))
lambda {query.execute(queryable)}.should raise_error(TypeError)
Expand Down

0 comments on commit ae5c1a8

Please sign in to comment.