@@ -86,9 +86,13 @@ def expand(input, active_property, context, ordered: false, framing: false, from
86
86
output_object = { }
87
87
88
88
# See if keys mapping to @type have terms with a local context
89
- type_key = input . keys . detect { |k | context . expand_iri ( k , vocab : true , quite : true ) == '@type' }
90
- if type_key
91
- Array ( input [ type_key ] ) . sort . each do |term |
89
+ type_key = nil
90
+ input . keys . sort .
91
+ select { |k | context . expand_iri ( k , vocab : true , quite : true ) == '@type' } .
92
+ each do |tk |
93
+
94
+ type_key ||= tk # Side effect saves the first found key mapping to @type
95
+ Array ( input [ tk ] ) . sort . each do |term |
92
96
term_context = type_scoped_context . term_definitions [ term ] . context if type_scoped_context . term_definitions [ term ]
93
97
context = term_context ? context . parse ( term_context , propagate : false ) : context
94
98
end
@@ -215,9 +219,9 @@ def expand_object(input, active_property, context, output_object,
215
219
raise JsonLdError ::InvalidReversePropertyMap ,
216
220
"@reverse not appropriate at this point" if expanded_active_property == '@reverse'
217
221
218
- # If result has already an expanded property member, an colliding keywords error has been detected and processing is aborted.
222
+ # If result has already an expanded property member (other than @type) , an colliding keywords error has been detected and processing is aborted.
219
223
raise JsonLdError ::CollidingKeywords ,
220
- "#{ expanded_property } already exists in result" if output_object . has_key? ( expanded_property )
224
+ "#{ expanded_property } already exists in result" if output_object . has_key? ( expanded_property ) && expanded_property != '@type'
221
225
222
226
expanded_value = case expanded_property
223
227
when '@id'
@@ -276,12 +280,9 @@ def expand_object(input, active_property, context, output_object,
276
280
"@type value must be a string or array of strings: #{ value . inspect } "
277
281
end
278
282
283
+ e_type = Array ( output_object [ '@type' ] ) + Array ( e_type )
279
284
# Use array form if framing
280
- if framing
281
- as_array ( e_type )
282
- else
283
- e_type
284
- end
285
+ framing || e_type . length > 1 ? e_type : e_type . first
285
286
when '@graph'
286
287
# If expanded property is @graph, set expanded value to the result of using this algorithm recursively passing active context, @graph for active property, and value for element.
287
288
value = expand ( value , '@graph' , context , ordered : ordered , framing : framing )
0 commit comments