@@ -190,6 +190,14 @@ def initialize(options = {})
190190 yield ( self ) if block_given?
191191 end
192192
193+ ##
194+ # Initial context, without mappings, vocab or default language
195+ #
196+ # @return [Boolean]
197+ def empty?
198+ @term_definitions . empty? && self . vocab . nil? && self . default_language . nil?
199+ end
200+
193201 # @param [String] value must be an absolute IRI
194202 def base = ( value )
195203 if value
@@ -247,6 +255,8 @@ def vocab=(value)
247255 # @see http://json-ld.org/spec/latest/json-ld-api/index.html#context-processing-algorithm
248256 def parse ( local_context , remote_contexts = [ ] )
249257 result = self . dup
258+ result . provided_context = local_context if self . empty?
259+
250260 local_context = [ local_context ] unless local_context . is_a? ( Array )
251261
252262 local_context . each do |context |
@@ -265,7 +275,7 @@ def parse(local_context, remote_contexts = [])
265275 ctx = JSON . load ( context )
266276 raise JSON ::LD ::JsonLdError ::InvalidRemoteContext , "Context missing @context key" if @options [ :validate ] && ctx [ '@context' ] . nil?
267277 result = parse ( ctx [ "@context" ] ? ctx [ "@context" ] . dup : { } )
268- result . provided_context = ctx [ "@context" ]
278+ result . provided_context = ctx [ "@context" ] if [ context ] == local_context
269279 result
270280 rescue JSON ::ParserError => e
271281 debug ( "parse" ) { "Failed to parse @context from remote document at #{ context } : #{ e . message } " }
@@ -283,9 +293,6 @@ def parse(local_context, remote_contexts = [])
283293
284294 context_no_base = self . dup
285295 context_no_base . base = nil
286- unless @options [ :processingMode ] == "json-ld-1.0"
287- context_no_base . provided_context = context . to_s
288- end
289296 context_no_base . context_base = context . to_s
290297
291298 begin
@@ -310,7 +317,7 @@ def parse(local_context, remote_contexts = [])
310317
311318 # 3.2.6) Set context to the result of recursively calling this algorithm, passing context no base for active context, context for local context, and remote contexts.
312319 context = context_no_base . parse ( context , remote_contexts . dup )
313- context . provided_context = context_no_base . provided_context
320+ context . provided_context = result . provided_context
314321 context . base ||= result . base
315322 result = context
316323 debug ( "parse" ) { "=> provided_context: #{ context . inspect } " }
0 commit comments