Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

In RDF::Query, add :name option as alias for :context, to be more RDF…

… 1.1 like.
  • Loading branch information...
commit b9aa1e4ca5f799921790b704d9c5e7b1a9593153 1 parent 58f757f
@gkellogg gkellogg authored
Showing with 29 additions and 16 deletions.
  1. +29 −16 lib/rdf/query.rb
View
45 lib/rdf/query.rb
@@ -129,10 +129,12 @@ def self.execute(queryable, patterns = nil, options = {}, &block)
# @option options [RDF::Resource, RDF::Query::Variable, false] :context (nil)
# Default context for matching against queryable.
# Named queries either match against a specifically named
- # contexts if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
- # Names that are against unbound variables match either detault
- # or named contexts.
+ # graphs if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
+ # Names that are against unbound variables match either default
+ # or named graphs.
# The name of `false` will only match against the default context.
+ # @option options [RDF::Resource, RDF::Query::Variable, false] :name (nil)
+ # Alias for `:context`.
# @yield [query]
# @yieldparam [RDF::Query] query
# @yieldreturn [void] ignored
@@ -146,9 +148,11 @@ def self.execute(queryable, patterns = nil, options = {}, &block)
# @option options [RDF::Resource, RDF::Query::Variable, false] :context (nil)
# Default context for matching against queryable.
# Named queries either match against a specifically named
- # contexts if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
- # Names that are against unbound variables match either detault
- # or named contexts.
+ # graphs if the name is an {RDF::Resource} or bound {RDF::Query::Variable}.
+ # Names that are against unbound variables match either default
+ # or named graphs.
+ # @option options [RDF::Resource, RDF::Query::Variable, false] :name (nil)
+ # Alias for `:context`.
# @yield [query]
# @yieldparam [RDF::Query] query
# @yieldreturn [void] ignored
@@ -157,7 +161,7 @@ def initialize(*patterns, &block)
patterns << @options if patterns.empty?
@variables = {}
@solutions = @options.delete(:solutions) || Solutions.new
- context = @options.delete(:context)
+ context = @options.delete(:context) || @options.delete(:name)
@patterns = case patterns.first
when Hash then compile_hash_patterns(HashPatternNormalizer.normalize!(patterns.first.dup, @options))
@@ -246,6 +250,8 @@ def optimize!(options = {})
# @option options [RDF::Resource, RDF::Query::Variable, false] context (nil)
# Specific context for matching against queryable;
# overrides default context defined on query.
+ # @option options [RDF::Resource, RDF::Query::Variable, false] name (nil)
+ # Alias for `:context`.
# @option options [Hash{Symbol => RDF::Term}] solutions
# optional initial solutions for chained queries
# @return [RDF::Query::Solutions]
@@ -264,7 +270,7 @@ def execute(queryable, options = {})
@solutions = options[:solutions] || (Solutions.new << RDF::Query::Solution.new({}))
patterns = @patterns
- context = options.fetch(:context, self.context)
+ context = options.fetch(:context, options.fetch(:name, self.context))
# Add context to pattern, if necessary
unless context.nil?
@@ -349,27 +355,34 @@ def +(other)
Query.new(self.patterns + other.patterns)
end
- # Is this is a named query?
+ # Is this query scoped to a named graph?
# @return [Boolean]
def named?
!!options[:context]
end
- # Is this is an unamed query?
+ # Is this query scoped to the default graph?
+ # @return [Boolean]
+ def default?
+ options[:context] == false
+ end
+
+ # Is this query unscoped? This indicates that it can return results from
+ # either a named graph or the default graph.
# @return [Boolean]
def unnamed?
- !named?
+ options[:context].nil?
end
- # Add name to query
- # @param [RDF::Value] value
- # @return [RDF::Value]
+ # Scope the query to named graphs matching value
+ # @param [RDF::IRI, RDF::Query::Variable] value
+ # @return [RDF::IRI, RDF::Query::Variable]
def context=(value)
options[:context] = value
end
- # Name of this query, if any
- # @return [RDF::Value]
+ # Scope of this query, if any
+ # @return [RDF::IRI, RDF::Query::Variable]
def context
options[:context]
end
Please sign in to comment.
Something went wrong with that request. Please try again.