Skip to content

Commit

Permalink
Finish 3.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed May 29, 2022
2 parents 2b73d12 + 0686853 commit bf54bb7
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/generate-docs.yml
Expand Up @@ -19,6 +19,8 @@ jobs:
run: gem install yard --no-document
- name: Build YARD Ruby Documentation
run: yardoc
- name: Copy etc files
run: mkdir -p ./doc/yard/etc && cp ./etc/doap.* ./doc/yard/etc/
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.2.7
3.2.8
2 changes: 1 addition & 1 deletion lib/rdf/model/dataset.rb
Expand Up @@ -79,7 +79,7 @@ def each
#
# @return [String]
def inspect
sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, uri.to_s)
sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, count.to_s)
end

##
Expand Down
5 changes: 3 additions & 2 deletions lib/rdf/query.rb
Expand Up @@ -294,7 +294,7 @@ def optimize!(**options)
# Alias for `:graph_name`.
# @param [Hash{Symbol => Object}] options
# any additional keyword options
# @option options [Hash{Symbol => RDF::Term}] bindings
# @option options [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
# optional variable bindings to use
# @option options [Boolean] :optimize
# Optimize query before execution.
Expand All @@ -313,6 +313,7 @@ def execute(queryable, bindings: {}, solutions: Solution.new, graph_name: nil, n
# Otherwise, a quick empty solution simplifies the logic below; no special case for
# the first pattern
@solutions = Query::Solutions(solutions)
bindings = bindings.to_h if bindings.is_a?(Solution)

# If there are no patterns, just return the empty solution
if empty?
Expand Down Expand Up @@ -341,7 +342,7 @@ def execute(queryable, bindings: {}, solutions: Solution.new, graph_name: nil, n
bindings.each_key do |variable|
if pattern.variables.include?(variable)
unbound_solutions, old_solutions = old_solutions, Query::Solutions()
bindings[variable].each do |binding|
Array(bindings[variable]).each do |binding|
unbound_solutions.each do |solution|
old_solutions << solution.merge(variable => binding)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rdf/query/pattern.rb
Expand Up @@ -160,7 +160,7 @@ def eql?(other)
#
# @param [RDF::Queryable] queryable
# the graph or repository to query
# @param [Hash{Symbol => RDF::Term}] bindings
# @param [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
# optional variable bindings to use
# @yield [statement]
# each matching statement
Expand All @@ -171,6 +171,7 @@ def eql?(other)
# @see RDF::Queryable#query
# @since 0.3.0
def execute(queryable, bindings = {}, &block)
bindings = bindings.to_h if bindings.is_a?(Solution)
query = {
subject: subject.is_a?(Variable) && bindings[subject.to_sym] ? bindings[subject.to_sym] : subject,
predicate: predicate.is_a?(Variable) && bindings[predicate.to_sym] ? bindings[predicate.to_sym] : predicate,
Expand Down
10 changes: 10 additions & 0 deletions spec/query_pattern_spec.rb
Expand Up @@ -599,10 +599,20 @@
let!(:statement) {repo.detect {|s| s.to_a.none?(&:node?)}}
let(:pattern) {described_class.new(:s, :p, :o)}
subject {pattern}

describe "#execute" do
it "executes query against repo" do
expect(subject.execute(repo).to_a.size).to eql repo.count
end

it "executes query with hash bindings" do
expect(subject.execute(repo, {subject: statement.subject}).to_a.size).to be > 0
end

it "executes query with solution bindings" do
soln = RDF::Query::Solution.new(subject: statement.subject)
expect(subject.execute(repo, soln).to_a.size).to be > 0
end
end

describe "#solution" do
Expand Down
21 changes: 21 additions & 0 deletions spec/query_spec.rb
Expand Up @@ -702,6 +702,14 @@
{o: EX.o1}, {o: EX.o4}]
end

it "limits a variable to the initial bindings (solution)" do
query = RDF::Query.new do |query|
query << [EX.x1, EX.p, :o]
end
expect(query.execute(graph, bindings: RDF::Query::Solution.new(o: [EX.o1, EX.o4]))).to have_result_set [
{o: EX.o1}, {o: EX.o4}]
end

it "uses bindings for multiple variables" do
graph << [EX.x1, EX.p1, EX.o1]
graph << [EX.x1, EX.p1, EX.o2]
Expand All @@ -714,6 +722,19 @@
]
end

it "uses bindings for multiple variables (solution)" do
graph << [EX.x1, EX.p1, EX.o1]
graph << [EX.x1, EX.p1, EX.o2]
graph << [EX.x2, EX.p1, EX.o1]
query = RDF::Query.new do |query|
query << [:s, EX.p1, :o]
end
solution = RDF::Query::Solution.new(o: EX.o1, s: EX.x1)
expect(query.execute(graph, bindings: solution)).to have_result_set [
{s: EX.x1, o: EX.o1}
]
end

end

context "solution modifiers" do
Expand Down

0 comments on commit bf54bb7

Please sign in to comment.