json-ld 3.2.3 → 3.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/json/ld/api.rb +807 -764
  4. data/lib/json/ld/compact.rb +304 -304
  5. data/lib/json/ld/conneg.rb +179 -161
  6. data/lib/json/ld/context.rb +2080 -1945
  7. data/lib/json/ld/expand.rb +745 -666
  8. data/lib/json/ld/extensions.rb +14 -13
  9. data/lib/json/ld/flatten.rb +257 -247
  10. data/lib/json/ld/format.rb +202 -194
  11. data/lib/json/ld/frame.rb +525 -502
  12. data/lib/json/ld/from_rdf.rb +224 -166
  13. data/lib/json/ld/html/nokogiri.rb +123 -121
  14. data/lib/json/ld/html/rexml.rb +151 -147
  15. data/lib/json/ld/reader.rb +107 -100
  16. data/lib/json/ld/resource.rb +224 -205
  17. data/lib/json/ld/streaming_reader.rb +574 -507
  18. data/lib/json/ld/streaming_writer.rb +93 -92
  19. data/lib/json/ld/to_rdf.rb +171 -167
  20. data/lib/json/ld/utils.rb +270 -264
  21. data/lib/json/ld/version.rb +24 -14
  22. data/lib/json/ld/writer.rb +334 -311
  23. data/lib/json/ld.rb +103 -96
  24. metadata +78 -209
  25. data/spec/api_spec.rb +0 -132
  26. data/spec/compact_spec.rb +0 -3482
  27. data/spec/conneg_spec.rb +0 -373
  28. data/spec/context_spec.rb +0 -2036
  29. data/spec/expand_spec.rb +0 -4496
  30. data/spec/flatten_spec.rb +0 -1203
  31. data/spec/format_spec.rb +0 -115
  32. data/spec/frame_spec.rb +0 -2498
  33. data/spec/from_rdf_spec.rb +0 -1005
  34. data/spec/matchers.rb +0 -20
  35. data/spec/rdfstar_spec.rb +0 -25
  36. data/spec/reader_spec.rb +0 -883
  37. data/spec/resource_spec.rb +0 -76
  38. data/spec/spec_helper.rb +0 -281
  39. data/spec/streaming_reader_spec.rb +0 -237
  40. data/spec/streaming_writer_spec.rb +0 -145
  41. data/spec/suite_compact_spec.rb +0 -22
  42. data/spec/suite_expand_spec.rb +0 -36
  43. data/spec/suite_flatten_spec.rb +0 -34
  44. data/spec/suite_frame_spec.rb +0 -29
  45. data/spec/suite_from_rdf_spec.rb +0 -22
  46. data/spec/suite_helper.rb +0 -411
  47. data/spec/suite_html_spec.rb +0 -22
  48. data/spec/suite_http_spec.rb +0 -35
  49. data/spec/suite_remote_doc_spec.rb +0 -22
  50. data/spec/suite_to_rdf_spec.rb +0 -30
  51. data/spec/support/extensions.rb +0 -44
  52. data/spec/test-files/test-1-compacted.jsonld +0 -10
  53. data/spec/test-files/test-1-context.jsonld +0 -7
  54. data/spec/test-files/test-1-expanded.jsonld +0 -5
  55. data/spec/test-files/test-1-input.jsonld +0 -10
  56. data/spec/test-files/test-1-rdf.ttl +0 -8
  57. data/spec/test-files/test-2-compacted.jsonld +0 -20
  58. data/spec/test-files/test-2-context.jsonld +0 -7
  59. data/spec/test-files/test-2-expanded.jsonld +0 -16
  60. data/spec/test-files/test-2-input.jsonld +0 -20
  61. data/spec/test-files/test-2-rdf.ttl +0 -14
  62. data/spec/test-files/test-3-compacted.jsonld +0 -11
  63. data/spec/test-files/test-3-context.jsonld +0 -8
  64. data/spec/test-files/test-3-expanded.jsonld +0 -10
  65. data/spec/test-files/test-3-input.jsonld +0 -11
  66. data/spec/test-files/test-3-rdf.ttl +0 -8
  67. data/spec/test-files/test-4-compacted.jsonld +0 -10
  68. data/spec/test-files/test-4-context.jsonld +0 -7
  69. data/spec/test-files/test-4-expanded.jsonld +0 -6
  70. data/spec/test-files/test-4-input.jsonld +0 -10
  71. data/spec/test-files/test-4-rdf.ttl +0 -5
  72. data/spec/test-files/test-5-compacted.jsonld +0 -13
  73. data/spec/test-files/test-5-context.jsonld +0 -7
  74. data/spec/test-files/test-5-expanded.jsonld +0 -9
  75. data/spec/test-files/test-5-input.jsonld +0 -13
  76. data/spec/test-files/test-5-rdf.ttl +0 -7
  77. data/spec/test-files/test-6-compacted.jsonld +0 -10
  78. data/spec/test-files/test-6-context.jsonld +0 -7
  79. data/spec/test-files/test-6-expanded.jsonld +0 -10
  80. data/spec/test-files/test-6-input.jsonld +0 -10
  81. data/spec/test-files/test-6-rdf.ttl +0 -6
  82. data/spec/test-files/test-7-compacted.jsonld +0 -23
  83. data/spec/test-files/test-7-context.jsonld +0 -4
  84. data/spec/test-files/test-7-expanded.jsonld +0 -20
  85. data/spec/test-files/test-7-input.jsonld +0 -23
  86. data/spec/test-files/test-7-rdf.ttl +0 -14
  87. data/spec/test-files/test-8-compacted.jsonld +0 -34
  88. data/spec/test-files/test-8-context.jsonld +0 -11
  89. data/spec/test-files/test-8-expanded.jsonld +0 -24
  90. data/spec/test-files/test-8-frame.jsonld +0 -18
  91. data/spec/test-files/test-8-framed.jsonld +0 -25
  92. data/spec/test-files/test-8-input.jsonld +0 -30
  93. data/spec/test-files/test-8-rdf.ttl +0 -15
  94. data/spec/test-files/test-9-compacted.jsonld +0 -20
  95. data/spec/test-files/test-9-context.jsonld +0 -13
  96. data/spec/test-files/test-9-expanded.jsonld +0 -14
  97. data/spec/test-files/test-9-input.jsonld +0 -12
  98. data/spec/to_rdf_spec.rb +0 -1551
  99. data/spec/writer_spec.rb +0 -427
data/lib/json/ld.rb CHANGED
@@ -1,6 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
1
  # frozen_string_literal: true
3
- $:.unshift(File.expand_path("../ld", __FILE__))
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('ld', __dir__))
4
4
  require 'rdf' # @see https://rubygems.org/gems/rdf
5
5
  require 'multi_json'
6
6
  require 'set'
@@ -40,47 +40,47 @@ module JSON
40
40
  autoload :Writer, 'json/ld/writer'
41
41
 
42
42
  # JSON-LD profiles
43
- JSON_LD_NS = "http://www.w3.org/ns/json-ld#"
44
- PROFILES = %w(expanded compacted flattened framed).map {|p| JSON_LD_NS + p}.freeze
43
+ JSON_LD_NS = 'http://www.w3.org/ns/json-ld#'
44
+ PROFILES = %w[expanded compacted flattened framed].map { |p| JSON_LD_NS + p }.freeze
45
45
 
46
46
  # Default context when compacting without one being specified
47
- DEFAULT_CONTEXT = "http://schema.org"
47
+ DEFAULT_CONTEXT = 'http://schema.org'
48
48
 
49
49
  # Acceptable MultiJson adapters
50
- MUTLI_JSON_ADAPTERS = %i(oj json_gem json_pure ok_json yajl nsjsonseerialization)
50
+ MUTLI_JSON_ADAPTERS = %i[oj json_gem json_pure ok_json yajl nsjsonseerialization]
51
51
 
52
- KEYWORDS = Set.new(%w(
53
- @annotation
54
- @base
55
- @container
56
- @context
57
- @default
58
- @direction
59
- @embed
60
- @explicit
61
- @first
62
- @graph
63
- @id
64
- @import
65
- @included
66
- @index
67
- @json
68
- @language
69
- @list
70
- @nest
71
- @none
72
- @omitDefault
73
- @propagate
74
- @protected
75
- @preserve
76
- @requireAll
77
- @reverse
78
- @set
79
- @type
80
- @value
81
- @version
82
- @vocab
83
- )).freeze
52
+ KEYWORDS = Set.new(%w[
53
+ @annotation
54
+ @base
55
+ @container
56
+ @context
57
+ @default
58
+ @direction
59
+ @embed
60
+ @explicit
61
+ @first
62
+ @graph
63
+ @id
64
+ @import
65
+ @included
66
+ @index
67
+ @json
68
+ @language
69
+ @list
70
+ @nest
71
+ @none
72
+ @omitDefault
73
+ @propagate
74
+ @protected
75
+ @preserve
76
+ @requireAll
77
+ @reverse
78
+ @set
79
+ @type
80
+ @value
81
+ @version
82
+ @vocab
83
+ ]).freeze
84
84
 
85
85
  # Regexp matching an NCName.
86
86
  NC_REGEXP = Regexp.new(
@@ -90,87 +90,94 @@ module JSON
90
90
  ( [a-zA-Z_]
91
91
  | \\\\u[0-9a-fA-F]
92
92
  )
93
- ( [0-9a-zA-Z_\.-]
93
+ ( [0-9a-zA-Z_.-]
94
94
  | \\\\u([0-9a-fA-F]{4})
95
95
  )*
96
96
  $},
97
- Regexp::EXTENDED)
97
+ Regexp::EXTENDED
98
+ )
98
99
 
99
100
  # Datatypes that are expressed in a native form and don't expand or compact
100
101
  NATIVE_DATATYPES = [RDF::XSD.integer.to_s, RDF::XSD.boolean.to_s, RDF::XSD.double.to_s]
101
102
 
102
103
  JSON_STATE = JSON::State.new(
103
- indent: " ",
104
- space: " ",
105
- space_before: "",
104
+ indent: ' ',
105
+ space: ' ',
106
+ space_before: '',
106
107
  object_nl: "\n",
107
108
  array_nl: "\n"
108
109
  )
109
110
 
110
111
  MAX_CONTEXTS_LOADED = 50
111
112
 
113
+ # URI Constants
114
+ RDF_JSON = RDF::URI("#{RDF.to_uri}JSON")
115
+ RDF_DIRECTION = RDF::URI("#{RDF.to_uri}direction")
116
+ RDF_LANGUAGE = RDF::URI("#{RDF.to_uri}language")
117
+
112
118
  class JsonLdError < StandardError
113
119
  def to_s
114
120
  "#{self.class.instance_variable_get :@code}: #{super}"
115
121
  end
122
+
116
123
  def code
117
124
  self.class.instance_variable_get :@code
118
125
  end
119
126
 
120
- class CollidingKeywords < JsonLdError; @code = "colliding keywords"; end
121
- class ConflictingIndexes < JsonLdError; @code = "conflicting indexes"; end
122
- class CyclicIRIMapping < JsonLdError; @code = "cyclic IRI mapping"; end
123
- class InvalidAnnotation < JsonLdError; @code = "invalid annotation"; end
124
- class InvalidBaseIRI < JsonLdError; @code = "invalid base IRI"; end
125
- class InvalidContainerMapping < JsonLdError; @code = "invalid container mapping"; end
126
- class InvalidContextEntry < JsonLdError; @code = "invalid context entry"; end
127
- class InvalidContextNullification < JsonLdError; @code = "invalid context nullification"; end
128
- class InvalidDefaultLanguage < JsonLdError; @code = "invalid default language"; end
129
- class InvalidIdValue < JsonLdError; @code = "invalid @id value"; end
130
- class InvalidIndexValue < JsonLdError; @code = "invalid @index value"; end
131
- class InvalidVersionValue < JsonLdError; @code = "invalid @version value"; end
132
- class InvalidImportValue < JsonLdError; @code = "invalid @import value"; end
133
- class InvalidIncludedValue < JsonLdError; @code = "invalid @included value"; end
134
- class InvalidIRIMapping < JsonLdError; @code = "invalid IRI mapping"; end
135
- class InvalidJsonLiteral < JsonLdError; @code = "invalid JSON literal"; end
136
- class InvalidKeywordAlias < JsonLdError; @code = "invalid keyword alias"; end
137
- class InvalidLanguageMapping < JsonLdError; @code = "invalid language mapping"; end
138
- class InvalidLanguageMapValue < JsonLdError; @code = "invalid language map value"; end
139
- class InvalidLanguageTaggedString < JsonLdError; @code = "invalid language-tagged string"; end
140
- class InvalidLanguageTaggedValue < JsonLdError; @code = "invalid language-tagged value"; end
141
- class InvalidLocalContext < JsonLdError; @code = "invalid local context"; end
142
- class InvalidNestValue < JsonLdError; @code = "invalid @nest value"; end
143
- class InvalidPrefixValue < JsonLdError; @code = "invalid @prefix value"; end
144
- class InvalidPropagateValue < JsonLdError; @code = "invalid @propagate value"; end
145
- class InvalidEmbeddedNode < JsonLdError; @code = "invalid embedded node"; end
146
- class InvalidRemoteContext < JsonLdError; @code = "invalid remote context"; end
147
- class InvalidReverseProperty < JsonLdError; @code = "invalid reverse property"; end
148
- class InvalidReversePropertyMap < JsonLdError; @code = "invalid reverse property map"; end
149
- class InvalidReversePropertyValue < JsonLdError; @code = "invalid reverse property value"; end
150
- class InvalidReverseValue < JsonLdError; @code = "invalid @reverse value"; end
151
- class InvalidScopedContext < JsonLdError; @code = "invalid scoped context"; end
152
- class InvalidScriptElement < JsonLdError; @code = "invalid script element"; end
153
- class InvalidSetOrListObject < JsonLdError; @code = "invalid set or list object"; end
127
+ class CollidingKeywords < JsonLdError; @code = 'colliding keywords'; end
128
+ class ConflictingIndexes < JsonLdError; @code = 'conflicting indexes'; end
129
+ class CyclicIRIMapping < JsonLdError; @code = 'cyclic IRI mapping'; end
130
+ class InvalidAnnotation < JsonLdError; @code = 'invalid annotation'; end
131
+ class InvalidBaseIRI < JsonLdError; @code = 'invalid base IRI'; end
132
+ class InvalidContainerMapping < JsonLdError; @code = 'invalid container mapping'; end
133
+ class InvalidContextEntry < JsonLdError; @code = 'invalid context entry'; end
134
+ class InvalidContextNullification < JsonLdError; @code = 'invalid context nullification'; end
135
+ class InvalidDefaultLanguage < JsonLdError; @code = 'invalid default language'; end
136
+ class InvalidIdValue < JsonLdError; @code = 'invalid @id value'; end
137
+ class InvalidIndexValue < JsonLdError; @code = 'invalid @index value'; end
138
+ class InvalidVersionValue < JsonLdError; @code = 'invalid @version value'; end
139
+ class InvalidImportValue < JsonLdError; @code = 'invalid @import value'; end
140
+ class InvalidIncludedValue < JsonLdError; @code = 'invalid @included value'; end
141
+ class InvalidIRIMapping < JsonLdError; @code = 'invalid IRI mapping'; end
142
+ class InvalidJsonLiteral < JsonLdError; @code = 'invalid JSON literal'; end
143
+ class InvalidKeywordAlias < JsonLdError; @code = 'invalid keyword alias'; end
144
+ class InvalidLanguageMapping < JsonLdError; @code = 'invalid language mapping'; end
145
+ class InvalidLanguageMapValue < JsonLdError; @code = 'invalid language map value'; end
146
+ class InvalidLanguageTaggedString < JsonLdError; @code = 'invalid language-tagged string'; end
147
+ class InvalidLanguageTaggedValue < JsonLdError; @code = 'invalid language-tagged value'; end
148
+ class InvalidLocalContext < JsonLdError; @code = 'invalid local context'; end
149
+ class InvalidNestValue < JsonLdError; @code = 'invalid @nest value'; end
150
+ class InvalidPrefixValue < JsonLdError; @code = 'invalid @prefix value'; end
151
+ class InvalidPropagateValue < JsonLdError; @code = 'invalid @propagate value'; end
152
+ class InvalidEmbeddedNode < JsonLdError; @code = 'invalid embedded node'; end
153
+ class InvalidRemoteContext < JsonLdError; @code = 'invalid remote context'; end
154
+ class InvalidReverseProperty < JsonLdError; @code = 'invalid reverse property'; end
155
+ class InvalidReversePropertyMap < JsonLdError; @code = 'invalid reverse property map'; end
156
+ class InvalidReversePropertyValue < JsonLdError; @code = 'invalid reverse property value'; end
157
+ class InvalidReverseValue < JsonLdError; @code = 'invalid @reverse value'; end
158
+ class InvalidScopedContext < JsonLdError; @code = 'invalid scoped context'; end
159
+ class InvalidScriptElement < JsonLdError; @code = 'invalid script element'; end
160
+ class InvalidSetOrListObject < JsonLdError; @code = 'invalid set or list object'; end
154
161
  class InvalidStreamingKeyOrder < JsonLdError; @code = 'invalid streaming key order' end
155
- class InvalidTermDefinition < JsonLdError; @code = "invalid term definition"; end
156
- class InvalidBaseDirection < JsonLdError; @code = "invalid base direction"; end
157
- class InvalidTypedValue < JsonLdError; @code = "invalid typed value"; end
158
- class InvalidTypeMapping < JsonLdError; @code = "invalid type mapping"; end
159
- class InvalidTypeValue < JsonLdError; @code = "invalid type value"; end
160
- class InvalidValueObject < JsonLdError; @code = "invalid value object"; end
161
- class InvalidValueObjectValue < JsonLdError; @code = "invalid value object value"; end
162
- class InvalidVocabMapping < JsonLdError; @code = "invalid vocab mapping"; end
163
- class IRIConfusedWithPrefix < JsonLdError; @code = "IRI confused with prefix"; end
164
- class KeywordRedefinition < JsonLdError; @code = "keyword redefinition"; end
165
- class LoadingDocumentFailed < JsonLdError; @code = "loading document failed"; end
166
- class LoadingRemoteContextFailed < JsonLdError; @code = "loading remote context failed"; end
167
- class ContextOverflow < JsonLdError; @code = "context overflow"; end
168
- class MissingIncludedReferent < JsonLdError; @code = "missing @included referent"; end
169
- class MultipleContextLinkHeaders < JsonLdError; @code = "multiple context link headers"; end
170
- class ProtectedTermRedefinition < JsonLdError; @code = "protected term redefinition"; end
171
- class ProcessingModeConflict < JsonLdError; @code = "processing mode conflict"; end
172
- class InvalidFrame < JsonLdError; @code = "invalid frame"; end
173
- class InvalidEmbedValue < InvalidFrame; @code = "invalid @embed value"; end
162
+ class InvalidTermDefinition < JsonLdError; @code = 'invalid term definition'; end
163
+ class InvalidBaseDirection < JsonLdError; @code = 'invalid base direction'; end
164
+ class InvalidTypedValue < JsonLdError; @code = 'invalid typed value'; end
165
+ class InvalidTypeMapping < JsonLdError; @code = 'invalid type mapping'; end
166
+ class InvalidTypeValue < JsonLdError; @code = 'invalid type value'; end
167
+ class InvalidValueObject < JsonLdError; @code = 'invalid value object'; end
168
+ class InvalidValueObjectValue < JsonLdError; @code = 'invalid value object value'; end
169
+ class InvalidVocabMapping < JsonLdError; @code = 'invalid vocab mapping'; end
170
+ class IRIConfusedWithPrefix < JsonLdError; @code = 'IRI confused with prefix'; end
171
+ class KeywordRedefinition < JsonLdError; @code = 'keyword redefinition'; end
172
+ class LoadingDocumentFailed < JsonLdError; @code = 'loading document failed'; end
173
+ class LoadingRemoteContextFailed < JsonLdError; @code = 'loading remote context failed'; end
174
+ class ContextOverflow < JsonLdError; @code = 'context overflow'; end
175
+ class MissingIncludedReferent < JsonLdError; @code = 'missing @included referent'; end
176
+ class MultipleContextLinkHeaders < JsonLdError; @code = 'multiple context link headers'; end
177
+ class ProtectedTermRedefinition < JsonLdError; @code = 'protected term redefinition'; end
178
+ class ProcessingModeConflict < JsonLdError; @code = 'processing mode conflict'; end
179
+ class InvalidFrame < JsonLdError; @code = 'invalid frame'; end
180
+ class InvalidEmbedValue < InvalidFrame; @code = 'invalid @embed value'; end
174
181
  end
175
182
  end
176
183
  end