@@ -80,8 +80,6 @@ def parse_object(input, active_property, context,
80
80
return
81
81
end
82
82
83
- input = context . expand_value ( active_property , input , base : base ) unless input . is_a? ( Hash )
84
-
85
83
# Note that we haven't parsed an @id key, so have no subject
86
84
have_id , node_reference , is_list_or_set = false , false , false
87
85
node_id ||= RDF ::Node . new ( @provisional_namer . get_sym )
@@ -94,7 +92,7 @@ def parse_object(input, active_property, context,
94
92
95
93
# Revert any previously type-scoped term definitions, unless this is from a map, a value object or a subject reference
96
94
# FIXME
97
- if context . previous_context
95
+ if input . is_a? ( Hash ) && context . previous_context
98
96
expanded_key_map = input . keys . inject ( { } ) do |memo , key |
99
97
memo . merge ( key => context . expand_iri ( key , vocab : true , as_string : true , base : base ) )
100
98
end
@@ -108,6 +106,11 @@ def parse_object(input, active_property, context,
108
106
context = context . parse ( property_scoped_context , base : base , override_protected : true ) unless
109
107
property_scoped_context . nil?
110
108
109
+ # Otherwise, unless the value is a number, expand the value according to the Value Expansion rules, passing active property.
110
+ unless input . is_a? ( Hash )
111
+ input = context . expand_value ( active_property , input , base : base )
112
+ end
113
+
111
114
# Output any type provided from a type map
112
115
provisional_statements << RDF ::Statement ( node_id , RDF . type , extra_type ) if
113
116
extra_type
@@ -237,10 +240,16 @@ def parse_object(input, active_property, context,
237
240
end
238
241
state = :properties
239
242
when '@nest'
243
+ nest_context = context . term_definitions [ active_property ] . context if context . term_definitions [ active_property ]
244
+ nest_context = if nest_context . nil?
245
+ context
246
+ else
247
+ context . parse ( nest_context , base : base , override_protected : true )
248
+ end
240
249
as_array ( value ) . each do |v |
241
250
raise JsonLdError ::InvalidNestValue , v . inspect unless
242
- v . is_a? ( Hash ) && v . keys . none? { |k | context . expand_iri ( k , vocab : true , base : base ) == '@value' }
243
- parse_object ( v , active_property , context , node_id : node_id ) do |st |
251
+ v . is_a? ( Hash ) && v . keys . none? { |k | nest_context . expand_iri ( k , vocab : true , base : base ) == '@value' }
252
+ parse_object ( v , active_property , nest_context , node_id : node_id ) do |st |
244
253
add_statement . call ( st )
245
254
end
246
255
end
@@ -271,9 +280,7 @@ def parse_object(input, active_property, context,
271
280
"found #{ key } in state #{ state } " if
272
281
![ :await_context , :await_type , :await_id ] . include? ( state )
273
282
is_list_or_set = true
274
- value = as_array ( value ) . map do |item |
275
- item . is_a? ( Hash ) ? item : context . expand_value ( active_property , item , base : base )
276
- end . compact
283
+ value = as_array ( value ) . compact
277
284
parse_object ( value , active_property , context , subject : subject , predicate : predicate , &block )
278
285
node_id = nil
279
286
state = :properties
@@ -532,8 +539,6 @@ def emit_object(input, active_property, context, subject, predicate, **options,
532
539
end
533
540
else
534
541
as_array ( input ) . flatten . each do |item |
535
- # if item is not a Hash, expand it
536
- item = context . expand_value ( active_property , item , base : base ) unless item . is_a? ( Hash )
537
542
# emit property/value
538
543
parse_object ( item , active_property , context ,
539
544
subject : subject , predicate : predicate , **options , &block )
0 commit comments