diff --git a/README.md b/README.md index a016b577..43130862 100755 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ Then, use the function in a query: See {SPARQL::Algebra::Expression.register_extension} for details. +### Variable Pre-binding + +A call to execute a parsed query can include pre-bound variables, which cause queries to be executed with matching variables bound as defined. Variable pre-binding can be done using a Hash structure, or a Query Solution. See [Query with Binding example](#query-with-binding) and {SPARQL::Algebra::Query#execute}. + ### SPARQLStar (SPARQL-star) The gem supports [SPARQL-star][] where patterns may include sub-patterns recursively, for a kind of Reification. @@ -287,6 +291,20 @@ a full set of RDF formats. query = SPARQL::Algebra.parse(%{(bgp (triple ?s ?p ?o))}) sparql = query.to_sparql #=> "SELECT * WHERE { ?s ?p ?o }" +### Query with Binding + + bindings = {page: RDF::URI("https://greggkellogg.net/")} + queryable = RDF::Repository.load("etc/doap.ttl") + query = SPARQL.parse(%( + PREFIX foaf: + SELECT ?person + WHERE { + ?person foaf:homepage ?page . + } + )) + solutions = query.execute(queryable, bindings: bindings) + solutions.to_sxp #=> (((person ))) + ### Command line processing sparql execute --dataset etc/doap.ttl etc/from_default.rq diff --git a/VERSION b/VERSION index be94e6f5..b347b11e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.2 +3.2.3 diff --git a/lib/sparql/algebra/query.rb b/lib/sparql/algebra/query.rb index 2ff4d5e9..3e3db8ab 100644 --- a/lib/sparql/algebra/query.rb +++ b/lib/sparql/algebra/query.rb @@ -38,7 +38,9 @@ def variables # the graph or repository to query # @param [Hash{Symbol => Object}] options # any additional keyword options - # @option options [Boolean] debug + # @option options [RDF::Query::Solution] :bindings + # a query solution containing zero or more variable bindings + # @option options [Boolean] :debug # Query execution debugging # @option options [RDF::Term, RDF::Query::Variable] :graph_name # @yield [solution] diff --git a/spec/readme_spec.rb b/spec/readme_spec.rb index 882f6f00..1e2836cb 100644 --- a/spec/readme_spec.rb +++ b/spec/readme_spec.rb @@ -16,7 +16,7 @@ def self.read_examples case title when "Command line processing" code.split("\n").reject {|c| c =~ /^\s*(?:#.*)?$/}.each do |command| - examples << {title: command, sh: command} + examples << {title: "#{title}: #{command.strip}", sh: command} end else examples << {title: title, eval_true: code}