@@ -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' ] ||= [ ]
0 commit comments