Skip to content

Commit 02340e8

Browse files
committed
Update Repository to remember statement options along with object, and not simply the object itself. This allows inferred statements to be added to the repo, and come back as having been inferred.
1 parent 2171105 commit 02340e8

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

lib/rdf/model/statement.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def self.from(statement, graph_name: nil, **options)
5757
# @return [RDF::Term]
5858
attr_accessor :object
5959

60+
# @return [Hash{Symbol => Object}]
61+
attr_accessor :options
62+
6063
##
6164
# @overload initialize(**options)
6265
# @param [Hash{Symbol => Object}] options

lib/rdf/repository.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ def each_statement(&block)
325325
@data.each do |g, ss|
326326
ss.each do |s, ps|
327327
ps.each do |p, os|
328-
os.each do |o|
329-
yield RDF::Statement.new(s, p, o, graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g)
328+
os.each do |o, object_options|
329+
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g))
330330
end
331331
end
332332
end
@@ -403,9 +403,9 @@ def query_pattern(pattern, **options, &block)
403403
[]
404404
end
405405
ps.each do |p, os|
406-
os.each do |o|
406+
os.each do |o, object_options|
407407
next unless object.nil? || object.eql?(o)
408-
yield RDF::Statement.new(s, p, o, graph_name: c.equal?(DEFAULT_GRAPH) ? nil : c)
408+
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: c.equal?(DEFAULT_GRAPH) ? nil : c))
409409
end
410410
end
411411
end
@@ -462,7 +462,7 @@ def has_statement_in?(data, statement)
462462
data.has_key?(g) &&
463463
data[g].has_key?(s) &&
464464
data[g][s].has_key?(p) &&
465-
data[g][s][p].include?(o)
465+
data[g][s][p].has_key?(o)
466466
end
467467

468468
##
@@ -476,9 +476,9 @@ def insert_to(data, statement)
476476
c ||= DEFAULT_GRAPH
477477

478478
return data.put(c) do |subs|
479-
subs = (subs || Hamster::Hash.new).put(s) do |preds|
480-
preds = (preds || Hamster::Hash.new).put(p) do |objs|
481-
(objs || Hamster::Set.new).add(o)
479+
(subs || Hamster::Hash.new).put(s) do |preds|
480+
(preds || Hamster::Hash.new).put(p) do |objs|
481+
(objs || Hamster::Hash.new).put(o, statement.options)
482482
end
483483
end
484484
end

spec/repository_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@
5555
expect(solutions.size).to eq unnamed_statements.size
5656
end
5757
end
58+
59+
it "remembers statement obtions" do
60+
subject << existing_statement = RDF::Statement(:s, RDF.type, :o, inferred: true)
61+
expect(subject).to have_statement(existing_statement)
62+
expect(subject.statements.first).to eq existing_statement
63+
expect(subject.statements.first).to be_inferred
64+
end
5865
end

0 commit comments

Comments
 (0)