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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -764
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1945
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +224 -166
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -167
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +78 -209
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2036
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2498
- data/spec/from_rdf_spec.rb +0 -1005
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1551
- 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
|
-
|
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 =
|
44
|
-
PROFILES = %w
|
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 =
|
47
|
+
DEFAULT_CONTEXT = 'http://schema.org'
|
48
48
|
|
49
49
|
# Acceptable MultiJson adapters
|
50
|
-
MUTLI_JSON_ADAPTERS = %i
|
50
|
+
MUTLI_JSON_ADAPTERS = %i[oj json_gem json_pure ok_json yajl nsjsonseerialization]
|
51
51
|
|
52
|
-
KEYWORDS = Set.new(%w
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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 =
|
121
|
-
class ConflictingIndexes < JsonLdError; @code =
|
122
|
-
class CyclicIRIMapping < JsonLdError; @code =
|
123
|
-
class InvalidAnnotation < JsonLdError; @code =
|
124
|
-
class InvalidBaseIRI < JsonLdError; @code =
|
125
|
-
class InvalidContainerMapping < JsonLdError; @code =
|
126
|
-
class InvalidContextEntry < JsonLdError; @code =
|
127
|
-
class InvalidContextNullification < JsonLdError; @code =
|
128
|
-
class InvalidDefaultLanguage < JsonLdError; @code =
|
129
|
-
class InvalidIdValue < JsonLdError; @code =
|
130
|
-
class InvalidIndexValue < JsonLdError; @code =
|
131
|
-
class InvalidVersionValue < JsonLdError; @code =
|
132
|
-
class InvalidImportValue < JsonLdError; @code =
|
133
|
-
class InvalidIncludedValue < JsonLdError; @code =
|
134
|
-
class InvalidIRIMapping < JsonLdError; @code =
|
135
|
-
class InvalidJsonLiteral < JsonLdError; @code =
|
136
|
-
class InvalidKeywordAlias < JsonLdError; @code =
|
137
|
-
class InvalidLanguageMapping < JsonLdError; @code =
|
138
|
-
class InvalidLanguageMapValue < JsonLdError; @code =
|
139
|
-
class InvalidLanguageTaggedString < JsonLdError; @code =
|
140
|
-
class InvalidLanguageTaggedValue < JsonLdError; @code =
|
141
|
-
class InvalidLocalContext < JsonLdError; @code =
|
142
|
-
class InvalidNestValue < JsonLdError; @code =
|
143
|
-
class InvalidPrefixValue < JsonLdError; @code =
|
144
|
-
class InvalidPropagateValue < JsonLdError; @code =
|
145
|
-
class InvalidEmbeddedNode < JsonLdError; @code =
|
146
|
-
class InvalidRemoteContext < JsonLdError; @code =
|
147
|
-
class InvalidReverseProperty < JsonLdError; @code =
|
148
|
-
class InvalidReversePropertyMap < JsonLdError; @code =
|
149
|
-
class InvalidReversePropertyValue < JsonLdError; @code =
|
150
|
-
class InvalidReverseValue < JsonLdError; @code =
|
151
|
-
class InvalidScopedContext < JsonLdError; @code =
|
152
|
-
class InvalidScriptElement < JsonLdError; @code =
|
153
|
-
class InvalidSetOrListObject < JsonLdError; @code =
|
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 =
|
156
|
-
class InvalidBaseDirection < JsonLdError; @code =
|
157
|
-
class InvalidTypedValue < JsonLdError; @code =
|
158
|
-
class InvalidTypeMapping < JsonLdError; @code =
|
159
|
-
class InvalidTypeValue < JsonLdError; @code =
|
160
|
-
class InvalidValueObject < JsonLdError; @code =
|
161
|
-
class InvalidValueObjectValue < JsonLdError; @code =
|
162
|
-
class InvalidVocabMapping < JsonLdError; @code =
|
163
|
-
class IRIConfusedWithPrefix < JsonLdError; @code =
|
164
|
-
class KeywordRedefinition < JsonLdError; @code =
|
165
|
-
class LoadingDocumentFailed < JsonLdError; @code =
|
166
|
-
class LoadingRemoteContextFailed < JsonLdError; @code =
|
167
|
-
class ContextOverflow < JsonLdError; @code =
|
168
|
-
class MissingIncludedReferent < JsonLdError; @code =
|
169
|
-
class MultipleContextLinkHeaders < JsonLdError; @code =
|
170
|
-
class ProtectedTermRedefinition < JsonLdError; @code =
|
171
|
-
class ProcessingModeConflict < JsonLdError; @code =
|
172
|
-
class InvalidFrame < JsonLdError; @code =
|
173
|
-
class InvalidEmbedValue < InvalidFrame; @code =
|
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
|