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
Copy file name to clipboardExpand all lines: lib/json/ld/flatten.rb
+91-7Lines changed: 91 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,18 @@
1
1
# -*- encoding: utf-8 -*-
2
2
# frozen_string_literal: true
3
+
require'json/canonicalization'
4
+
3
5
moduleJSON::LD
4
6
moduleFlatten
5
7
includeUtils
6
8
7
9
##
8
10
# This algorithm creates a JSON object node map holding an indexed representation of the graphs and nodes represented in the passed expanded document. All nodes that are not uniquely identified by an IRI get assigned a (new) blank node identifier. The resulting node map will have a member for every graph in the document whose value is another object with a member for every node represented in the document. The default graph is stored under the @default member, all other graphs are stored under their graph name.
9
11
#
12
+
# For RDF*/JSON-LD*:
13
+
# * Values of `@id` can be an object (embedded node); when these are used as keys in a Node Map, they are serialized as canonical JSON, and de-serialized when flattening.
14
+
# * The presence of `@annotation` implies an embedded node and the annotation object is removed from the node/value object in which it appears.
15
+
#
10
16
# @param [Array, Hash] element
11
17
# Expanded JSON-LD input
12
18
# @param [Hash] graph_map A map of graph name to subjects
@@ -16,12 +22,15 @@ module Flatten
16
22
# Node identifier
17
23
# @param [String] active_property (nil)
18
24
# Property within current node
25
+
# @param [Boolean] reverse (false)
26
+
# Processing a reverse relationship
19
27
# @param [Array] list (nil)
20
28
# Used when property value is a list
21
29
defcreate_node_map(element,graph_map,
22
30
active_graph: '@default',
23
31
active_subject: nil,
24
32
active_property: nil,
33
+
reverse: false,
25
34
list: nil)
26
35
ifelement.is_a?(Array)
27
36
# If element is an array, process each entry in element recursively by passing item for element, node map, active graph, active subject, active property, and list.
0 commit comments