Skip to content

Commit

Permalink
Update Repository to remember statement options along with object, an…
Browse files Browse the repository at this point in the history
…d not simply the object itself. This allows inferred statements to be added to the repo, and come back as having been inferred.
  • Loading branch information
gkellogg committed Jan 21, 2019
1 parent 2171105 commit 02340e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/rdf/model/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def self.from(statement, graph_name: nil, **options)
# @return [RDF::Term]
attr_accessor :object

# @return [Hash{Symbol => Object}]
attr_accessor :options

##
# @overload initialize(**options)
# @param [Hash{Symbol => Object}] options
Expand Down
16 changes: 8 additions & 8 deletions lib/rdf/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ def each_statement(&block)
@data.each do |g, ss|
ss.each do |s, ps|
ps.each do |p, os|
os.each do |o|
yield RDF::Statement.new(s, p, o, graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g)
os.each do |o, object_options|
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g))
end
end
end
Expand Down Expand Up @@ -403,9 +403,9 @@ def query_pattern(pattern, **options, &block)
[]
end
ps.each do |p, os|
os.each do |o|
os.each do |o, object_options|
next unless object.nil? || object.eql?(o)
yield RDF::Statement.new(s, p, o, graph_name: c.equal?(DEFAULT_GRAPH) ? nil : c)
yield RDF::Statement.new(s, p, o, object_options.merge(graph_name: c.equal?(DEFAULT_GRAPH) ? nil : c))
end
end
end
Expand Down Expand Up @@ -462,7 +462,7 @@ def has_statement_in?(data, statement)
data.has_key?(g) &&
data[g].has_key?(s) &&
data[g][s].has_key?(p) &&
data[g][s][p].include?(o)
data[g][s][p].has_key?(o)
end

##
Expand All @@ -476,9 +476,9 @@ def insert_to(data, statement)
c ||= DEFAULT_GRAPH

return data.put(c) do |subs|
subs = (subs || Hamster::Hash.new).put(s) do |preds|
preds = (preds || Hamster::Hash.new).put(p) do |objs|
(objs || Hamster::Set.new).add(o)
(subs || Hamster::Hash.new).put(s) do |preds|
(preds || Hamster::Hash.new).put(p) do |objs|
(objs || Hamster::Hash.new).put(o, statement.options)
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@
expect(solutions.size).to eq unnamed_statements.size
end
end

it "remembers statement obtions" do
subject << existing_statement = RDF::Statement(:s, RDF.type, :o, inferred: true)
expect(subject).to have_statement(existing_statement)
expect(subject.statements.first).to eq existing_statement
expect(subject.statements.first).to be_inferred
end
end

0 comments on commit 02340e8

Please sign in to comment.