You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Updates a node map from which annotations have been folded into embedded triples to re-extract the annotations.
198
+
#
199
+
# Map entries where the key is of the form of a canonicalized JSON object are used to find keys with the `@id` and property components. If found, the original map entry is removed and entries added to an `@annotation` property of the associated value.
200
+
#
201
+
# * Keys which are of the form of a canonicalized JSON object are examined in inverse order of length.
202
+
# * Deserialize the key into a map, and re-serialize the value of `@id`.
203
+
# * If the map contains an entry with that value (after re-canonicalizing, as appropriate), and the associated antry has a item which matches the non-`@id` item from the map, the node is used to create an `@annotation` entry within that value.
204
+
#
205
+
# @param [Hash{String => Hash}] input
206
+
# @return [Hash{String => Hash}]
207
+
defcreate_annotations(node_map)
208
+
node_map.keys.
209
+
select{|k| k.start_with?('{')}.
210
+
sort_by(&:length).
211
+
reverse.eachdo |key|
212
+
213
+
# Deserialize key, and re-serialize the `@id` value.
214
+
emb=JSON.parse(key)
215
+
id=emb.delete('@id')
216
+
property,value=emb.to_a.first
217
+
218
+
# If id is a map, set it to the result of canonicalizing that value, otherwise to itself.
219
+
id=id.to_json_c14nifid.is_a?(Hash)
220
+
221
+
nextunlessnode_map.key?(id)
222
+
# If node map has an entry for id and that entry contains the same property and value from entry:
# If object is an IRI, blank node identifier, or statement, and node map does not have an object member, create one and initialize its value to a new JSON object consisting of a single member @id whose value is set to object.
# If predicate equals rdf:type, and object is an IRI or blank node identifier, append object to the value of the @type member of node. If no such member exists, create one and initialize it to an array whose only item is object. Finally, continue to the next RDF triple.
58
-
# XXX JSON-LD* does not support embedded value of @type
0 commit comments