@@ -80,8 +80,6 @@ def parse_object(input, active_property, context,
8080 return
8181 end
8282
83- input = context . expand_value ( active_property , input , base : base ) unless input . is_a? ( Hash )
84-
8583 # Note that we haven't parsed an @id key, so have no subject
8684 have_id , node_reference , is_list_or_set = false , false , false
8785 node_id ||= RDF ::Node . new ( @provisional_namer . get_sym )
@@ -94,7 +92,7 @@ def parse_object(input, active_property, context,
9492
9593 # Revert any previously type-scoped term definitions, unless this is from a map, a value object or a subject reference
9694 # FIXME
97- if context . previous_context
95+ if input . is_a? ( Hash ) && context . previous_context
9896 expanded_key_map = input . keys . inject ( { } ) do |memo , key |
9997 memo . merge ( key => context . expand_iri ( key , vocab : true , as_string : true , base : base ) )
10098 end
@@ -108,6 +106,11 @@ def parse_object(input, active_property, context,
108106 context = context . parse ( property_scoped_context , base : base , override_protected : true ) unless
109107 property_scoped_context . nil?
110108
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+
111114 # Output any type provided from a type map
112115 provisional_statements << RDF ::Statement ( node_id , RDF . type , extra_type ) if
113116 extra_type
@@ -237,10 +240,16 @@ def parse_object(input, active_property, context,
237240 end
238241 state = :properties
239242 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
240249 as_array ( value ) . each do |v |
241250 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 |
244253 add_statement . call ( st )
245254 end
246255 end
@@ -271,9 +280,7 @@ def parse_object(input, active_property, context,
271280 "found #{ key } in state #{ state } " if
272281 ![ :await_context , :await_type , :await_id ] . include? ( state )
273282 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
277284 parse_object ( value , active_property , context , subject : subject , predicate : predicate , &block )
278285 node_id = nil
279286 state = :properties
@@ -532,8 +539,6 @@ def emit_object(input, active_property, context, subject, predicate, **options,
532539 end
533540 else
534541 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 )
537542 # emit property/value
538543 parse_object ( item , active_property , context ,
539544 subject : subject , predicate : predicate , **options , &block )
0 commit comments