Skip to content

Commit 1d98d69

Browse files
committed
Fix annotation creation for flatten and fromRdf as well as reversing annotation relationships.
1 parent 1d4afaa commit 1d98d69

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/json/ld/flatten.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,21 @@ def create_node_map(element, graph_map,
124124

125125
# For rdfstar, if node contains an `@annotation` member ...
126126
# note: active_subject will not be nil
127-
# XXX: what if we're reversing an annotation?
128127
if annotation = element.delete('@annotation')
129128
# rdfstar being true is implicit, as it is checked in expansion
130-
as = if node_reference?(active_subject)
131-
active_subject['@id']
129+
if node_reference?(active_subject)
130+
# If this is a node reference, then we're processing a revers relationship
131+
as = active_subject['@id']
132+
reification = {'@id' => node['@id'], active_property => [{ '@id' => as }]}
132133
else
133-
active_subject
134+
as = active_subject
135+
reification = {'@id' => as, active_property => [{ '@id' => node['@id'] }]}
134136
end
135137

136-
reification = {'@id' => as, active_property => [{ '@id' => node['@id'] }]}
137-
138138
# Note that annotation is an array, make the reified subject the id of each member of that array.
139139
annotation.each do |a|
140-
# XXX may be zero or more reifiers; use bnode for now.
141-
reifier = namer.get_name
140+
# Use an provided reifier before allocating a fresh blank node
141+
reifier = a.fetch('@id', namer.get_name)
142142
a = a.merge('@id' => reifier, '@reifies' => reification)
143143

144144
# Invoke recursively using annotation.
@@ -252,7 +252,8 @@ def create_annotations(node_map)
252252
target_values.is_a?(Array)
253253

254254
target_values.each do |t_value|
255-
next unless t_value == reif_value
255+
# See if target value matches the reification value (other than a potential `@annotation`).
256+
next unless t_value.dup.delete_if {|k, _| %w(@annotation).include?(k)} == reif_value
256257

257258
# Add annotation to the identified value
258259
t_value['@annotation'] ||= []

spec/rdfstar_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
describe m.name do
1818
m.entries.each do |t|
1919
specify "#{t.property('@id')}: #{t.name}#{' (negative test)' unless t.positiveTest?}" do
20-
pending "annotation folding" if t.name.include?("(with @annotation)")
2120
t.options[:ordered] = false
2221
expect { t.run self }.not_to write.to(:error)
2322
end

0 commit comments

Comments
 (0)