Skip to content

Commit bf54bb7

Browse files
committed
Finish 3.2.8
2 parents 2b73d12 + 0686853 commit bf54bb7

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

.github/workflows/generate-docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
run: gem install yard --no-document
2020
- name: Build YARD Ruby Documentation
2121
run: yardoc
22+
- name: Copy etc files
23+
run: mkdir -p ./doc/yard/etc && cp ./etc/doap.* ./doc/yard/etc/
2224
- name: Deploy
2325
uses: peaceiris/actions-gh-pages@v3
2426
with:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.7
1+
3.2.8

lib/rdf/model/dataset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def each
7979
#
8080
# @return [String]
8181
def inspect
82-
sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, uri.to_s)
82+
sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, count.to_s)
8383
end
8484

8585
##

lib/rdf/query.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def optimize!(**options)
294294
# Alias for `:graph_name`.
295295
# @param [Hash{Symbol => Object}] options
296296
# any additional keyword options
297-
# @option options [Hash{Symbol => RDF::Term}] bindings
297+
# @option options [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
298298
# optional variable bindings to use
299299
# @option options [Boolean] :optimize
300300
# Optimize query before execution.
@@ -313,6 +313,7 @@ def execute(queryable, bindings: {}, solutions: Solution.new, graph_name: nil, n
313313
# Otherwise, a quick empty solution simplifies the logic below; no special case for
314314
# the first pattern
315315
@solutions = Query::Solutions(solutions)
316+
bindings = bindings.to_h if bindings.is_a?(Solution)
316317

317318
# If there are no patterns, just return the empty solution
318319
if empty?
@@ -341,7 +342,7 @@ def execute(queryable, bindings: {}, solutions: Solution.new, graph_name: nil, n
341342
bindings.each_key do |variable|
342343
if pattern.variables.include?(variable)
343344
unbound_solutions, old_solutions = old_solutions, Query::Solutions()
344-
bindings[variable].each do |binding|
345+
Array(bindings[variable]).each do |binding|
345346
unbound_solutions.each do |solution|
346347
old_solutions << solution.merge(variable => binding)
347348
end

lib/rdf/query/pattern.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def eql?(other)
160160
#
161161
# @param [RDF::Queryable] queryable
162162
# the graph or repository to query
163-
# @param [Hash{Symbol => RDF::Term}] bindings
163+
# @param [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
164164
# optional variable bindings to use
165165
# @yield [statement]
166166
# each matching statement
@@ -171,6 +171,7 @@ def eql?(other)
171171
# @see RDF::Queryable#query
172172
# @since 0.3.0
173173
def execute(queryable, bindings = {}, &block)
174+
bindings = bindings.to_h if bindings.is_a?(Solution)
174175
query = {
175176
subject: subject.is_a?(Variable) && bindings[subject.to_sym] ? bindings[subject.to_sym] : subject,
176177
predicate: predicate.is_a?(Variable) && bindings[predicate.to_sym] ? bindings[predicate.to_sym] : predicate,

spec/query_pattern_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,20 @@
599599
let!(:statement) {repo.detect {|s| s.to_a.none?(&:node?)}}
600600
let(:pattern) {described_class.new(:s, :p, :o)}
601601
subject {pattern}
602+
602603
describe "#execute" do
603604
it "executes query against repo" do
604605
expect(subject.execute(repo).to_a.size).to eql repo.count
605606
end
607+
608+
it "executes query with hash bindings" do
609+
expect(subject.execute(repo, {subject: statement.subject}).to_a.size).to be > 0
610+
end
611+
612+
it "executes query with solution bindings" do
613+
soln = RDF::Query::Solution.new(subject: statement.subject)
614+
expect(subject.execute(repo, soln).to_a.size).to be > 0
615+
end
606616
end
607617

608618
describe "#solution" do

spec/query_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@
702702
{o: EX.o1}, {o: EX.o4}]
703703
end
704704

705+
it "limits a variable to the initial bindings (solution)" do
706+
query = RDF::Query.new do |query|
707+
query << [EX.x1, EX.p, :o]
708+
end
709+
expect(query.execute(graph, bindings: RDF::Query::Solution.new(o: [EX.o1, EX.o4]))).to have_result_set [
710+
{o: EX.o1}, {o: EX.o4}]
711+
end
712+
705713
it "uses bindings for multiple variables" do
706714
graph << [EX.x1, EX.p1, EX.o1]
707715
graph << [EX.x1, EX.p1, EX.o2]
@@ -714,6 +722,19 @@
714722
]
715723
end
716724

725+
it "uses bindings for multiple variables (solution)" do
726+
graph << [EX.x1, EX.p1, EX.o1]
727+
graph << [EX.x1, EX.p1, EX.o2]
728+
graph << [EX.x2, EX.p1, EX.o1]
729+
query = RDF::Query.new do |query|
730+
query << [:s, EX.p1, :o]
731+
end
732+
solution = RDF::Query::Solution.new(o: EX.o1, s: EX.x1)
733+
expect(query.execute(graph, bindings: solution)).to have_result_set [
734+
{s: EX.x1, o: EX.o1}
735+
]
736+
end
737+
717738
end
718739

719740
context "solution modifiers" do

0 commit comments

Comments
 (0)