diff --git a/VERSION b/VERSION index d169b2f..c5d54ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.8 +0.0.9 diff --git a/lib/sparql/algebra/extensions.rb b/lib/sparql/algebra/extensions.rb index cd6836f..4c3f8d1 100644 --- a/lib/sparql/algebra/extensions.rb +++ b/lib/sparql/algebra/extensions.rb @@ -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] 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 diff --git a/lib/sparql/algebra/operator.rb b/lib/sparql/algebra/operator.rb index 2b6bee9..a0d0468 100644 --- a/lib/sparql/algebra/operator.rb +++ b/lib/sparql/algebra/operator.rb @@ -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' @@ -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 diff --git a/lib/sparql/algebra/operator/bgp.rb b/lib/sparql/algebra/operator/bgp.rb new file mode 100644 index 0000000..48ee6eb --- /dev/null +++ b/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 ((: )) + # (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 diff --git a/spec/query_spec.rb b/spec/query_spec.rb index 19c2fe7..36296de 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -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 () (bgp)))) lambda {query.execute(queryable)}.should raise_error(TypeError)