json-ld 3.2.2 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -212,7 +212,7 @@ module JSON::LD
212
212
  self.default_language = options[:language] if options[:language] =~ /^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/
213
213
  @term_definitions = options[:term_definitions] if options[:term_definitions]
214
214
 
215
- #log_debug("init") {"iri_to_term: #{iri_to_term.inspect}"}
215
+ # log_debug("init") {"iri_to_term: #{iri_to_term.inspect}"}
216
216
 
217
217
  yield(self) if block_given?
218
218
  end
@@ -267,13 +267,13 @@ module JSON::LD
267
267
  "Attempt to clear a context with protected terms"
268
268
  end
269
269
  when Context
270
- log_debug("parse") {"context: #{context.inspect}"}
270
+ # log_debug("parse") {"context: #{context.inspect}"}
271
271
  result = result.merge(context)
272
272
  when IO, StringIO
273
- log_debug("parse") {"io: #{context}"}
273
+ # log_debug("parse") {"io: #{context}"}
274
274
  # Load context document, if it is an open file
275
275
  begin
276
- ctx = JSON.load(context)
276
+ ctx = load_context(context, **@options)
277
277
  raise JSON::LD::JsonLdError::InvalidRemoteContext, "Context missing @context key" if @options[:validate] && ctx['@context'].nil?
278
278
  result = result.parse(ctx["@context"] ? ctx["@context"] : {})
279
279
  rescue JSON::ParserError => e
@@ -282,7 +282,7 @@ module JSON::LD
282
282
  self
283
283
  end
284
284
  when String, RDF::URI
285
- log_debug("parse") {"remote: #{context}, base: #{result.context_base || result.base}"}
285
+ # log_debug("parse") {"remote: #{context}, base: #{result.context_base || result.base}"}
286
286
 
287
287
  # 3.2.1) Set context to the result of resolving value against the base IRI which is established as specified in section 5.1 Establishing a Base URI of [RFC3986]. Only the basic algorithm in section 5.2 of [RFC3986] is used; neither Syntax-Based Normalization nor Scheme-Based Normalization are performed. Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of [RFC3987].
288
288
  context = RDF::URI(result.context_base || base).join(context)
@@ -297,13 +297,14 @@ module JSON::LD
297
297
 
298
298
  cached_context = if PRELOADED[context_canon.to_s]
299
299
  # If we have a cached context, merge it into the current context (result) and use as the new context
300
- log_debug("parse") {"=> cached_context: #{context_canon.to_s.inspect}"}
300
+ # log_debug("parse") {"=> cached_context: #{context_canon.to_s.inspect}"}
301
301
 
302
302
  # If this is a Proc, then replace the entry with the result of running the Proc
303
303
  if PRELOADED[context_canon.to_s].respond_to?(:call)
304
- log_debug("parse") {"=> (call)"}
304
+ # log_debug("parse") {"=> (call)"}
305
305
  PRELOADED[context_canon.to_s] = PRELOADED[context_canon.to_s].call
306
306
  end
307
+ PRELOADED[context_canon.to_s].context_base ||= context_canon.to_s
307
308
  PRELOADED[context_canon.to_s]
308
309
  else
309
310
  # Load context document, if it is a string
@@ -478,7 +479,7 @@ module JSON::LD
478
479
  remote_contexts: [],
479
480
  validate_scoped: true)
480
481
  # Expand a string value, unless it matches a keyword
481
- log_debug("create_term_definition") {"term = #{term.inspect}"}
482
+ # log_debug("create_term_definition") {"term = #{term.inspect}"}
482
483
 
483
484
  # If defined contains the key term, then the associated value must be true, indicating that the term definition has already been created, so return. Otherwise, a cyclical term definition has been detected, which is an error.
484
485
  case defined[term]
@@ -523,7 +524,7 @@ module JSON::LD
523
524
 
524
525
  raise JsonLdError::InvalidTermDefinition, "Term definition for #{term.inspect} is an #{value.class} on term #{term.inspect}" unless value.is_a?(Hash)
525
526
 
526
- #log_debug("") {"Hash[#{term.inspect}] = #{value.inspect}"}
527
+ # log_debug("") {"Hash[#{term.inspect}] = #{value.inspect}"}
527
528
  definition = TermDefinition.new(term)
528
529
  definition.simple = simple_term
529
530
 
@@ -565,7 +566,7 @@ module JSON::LD
565
566
  elsif !JSON_LD_10_TYPE_VALUES.include?(type) && !(type.is_a?(RDF::URI) && type.absolute?)
566
567
  raise JsonLdError::InvalidTypeMapping, "unknown mapping for '@type': #{type.inspect} on term #{term.inspect}"
567
568
  end
568
- #log_debug("") {"type_mapping: #{type.inspect}"}
569
+ # log_debug("") {"type_mapping: #{type.inspect}"}
569
570
  definition.type_mapping = type
570
571
  end
571
572
 
@@ -649,7 +650,7 @@ module JSON::LD
649
650
  # Otherwise, term is an absolute IRI. Set the IRI mapping for definition to term
650
651
  term
651
652
  end
652
- log_debug("") {"=> #{definition.id}"}
653
+ # log_debug("") {"=> #{definition.id}"}
653
654
  elsif term.include?('/')
654
655
  # If term is a relative IRI
655
656
  definition.id = expand_iri(term, vocab: true)
@@ -662,13 +663,13 @@ module JSON::LD
662
663
  # Otherwise, active context must have a vocabulary mapping, otherwise an invalid value has been detected, which is an error. Set the IRI mapping for definition to the result of concatenating the value associated with the vocabulary mapping and term.
663
664
  raise JsonLdError::InvalidIRIMapping, "relative term definition without vocab: #{term} on term #{term.inspect}" unless vocab
664
665
  definition.id = vocab + term
665
- log_debug("") {"=> #{definition.id}"}
666
+ # log_debug("") {"=> #{definition.id}"}
666
667
  end
667
668
 
668
669
  @iri_to_term[definition.id] = term if simple_term && definition.id
669
670
 
670
671
  if value.key?('@container')
671
- #log_debug("") {"container_mapping: #{value['@container'].inspect}"}
672
+ # log_debug("") {"container_mapping: #{value['@container'].inspect}"}
672
673
  definition.container_mapping = check_container(value['@container'], local_context, defined, term)
673
674
 
674
675
  # If @container includes @type
@@ -702,7 +703,7 @@ module JSON::LD
702
703
  when nil then [nil]
703
704
  else value['@context']
704
705
  end
705
- log_debug("") {"context: #{definition.context.inspect}"}
706
+ # log_debug("") {"context: #{definition.context.inspect}"}
706
707
  rescue JsonLdError => e
707
708
  raise JsonLdError::InvalidScopedContext, "Term definition for #{term.inspect} contains illegal value for @context: #{e.message}"
708
709
  end
@@ -722,14 +723,14 @@ module JSON::LD
722
723
  else
723
724
  raise JsonLdError::InvalidLanguageMapping, "language must be null or a string, was #{value['@language'].inspect}} on term #{term.inspect}"
724
725
  end
725
- #log_debug("") {"language_mapping: #{language.inspect}"}
726
+ # log_debug("") {"language_mapping: #{language.inspect}"}
726
727
  definition.language_mapping = language || false
727
728
  end
728
729
 
729
730
  if value.key?('@direction')
730
731
  direction = value['@direction']
731
732
  raise JsonLdError::InvalidBaseDirection, "direction must be null, 'ltr', or 'rtl', was #{language.inspect}} on term #{term.inspect}" unless direction.nil? || %w(ltr rtl).include?(direction)
732
- #log_debug("") {"direction_mapping: #{direction.inspect}"}
733
+ # log_debug("") {"direction_mapping: #{direction.inspect}"}
733
734
  definition.direction_mapping = direction || false
734
735
  end
735
736
 
@@ -737,7 +738,7 @@ module JSON::LD
737
738
  nest = value['@nest']
738
739
  raise JsonLdError::InvalidNestValue, "nest must be a string, was #{nest.inspect}} on term #{term.inspect}" unless nest.is_a?(String)
739
740
  raise JsonLdError::InvalidNestValue, "nest must not be a keyword other than @nest, was #{nest.inspect}} on term #{term.inspect}" if nest.match?(/^@[a-zA-Z]+$/) && nest != '@nest'
740
- #log_debug("") {"nest: #{nest.inspect}"}
741
+ # log_debug("") {"nest: #{nest.inspect}"}
741
742
  definition.nest = nest
742
743
  end
743
744
 
@@ -897,22 +898,21 @@ module JSON::LD
897
898
  # @param [Hash{Symbol => Object}] options ({})
898
899
  # @return [Hash]
899
900
  def serialize(provided_context: nil, **options)
900
- #log_debug("serlialize: generate context")
901
- #log_debug("") {"=> context: #{inspect}"}
901
+ # log_debug("serlialize: generate context")
902
+ # log_debug("") {"=> context: #{inspect}"}
902
903
  use_context = case provided_context
903
904
  when String, RDF::URI
904
- #log_debug "serlialize: reuse context: #{provided_context.inspect}"
905
+ # log_debug "serlialize: reuse context: #{provided_context.inspect}"
905
906
  provided_context.to_s
906
907
  when Hash
907
- #log_debug "serlialize: reuse context: #{provided_context.inspect}"
908
+ # log_debug "serlialize: reuse context: #{provided_context.inspect}"
908
909
  # If it has an @context entry use it, otherwise it is assumed to be the body of a context
909
910
  provided_context.fetch('@context', provided_context)
910
911
  when Array
911
- #log_debug "serlialize: reuse context: #{provided_context.inspect}"
912
+ # log_debug "serlialize: reuse context: #{provided_context.inspect}"
912
913
  provided_context
913
914
  when IO, StringIO
914
- provided_context.rewind
915
- JSON.load(provided_context).fetch('@context', {})
915
+ load_context(provided_context, **@options).fetch('@context', {})
916
916
  else
917
917
  ctx = {}
918
918
  ctx['@version'] = 1.1 if @processingMode == 'json-ld-1.1'
@@ -1015,7 +1015,7 @@ module JSON::LD
1015
1015
  #
1016
1016
  # @return [TermDefinition]
1017
1017
  def set_mapping(term, value)
1018
- #log_debug("") {"map #{term.inspect} to #{value.inspect}"}
1018
+ # log_debug("") {"map #{term.inspect} to #{value.inspect}"}
1019
1019
  term = term.to_s
1020
1020
  term_definitions[term] = TermDefinition.new(term, id: value, simple: true, prefix: (value.to_s.end_with?(*PREFIX_URI_ENDINGS)))
1021
1021
  term_definitions[term].simple = true
@@ -1467,8 +1467,6 @@ module JSON::LD
1467
1467
  end
1468
1468
  end
1469
1469
 
1470
- RDF_LITERAL_NATIVE_TYPES = Set.new([RDF::XSD.boolean, RDF::XSD.integer, RDF::XSD.double]).freeze
1471
-
1472
1470
  ##
1473
1471
  # If active property has a type mapping in the active context set to @id or @vocab, a JSON object with a single member @id whose value is the result of using the IRI Expansion algorithm on value is returned.
1474
1472
  #
@@ -1491,7 +1489,7 @@ module JSON::LD
1491
1489
 
1492
1490
  # If the active property has a type mapping in active context that is @id, return a new JSON object containing a single key-value pair where the key is @id and the value is the result of using the IRI Expansion algorithm, passing active context, value, and true for document relative.
1493
1491
  if value.is_a?(String) && td.type_mapping == '@id'
1494
- #log_debug("") {"as relative IRI: #{value.inspect}"}
1492
+ # log_debug("") {"as relative IRI: #{value.inspect}"}
1495
1493
  return {'@id' => expand_iri(value, documentRelative: true, base: base).to_s}
1496
1494
  end
1497
1495
 
@@ -1500,50 +1498,12 @@ module JSON::LD
1500
1498
  return {'@id' => expand_iri(value, vocab: true, documentRelative: true, base: base).to_s}
1501
1499
  end
1502
1500
 
1503
- value = RDF::Literal(value) if
1504
- value.is_a?(Date) ||
1505
- value.is_a?(DateTime) ||
1506
- value.is_a?(Time)
1507
-
1508
1501
  result = case value
1509
1502
  when RDF::URI, RDF::Node
1510
1503
  {'@id' => value.to_s}
1511
- when RDF::Literal
1512
- res = {}
1513
- if value.datatype == RDF::URI(RDF.to_uri + "JSON") && processingMode('json-ld-1.1')
1514
- # Value parsed as JSON
1515
- # FIXME: MultiJson
1516
- res['@type'] = '@json'
1517
- res['@value'] = ::JSON.parse(value.object)
1518
- elsif value.datatype.start_with?("https://www.w3.org/ns/i18n#") && rdfDirection == 'i18n-datatype' && processingMode('json-ld-1.1')
1519
- lang, dir = value.datatype.fragment.split('_')
1520
- res['@value'] = value.to_s
1521
- unless lang.empty?
1522
- if lang !~ /^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/
1523
- if options[:validate]
1524
- raise JsonLdError::InvalidLanguageMapping, "rdf:language must be valid BCP47: #{lang.inspect}"
1525
- else
1526
- warn "rdf:language must be valid BCP47: #{lang.inspect}"
1527
- end
1528
- end
1529
- res['@language'] = lang
1530
- end
1531
- res['@direction'] = dir
1532
- elsif useNativeTypes && RDF_LITERAL_NATIVE_TYPES.include?(value.datatype) && value.valid?
1533
- res['@type'] = uri(coerce(property)) if coerce(property)
1534
- res['@value'] = value.object
1535
- else
1536
- value.canonicalize! if value.valid? && value.datatype == RDF::XSD.double
1537
- if coerce(property)
1538
- res['@type'] = uri(coerce(property)).to_s
1539
- elsif value.datatype?
1540
- res['@type'] = uri(value.datatype).to_s
1541
- elsif value.language? || language(property)
1542
- res['@language'] = (value.language || language(property)).to_s
1543
- end
1544
- res['@value'] = value.to_s
1545
- end
1546
- res
1504
+ when Date, DateTime, Time
1505
+ lit = RDF::Literal.new(value)
1506
+ {'@value' => lit.to_s, '@type' => lit.datatype.to_s}
1547
1507
  else
1548
1508
  # Otherwise, initialize result to a JSON object with an @value member whose value is set to value.
1549
1509
  res = {}
@@ -1561,8 +1521,6 @@ module JSON::LD
1561
1521
  end
1562
1522
 
1563
1523
  result
1564
- rescue ::JSON::ParserError => e
1565
- raise JSON::LD::JsonLdError::InvalidJsonLiteral, e.message
1566
1524
  end
1567
1525
 
1568
1526
  ##
@@ -1579,7 +1537,7 @@ module JSON::LD
1579
1537
  # @see https://www.w3.org/TR/json-ld11-api/#value-compaction
1580
1538
  # FIXME: revisit the specification version of this.
1581
1539
  def compact_value(property, value, base: nil)
1582
- #log_debug("compact_value") {"property: #{property.inspect}, value: #{value.inspect}"}
1540
+ # log_debug("compact_value") {"property: #{property.inspect}, value: #{value.inspect}"}
1583
1541
 
1584
1542
  indexing = index?(value) && container(property).include?('@index')
1585
1543
  language = language(property)
@@ -1588,25 +1546,25 @@ module JSON::LD
1588
1546
  result = case
1589
1547
  when coerce(property) == '@id' && value.key?('@id') && (value.keys - %w(@id @index)).empty?
1590
1548
  # Compact an @id coercion
1591
- #log_debug("") {" (@id & coerce)"}
1549
+ # log_debug("") {" (@id & coerce)"}
1592
1550
  compact_iri(value['@id'], base: base)
1593
1551
  when coerce(property) == '@vocab' && value.key?('@id') && (value.keys - %w(@id @index)).empty?
1594
1552
  # Compact an @id coercion
1595
- #log_debug("") {" (@id & coerce & vocab)"}
1553
+ # log_debug("") {" (@id & coerce & vocab)"}
1596
1554
  compact_iri(value['@id'], vocab: true)
1597
1555
  when value.key?('@id')
1598
- #log_debug("") {" (@id)"}
1556
+ # log_debug("") {" (@id)"}
1599
1557
  # return value as is
1600
1558
  value
1601
1559
  when value['@type'] && value['@type'] == coerce(property)
1602
1560
  # Compact common datatype
1603
- #log_debug("") {" (@type & coerce) == #{coerce(property)}"}
1561
+ # log_debug("") {" (@type & coerce) == #{coerce(property)}"}
1604
1562
  value['@value']
1605
1563
  when coerce(property) == '@none' || value['@type']
1606
1564
  # use original expanded value
1607
1565
  value
1608
1566
  when !value['@value'].is_a?(String)
1609
- #log_debug("") {" (native)"}
1567
+ # log_debug("") {" (native)"}
1610
1568
  indexing || !index?(value) ? value['@value'] : value
1611
1569
  when value['@language'].to_s.downcase == language.to_s.downcase && value['@direction'] == direction
1612
1570
  # Compact language and direction
@@ -1627,7 +1585,7 @@ module JSON::LD
1627
1585
 
1628
1586
  # If the result is an object, tranform keys using any term keyword aliases
1629
1587
  if result.is_a?(Hash) && result.keys.any? {|k| self.alias(k) != k}
1630
- #log_debug("") {" (map to key aliases)"}
1588
+ # log_debug("") {" (map to key aliases)"}
1631
1589
  new_element = {}
1632
1590
  result.each do |k, v|
1633
1591
  new_element[self.alias(k)] = v
@@ -1635,7 +1593,7 @@ module JSON::LD
1635
1593
  result = new_element
1636
1594
  end
1637
1595
 
1638
- #log_debug("") {"=> #{result.inspect}"}
1596
+ # log_debug("") {"=> #{result.inspect}"}
1639
1597
  result
1640
1598
  end
1641
1599
 
@@ -1731,11 +1689,21 @@ module JSON::LD
1731
1689
  CONTEXT_BASE_FRAG_OR_QUERY = %w(? #).freeze
1732
1690
  CONTEXT_TYPE_ID_VOCAB = %w(@id @vocab).freeze
1733
1691
 
1692
+ ##
1693
+ # Reads the `@context` from an IO
1694
+ def load_context(io, **options)
1695
+ io.rewind
1696
+ remote_doc = API.loadRemoteDocument(io, **options)
1697
+ remote_doc.document.is_a?(String) ?
1698
+ MultiJson.load(remote_doc.document) :
1699
+ remote_doc.document
1700
+ end
1701
+
1734
1702
  def uri(value)
1735
1703
  case value.to_s
1736
1704
  when /^_:(.*)$/
1737
1705
  # Map BlankNodes if a namer is given
1738
- #log_debug "uri(bnode)#{value}: #{$1}"
1706
+ # log_debug "uri(bnode)#{value}: #{$1}"
1739
1707
  bnode(namer.get_sym($1))
1740
1708
  else
1741
1709
  value = RDF::URI(value)
@@ -1854,25 +1822,25 @@ module JSON::LD
1854
1822
  # for the type mapping or language mapping
1855
1823
  # @return [String]
1856
1824
  def select_term(iri, containers, type_language, preferred_values)
1857
- #log_debug("select_term") {
1825
+ # log_debug("select_term") {
1858
1826
  # "iri: #{iri.inspect}, " +
1859
1827
  # "containers: #{containers.inspect}, " +
1860
1828
  # "type_language: #{type_language.inspect}, " +
1861
1829
  # "preferred_values: #{preferred_values.inspect}"
1862
1830
  #}
1863
1831
  container_map = inverse_context[iri]
1864
- #log_debug(" ") {"container_map: #{container_map.inspect}"}
1832
+ # log_debug(" ") {"container_map: #{container_map.inspect}"}
1865
1833
  containers.each do |container|
1866
1834
  next unless container_map.key?(container)
1867
1835
  tl_map = container_map[container]
1868
1836
  value_map = tl_map[type_language]
1869
1837
  preferred_values.each do |item|
1870
1838
  next unless value_map.key?(item)
1871
- #log_debug("=>") {value_map[item].inspect}
1839
+ # log_debug("=>") {value_map[item].inspect}
1872
1840
  return value_map[item]
1873
1841
  end
1874
1842
  end
1875
- #log_debug("=>") {"nil"}
1843
+ # log_debug("=>") {"nil"}
1876
1844
  nil
1877
1845
  end
1878
1846
 
@@ -29,13 +29,13 @@ module JSON::LD
29
29
  # @return [Array<Hash{String => Object}>]
30
30
  def expand(input, active_property, context,
31
31
  framing: false, from_map: false, log_depth: nil)
32
- log_debug("expand", depth: log_depth.to_i) {"input: #{input.inspect}, active_property: #{active_property.inspect}, context: #{context.inspect}"}
32
+ # log_debug("expand", depth: log_depth.to_i) {"input: #{input.inspect}, active_property: #{active_property.inspect}, context: #{context.inspect}"}
33
33
  framing = false if active_property == '@default'
34
34
  expanded_active_property = context.expand_iri(active_property, vocab: true, as_string: true, base: @options[:base]) if active_property
35
35
 
36
36
  # Use a term-specific context, if defined, based on the non-type-scoped context.
37
37
  property_scoped_context = context.term_definitions[active_property].context if active_property && context.term_definitions[active_property]
38
- log_debug("expand", depth: log_depth.to_i) {"property_scoped_context: #{property_scoped_context.inspect}"} unless property_scoped_context.nil?
38
+ # log_debug("expand", depth: log_depth.to_i) {"property_scoped_context: #{property_scoped_context.inspect}"} unless property_scoped_context.nil?
39
39
 
40
40
  result = case input
41
41
  when Array
@@ -76,7 +76,7 @@ module JSON::LD
76
76
  !(expanded_key_map.values == ['@id'])
77
77
 
78
78
  # If there's a previous context, the context was type-scoped
79
- log_debug("expand", depth: log_depth.to_i) {"previous_context: #{context.previous_context.inspect}"} if revert_context
79
+ # log_debug("expand", depth: log_depth.to_i) {"previous_context: #{context.previous_context.inspect}"} if revert_context
80
80
  context = context.previous_context if revert_context
81
81
  end
82
82
 
@@ -84,12 +84,12 @@ module JSON::LD
84
84
  unless property_scoped_context.nil?
85
85
  context = context.parse(property_scoped_context, base: @options[:base], override_protected: true)
86
86
  end
87
- log_debug("expand", depth: log_depth.to_i) {"after property_scoped_context: #{context.inspect}"} unless property_scoped_context.nil?
87
+ # log_debug("expand", depth: log_depth.to_i) {"after property_scoped_context: #{context.inspect}"} unless property_scoped_context.nil?
88
88
 
89
89
  # If element contains the key @context, set active context to the result of the Context Processing algorithm, passing active context and the value of the @context key as local context.
90
90
  if input.key?('@context')
91
91
  context = context.parse(input['@context'], base: @options[:base])
92
- log_debug("expand", depth: log_depth.to_i) {"context: #{context.inspect}"}
92
+ # log_debug("expand", depth: log_depth.to_i) {"context: #{context.inspect}"}
93
93
  end
94
94
 
95
95
  # Set the type-scoped context to the context on input, for use later
@@ -107,7 +107,7 @@ module JSON::LD
107
107
  Array(input[tk]).sort.each do |term|
108
108
  term_context = type_scoped_context.term_definitions[term].context if type_scoped_context.term_definitions[term]
109
109
  unless term_context.nil?
110
- log_debug("expand", depth: log_depth.to_i) {"term_context[#{term}]: #{term_context.inspect}"}
110
+ # log_debug("expand", depth: log_depth.to_i) {"term_context[#{term}]: #{term_context.inspect}"}
111
111
  context = context.parse(term_context, base: @options[:base], propagate: false)
112
112
  end
113
113
  end
@@ -121,7 +121,7 @@ module JSON::LD
121
121
  type_scoped_context: type_scoped_context,
122
122
  log_depth: log_depth.to_i + 1)
123
123
 
124
- log_debug("output object", depth: log_depth.to_i) {output_object.inspect}
124
+ # log_debug("output object", depth: log_depth.to_i) {output_object.inspect}
125
125
 
126
126
  # If result contains the key @value:
127
127
  if value?(output_object)
@@ -199,7 +199,7 @@ module JSON::LD
199
199
  if (expanded_active_property || '@graph') == '@graph' &&
200
200
  (output_object.key?('@value') || output_object.key?('@list') ||
201
201
  (output_object.keys - KEY_ID).empty? && !framing)
202
- log_debug(" =>", depth: log_depth.to_i) { "empty top-level: " + output_object.inspect}
202
+ # log_debug(" =>", depth: log_depth.to_i) { "empty top-level: " + output_object.inspect}
203
203
  return nil
204
204
  end
205
205
 
@@ -219,12 +219,12 @@ module JSON::LD
219
219
  base: @options[:base],
220
220
  override_protected: true)
221
221
  end
222
- log_debug("expand", depth: log_depth.to_i) {"property_scoped_context: #{context.inspect}"} unless property_scoped_context.nil?
222
+ # log_debug("expand", depth: log_depth.to_i) {"property_scoped_context: #{context.inspect}"} unless property_scoped_context.nil?
223
223
 
224
224
  context.expand_value(active_property, input, base: @options[:base])
225
225
  end
226
226
 
227
- log_debug(depth: log_depth.to_i) {" => #{result.inspect}"}
227
+ # log_debug(depth: log_depth.to_i) {" => #{result.inspect}"}
228
228
  result
229
229
  end
230
230
 
@@ -258,10 +258,10 @@ module JSON::LD
258
258
  expanded_property.to_s.start_with?("_:") &&
259
259
  context.processingMode('json-ld-1.1')
260
260
 
261
- log_debug("expand property", depth: log_depth.to_i) {"ap: #{active_property.inspect}, expanded: #{expanded_property.inspect}, value: #{value.inspect}"}
261
+ # log_debug("expand property", depth: log_depth.to_i) {"ap: #{active_property.inspect}, expanded: #{expanded_property.inspect}, value: #{value.inspect}"}
262
262
 
263
263
  if expanded_property.nil?
264
- log_debug(" => ", depth: log_depth.to_i) {"skip nil property"}
264
+ # log_debug(" => ", depth: log_depth.to_i) {"skip nil property"}
265
265
  next
266
266
  end
267
267
 
@@ -341,7 +341,7 @@ module JSON::LD
341
341
  Array(output_object['@included']) + included_result
342
342
  when '@type'
343
343
  # If expanded property is @type and value is neither a string nor an array of strings, an invalid type value error has been detected and processing is aborted. Otherwise, set expanded value to the result of using the IRI Expansion algorithm, passing active context, true for vocab, and true for document relative to expand the value or each of its items.
344
- log_debug("@type", depth: log_depth.to_i) {"value: #{value.inspect}"}
344
+ # log_debug("@type", depth: log_depth.to_i) {"value: #{value.inspect}"}
345
345
  e_type = case value
346
346
  when Array
347
347
  value.map do |v|
@@ -516,7 +516,7 @@ module JSON::LD
516
516
 
517
517
  # If expanded value contains an @reverse member, i.e., properties that are reversed twice, execute for each of its property and item the following steps:
518
518
  if value.key?('@reverse')
519
- log_debug("@reverse", depth: log_depth.to_i) {"double reverse: #{value.inspect}"}
519
+ # log_debug("@reverse", depth: log_depth.to_i) {"double reverse: #{value.inspect}"}
520
520
  value['@reverse'].each do |property, item|
521
521
  # If result does not have a property member, create one and set its value to an empty array.
522
522
  # Append item to the value of the property member of result.
@@ -566,7 +566,7 @@ module JSON::LD
566
566
  end
567
567
 
568
568
  # Unless expanded value is null, set the expanded property member of result to expanded value.
569
- log_debug("expand #{expanded_property}", depth: log_depth.to_i) { expanded_value.inspect}
569
+ # log_debug("expand #{expanded_property}", depth: log_depth.to_i) { expanded_value.inspect}
570
570
  output_object[expanded_property] = expanded_value unless expanded_value.nil? && expanded_property == '@value' && input_type != '@json'
571
571
  next
572
572
  end
@@ -619,7 +619,7 @@ module JSON::LD
619
619
  if id_context.nil?
620
620
  context
621
621
  else
622
- log_debug("expand", depth: log_depth.to_i) {"id_context: #{id_context.inspect}"}
622
+ # log_debug("expand", depth: log_depth.to_i) {"id_context: #{id_context.inspect}"}
623
623
  context.parse(id_context, base: @options[:base], propagate: false)
624
624
  end
625
625
  else
@@ -632,7 +632,7 @@ module JSON::LD
632
632
  # If container mapping in the active context includes @type, and k is a term in the active context having a local context, use that context when expanding values
633
633
  map_context = container_context.term_definitions[k].context if container.include?('@type') && container_context.term_definitions[k]
634
634
  unless map_context.nil?
635
- log_debug("expand", depth: log_depth.to_i) {"map_context: #{map_context.inspect}"}
635
+ # log_debug("expand", depth: log_depth.to_i) {"map_context: #{map_context.inspect}"}
636
636
  map_context = container_context.parse(map_context, base: @options[:base],
637
637
  propagate: false)
638
638
  end
@@ -688,21 +688,21 @@ module JSON::LD
688
688
 
689
689
  # If expanded value is null, ignore key by continuing to the next key from element.
690
690
  if expanded_value.nil?
691
- log_debug(" => skip nil value", depth: log_depth.to_i)
691
+ # log_debug(" => skip nil value", depth: log_depth.to_i)
692
692
  next
693
693
  end
694
- log_debug(depth: log_depth.to_i) {" => #{expanded_value.inspect}"}
694
+ # log_debug(depth: log_depth.to_i) {" => #{expanded_value.inspect}"}
695
695
 
696
696
  # If the container mapping associated to key in active context is @list and expanded value is not already a list object, convert expanded value to a list object by first setting it to an array containing only expanded value if it is not already an array, and then by setting it to a JSON object containing the key-value pair @list-expanded value.
697
697
  if container.first == '@list' && container.length == 1 && !list?(expanded_value)
698
- log_debug(" => ", depth: log_depth.to_i) { "convert #{expanded_value.inspect} to list"}
698
+ # log_debug(" => ", depth: log_depth.to_i) { "convert #{expanded_value.inspect} to list"}
699
699
  expanded_value = {'@list' => as_array(expanded_value)}
700
700
  end
701
- log_debug(depth: log_depth.to_i) {" => #{expanded_value.inspect}"}
701
+ # log_debug(depth: log_depth.to_i) {" => #{expanded_value.inspect}"}
702
702
 
703
703
  # convert expanded value to @graph if container specifies it
704
704
  if container.first == '@graph' && container.length == 1
705
- log_debug(" => ", depth: log_depth.to_i) { "convert #{expanded_value.inspect} to list"}
705
+ # log_debug(" => ", depth: log_depth.to_i) { "convert #{expanded_value.inspect} to list"}
706
706
  expanded_value = as_array(expanded_value).map do |v|
707
707
  {'@graph' => as_array(v)}
708
708
  end
@@ -742,7 +742,7 @@ module JSON::LD
742
742
  nest_context = if nest_context.nil?
743
743
  context
744
744
  else
745
- log_debug("expand", depth: log_depth.to_i) {"nest_context: #{nest_context.inspect}"}
745
+ # log_debug("expand", depth: log_depth.to_i) {"nest_context: #{nest_context.inspect}"}
746
746
  context.parse(nest_context, base: @options[:base],
747
747
  override_protected: true)
748
748
  end