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
# If the active property is @list or its container mapping is set to @list, the expanded item must not be an array or a list object, otherwise a list of lists error has been detected and processing is aborted.
34
-
raiseJsonLdError::ListOfLists,
35
-
"A list may not contain another list"if
36
-
is_list && (v.is_a?(Array) || list?(v))
33
+
# If the active property is @list or its container mapping is set to @list and v is an array, change it to a list object
# Spec FIXME: need to be sure that result is an array
284
283
value=as_array(value)
285
284
286
-
# If expanded value is a list object, a list of lists error has been detected and processing is aborted.
287
-
# Spec FIXME: Also look at each object if result is an array
288
-
raiseJsonLdError::ListOfLists,
289
-
"A list may not contain another list"ifvalue.any?{|v| list?(v)}
290
-
291
285
value
292
286
when'@set'
293
287
# If expanded property is @set, set expanded value to the result of using this algorithm recursively, passing active context, active property, and value for element.
Copy file name to clipboardExpand all lines: lib/json/ld/flatten.rb
+99-90Lines changed: 99 additions & 90 deletions
Original file line number
Diff line number
Diff line change
@@ -7,111 +7,120 @@ module Flatten
7
7
##
8
8
# 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
9
#
10
-
# @param [Array, Hash] input
10
+
# @param [Array, Hash] element
11
11
# Expanded JSON-LD input
12
-
# @param [Hash] graphs A map of graph name to subjects
13
-
# @param [String] graph
12
+
# @param [Hash] graph_map A map of graph name to subjects
13
+
# @param [String] active_graph
14
14
# The name of the currently active graph that the processor should use when processing.
15
-
# @param [String] name
16
-
# The name assigned to the current input if it is a bnode
# If input is an array, process each entry in input recursively by passing item for input, node map, active graph, active subject, active property, and list.
# 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.
29
+
element.mapdo |o|
30
+
create_node_map(o,graph_map,
31
+
active_graph: active_graph,
32
+
active_subject: active_subject,
33
+
active_property: active_property,
34
+
list: list)
35
+
end
36
+
elsif !element.is_a?(Hash)
37
+
raise"Expected hash or array to create_node_map, got #{element.inspect}"
38
+
else
39
+
graph=(graph_map[active_graph] ||= {})
40
+
subject_node=graph[active_subject]
33
41
34
-
# spec requires @type to be named first, so assign names early
0 commit comments