json-ld 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/VERSION +1 -1
- data/bin/jsonld +2 -2
- data/lib/json/ld/api.rb +9 -3
- data/lib/json/ld/context.rb +252 -117
- data/lib/json/ld/frame.rb +8 -8
- data/lib/json/ld/from_rdf.rb +8 -3
- data/lib/json/ld/writer.rb +9 -2
- data/spec/api_spec.rb +4 -4
- data/spec/compact_spec.rb +11 -11
- data/spec/context_spec.rb +274 -136
- data/spec/expand_spec.rb +15 -15
- data/spec/flatten_spec.rb +1 -1
- data/spec/format_spec.rb +6 -6
- data/spec/frame_spec.rb +54 -1
- data/spec/from_rdf_spec.rb +112 -77
- data/spec/matchers.rb +3 -3
- data/spec/reader_spec.rb +6 -6
- data/spec/resource_spec.rb +6 -6
- data/spec/to_rdf_spec.rb +4 -8
- data/spec/writer_spec.rb +1 -1
- metadata +18 -4
data/lib/json/ld/frame.rb
CHANGED
@@ -10,13 +10,15 @@ module JSON::LD
|
|
10
10
|
# @param [Hash{String => Hash}] nodes
|
11
11
|
# Map of flattened nodes
|
12
12
|
# @param [Hash{String => Object}] frame
|
13
|
-
# @param [Hash{
|
13
|
+
# @param [Hash{Symbol => Object}] options ({})
|
14
|
+
# @option options [Hash{String => Object}] :parent
|
14
15
|
# Parent node or top-level array
|
15
|
-
# @
|
16
|
+
# @option options [String] :property
|
16
17
|
# Property referencing this frame, or null for array.
|
17
18
|
# @raise [JSON::LD::InvalidFrame]
|
18
|
-
def frame(state, nodes, frame,
|
19
|
+
def frame(state, nodes, frame, options = {})
|
19
20
|
depth do
|
21
|
+
parent, property = options[:parent], options[:property]
|
20
22
|
debug("frame") {"state: #{state.inspect}"}
|
21
23
|
debug("frame") {"nodes: #{nodes.keys.inspect}"}
|
22
24
|
debug("frame") {"frame: #{frame.to_json(JSON_STATE)}"}
|
@@ -48,9 +50,7 @@ module JSON::LD
|
|
48
50
|
|
49
51
|
# If embedOn is true, and id is in map of embeds from state
|
50
52
|
if embed && (existing = state[:embeds].fetch(id, nil))
|
51
|
-
# only overwrite an existing embed if it has already been added to its
|
52
|
-
# parent -- otherwise its parent is somewhere up the tree from this
|
53
|
-
# embed and the embed would occur twice once the tree is added
|
53
|
+
# only overwrite an existing embed if it has already been added to its parent -- otherwise its parent is somewhere up the tree from this embed and the embed would occur twice once the tree is added
|
54
54
|
embed = false
|
55
55
|
|
56
56
|
embed = if existing[:parent].is_a?(Array)
|
@@ -114,7 +114,7 @@ module JSON::LD
|
|
114
114
|
debug("frame") {"list item of #{prop} recurse for #{itemid.inspect}"}
|
115
115
|
|
116
116
|
# If listitem is a node reference process listitem recursively using this algorithm passing a new map of nodes that contains the @id of listitem as the key and the node reference as the value. Pass the first value from frame for property as frame, list as parent, and @list as active property.
|
117
|
-
frame(state, {itemid => @node_map[itemid]}, frame[prop].first, list, '@list')
|
117
|
+
frame(state, {itemid => @node_map[itemid]}, frame[prop].first, parent: list, property: '@list')
|
118
118
|
else
|
119
119
|
# Otherwise, append a copy of listitem to @list in list.
|
120
120
|
debug("frame") {"list item of #{prop} non-node ref #{listitem.inspect}"}
|
@@ -128,7 +128,7 @@ module JSON::LD
|
|
128
128
|
debug("frame") {"value property #{prop} recurse for #{itemid.inspect}"}
|
129
129
|
|
130
130
|
# passing a new map as nodes that contains the @id of item as the key and the node reference as the value. Pass the first value from frame for property as frame, output as parent, and property as active property
|
131
|
-
frame(state, {itemid => @node_map[itemid]}, frame[prop].first, output, prop)
|
131
|
+
frame(state, {itemid => @node_map[itemid]}, frame[prop].first, parent: output, property: prop)
|
132
132
|
else
|
133
133
|
# Otherwise, append a copy of item to active property in output.
|
134
134
|
debug("frame") {"value property #{prop} non-node ref #{item.inspect}"}
|
data/lib/json/ld/from_rdf.rb
CHANGED
@@ -13,6 +13,7 @@ module JSON::LD
|
|
13
13
|
def from_statements(input)
|
14
14
|
default_graph = {}
|
15
15
|
graph_map = {'@default' => default_graph}
|
16
|
+
node_usages_map = {}
|
16
17
|
|
17
18
|
value = nil
|
18
19
|
ec = Context.new
|
@@ -51,9 +52,12 @@ module JSON::LD
|
|
51
52
|
if statement.object.resource?
|
52
53
|
# Append a new JSON object consisting of three members, node, property, and value to the usages array. The node member is set to a reference to node, property to predicate, and value to a reference to value.
|
53
54
|
merge_value(node_map[statement.object.to_s], :usages, {
|
54
|
-
:node
|
55
|
-
:
|
56
|
-
:value
|
55
|
+
node: node,
|
56
|
+
property: statement.predicate.to_s,
|
57
|
+
value: value
|
58
|
+
})
|
59
|
+
|
60
|
+
(node_usages_map[statement.object.to_s] ||= []) << node['@id']
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -69,6 +73,7 @@ module JSON::LD
|
|
69
73
|
# If property equals rdf:rest, the value associated to the usages member of node has exactly 1 entry, node has a rdf:first and rdf:rest property, both of which have as value an array consisting of a single element, and node has no other members apart from an optional @type member whose value is an array with a single item equal to rdf:List, node represents a well-formed list node. Continue with the following steps:
|
70
74
|
debug("list element?") {node.to_json(JSON_STATE)}
|
71
75
|
while property == RDF.rest.to_s &&
|
76
|
+
node_usages_map[node['@id']].uniq.length == 1 &&
|
72
77
|
blank_node?(node) &&
|
73
78
|
node.keys.none? {|k| !["@id", '@type', :usages, RDF.first.to_s, RDF.rest.to_s].include?(k)} &&
|
74
79
|
Array(node[:usages]).length == 1 &&
|
data/lib/json/ld/writer.rb
CHANGED
@@ -85,6 +85,8 @@ module JSON::LD
|
|
85
85
|
# Add standard prefixes to @prefixes, if necessary.
|
86
86
|
# @option options [IO, Array, Hash, String, Context] :context ({})
|
87
87
|
# context to use when serializing. Constructed context for native serialization.
|
88
|
+
# @option options [IO, Array, Hash, String, Context] :frame ({})
|
89
|
+
# frame to use when serializing.
|
88
90
|
# @option options [Boolean] :unique_bnodes (false)
|
89
91
|
# Use unique bnode identifiers, defaults to using the identifier which the node was originall initialized with (if any).
|
90
92
|
# @yield [writer] `self`
|
@@ -168,8 +170,13 @@ module JSON::LD
|
|
168
170
|
result = API.flatten(result, context, @options)
|
169
171
|
end
|
170
172
|
|
171
|
-
|
172
|
-
if
|
173
|
+
frame = RDF::Util::File.open_file(@options[:frame]) if @options[:frame].is_a?(String)
|
174
|
+
if frame ||= @options[:frame]
|
175
|
+
# Perform framing, if given a frame
|
176
|
+
debug("writer") { "frame result"}
|
177
|
+
result = API.frame(result, frame, @options)
|
178
|
+
elsif context
|
179
|
+
# Perform compaction, if we have a context
|
173
180
|
debug("writer") { "compact result"}
|
174
181
|
result = API.compact(result, context, @options)
|
175
182
|
end
|
data/spec/api_spec.rb
CHANGED
@@ -21,21 +21,21 @@ describe JSON::LD::API do
|
|
21
21
|
options = {:debug => @debug}
|
22
22
|
options[:expandContext] = File.open(context) if context
|
23
23
|
jld = JSON::LD::API.expand(File.open(filename), options)
|
24
|
-
jld.
|
24
|
+
expect(jld).to produce(JSON.load(File.open(expanded)), @debug)
|
25
25
|
end if File.exist?(expanded)
|
26
26
|
|
27
27
|
it "compacts" do
|
28
28
|
jld = JSON::LD::API.compact(File.open(filename), File.open(context), :debug => @debug)
|
29
|
-
jld.
|
29
|
+
expect(jld).to produce(JSON.load(File.open(compacted)), @debug)
|
30
30
|
end if File.exist?(compacted) && File.exist?(context)
|
31
31
|
|
32
32
|
it "frame" do
|
33
33
|
jld = JSON::LD::API.frame(File.open(filename), File.open(frame), :debug => @debug)
|
34
|
-
jld.
|
34
|
+
expect(jld).to produce(JSON.load(File.open(framed)), @debug)
|
35
35
|
end if File.exist?(framed) && File.exist?(frame)
|
36
36
|
|
37
37
|
it "toRdf" do
|
38
|
-
RDF::Repository.load(filename, :debug => @debug).
|
38
|
+
expect(RDF::Repository.load(filename, :debug => @debug)).to be_equivalent_graph(RDF::Repository.load(ttl), :trace => @debug)
|
39
39
|
end if File.exist?(ttl)
|
40
40
|
end
|
41
41
|
end
|
data/spec/compact_spec.rb
CHANGED
@@ -180,7 +180,7 @@ describe JSON::LD::API do
|
|
180
180
|
}.each_pair do |title, params|
|
181
181
|
it title do
|
182
182
|
jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
|
183
|
-
jld.
|
183
|
+
expect(jld).to produce(params[:output], @debug)
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
@@ -243,7 +243,7 @@ describe JSON::LD::API do
|
|
243
243
|
}.each do |title, params|
|
244
244
|
it title do
|
245
245
|
jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
|
246
|
-
jld.
|
246
|
+
expect(jld).to produce(params[:output], @debug)
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
@@ -306,7 +306,7 @@ describe JSON::LD::API do
|
|
306
306
|
ctx = params[:context].is_a?(String) ? JSON.parse(params[:context]) : params[:context]
|
307
307
|
output = params[:output].is_a?(String) ? JSON.parse(params[:output]) : params[:output]
|
308
308
|
jld = JSON::LD::API.compact(input, ctx, :debug => @debug)
|
309
|
-
jld.
|
309
|
+
expect(jld).to produce(output, @debug)
|
310
310
|
end
|
311
311
|
end
|
312
312
|
end
|
@@ -353,7 +353,7 @@ describe JSON::LD::API do
|
|
353
353
|
ctx = params[:context].is_a?(String) ? JSON.parse(params[:context]) : params[:context]
|
354
354
|
output = params[:output].is_a?(String) ? JSON.parse(params[:output]) : params[:output]
|
355
355
|
jld = JSON::LD::API.compact(input, ctx, :debug => @debug)
|
356
|
-
jld.
|
356
|
+
expect(jld).to produce(output, @debug)
|
357
357
|
end
|
358
358
|
end
|
359
359
|
end
|
@@ -373,7 +373,7 @@ describe JSON::LD::API do
|
|
373
373
|
"foo" => "bar"
|
374
374
|
}
|
375
375
|
jld = JSON::LD::API.compact(input, ctx, :debug => @debug, :validate => true)
|
376
|
-
jld.
|
376
|
+
expect(jld).to produce(expected, @debug)
|
377
377
|
end
|
378
378
|
end
|
379
379
|
|
@@ -389,9 +389,9 @@ describe JSON::LD::API do
|
|
389
389
|
"@context" => "http://example.com/context",
|
390
390
|
"b" => "c"
|
391
391
|
}
|
392
|
-
JSON::LD::API.
|
392
|
+
allow(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
393
393
|
jld = JSON::LD::API.compact(input, "http://example.com/context", :debug => @debug, :validate => true)
|
394
|
-
jld.
|
394
|
+
expect(jld).to produce(expected, @debug)
|
395
395
|
end
|
396
396
|
end
|
397
397
|
|
@@ -420,7 +420,7 @@ describe JSON::LD::API do
|
|
420
420
|
}.each_pair do |title, params|
|
421
421
|
it title do
|
422
422
|
jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
|
423
|
-
jld.
|
423
|
+
expect(jld).to produce(params[:output], @debug)
|
424
424
|
end
|
425
425
|
end
|
426
426
|
end
|
@@ -457,7 +457,7 @@ describe JSON::LD::API do
|
|
457
457
|
}.each_pair do |title, params|
|
458
458
|
it title do
|
459
459
|
jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
|
460
|
-
jld.
|
460
|
+
expect(jld).to produce(params[:output], @debug)
|
461
461
|
end
|
462
462
|
end
|
463
463
|
end
|
@@ -481,7 +481,7 @@ describe JSON::LD::API do
|
|
481
481
|
}.each_pair do |title, params|
|
482
482
|
it title do
|
483
483
|
jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
|
484
|
-
jld.
|
484
|
+
expect(jld).to produce(params[:output], @debug)
|
485
485
|
end
|
486
486
|
end
|
487
487
|
end
|
@@ -503,7 +503,7 @@ describe JSON::LD::API do
|
|
503
503
|
},
|
504
504
|
}.each do |title, params|
|
505
505
|
it title do
|
506
|
-
|
506
|
+
expect {JSON::LD::API.compact(params[:input], {})}.to raise_error(params[:exception])
|
507
507
|
end
|
508
508
|
end
|
509
509
|
end
|
data/spec/context_spec.rb
CHANGED
@@ -43,20 +43,20 @@ describe JSON::LD::Context do
|
|
43
43
|
context "remote" do
|
44
44
|
|
45
45
|
it "retrieves and parses a remote context document" do
|
46
|
-
JSON::LD::API.
|
46
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
47
47
|
ec = subject.parse("http://example.com/context")
|
48
|
-
ec.provided_context.
|
48
|
+
expect(ec.provided_context).to produce("http://example.com/context", @debug)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "fails given a missing remote @context" do
|
52
|
-
JSON::LD::API.
|
53
|
-
|
52
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_raise(IOError)
|
53
|
+
expect {subject.parse("http://example.com/context")}.to raise_error(JSON::LD::JsonLdError::LoadingRemoteContextFailed, %r{http://example.com/context})
|
54
54
|
end
|
55
55
|
|
56
56
|
it "creates mappings" do
|
57
|
-
JSON::LD::API.
|
57
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
58
58
|
ec = subject.parse("http://example.com/context")
|
59
|
-
ec.mappings.
|
59
|
+
expect(ec.send(:mappings)).to produce({
|
60
60
|
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
61
61
|
"name" => "http://xmlns.com/foaf/0.1/name",
|
62
62
|
"homepage" => "http://xmlns.com/foaf/0.1/homepage",
|
@@ -65,15 +65,15 @@ describe JSON::LD::Context do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "notes non-existing @context" do
|
68
|
-
|
68
|
+
expect {subject.parse(StringIO.new("{}"))}.to raise_error
|
69
69
|
end
|
70
70
|
|
71
71
|
it "parses a referenced context at a relative URI" do
|
72
72
|
rd1 = JSON::LD::API::RemoteDocument.new("http://example.com/c1", %({"@context": "context"}))
|
73
|
-
JSON::LD::API.
|
74
|
-
JSON::LD::API.
|
73
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/c1").and_yield(rd1)
|
74
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
75
75
|
ec = subject.parse("http://example.com/c1")
|
76
|
-
ec.mappings.
|
76
|
+
expect(ec.send(:mappings)).to produce({
|
77
77
|
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
78
78
|
"name" => "http://xmlns.com/foaf/0.1/name",
|
79
79
|
"homepage" => "http://xmlns.com/foaf/0.1/homepage",
|
@@ -92,7 +92,7 @@ describe JSON::LD::Context do
|
|
92
92
|
|
93
93
|
it "merges definitions from each context" do
|
94
94
|
ec = subject.parse(@ctx)
|
95
|
-
ec.mappings.
|
95
|
+
expect(ec.send(:mappings)).to produce({
|
96
96
|
"foo" => "http://example.com/foo",
|
97
97
|
"bar" => "http://example.com/foo"
|
98
98
|
}, @debug)
|
@@ -101,79 +101,79 @@ describe JSON::LD::Context do
|
|
101
101
|
|
102
102
|
context "Hash" do
|
103
103
|
it "extracts @language" do
|
104
|
-
subject.parse({
|
104
|
+
expect(subject.parse({
|
105
105
|
"@language" => "en"
|
106
|
-
}).default_language.
|
106
|
+
}).default_language).to produce("en", @debug)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "extracts @vocab" do
|
110
|
-
subject.parse({
|
110
|
+
expect(subject.parse({
|
111
111
|
"@vocab" => "http://schema.org/"
|
112
|
-
}).vocab.
|
112
|
+
}).vocab).to produce("http://schema.org/", @debug)
|
113
113
|
end
|
114
114
|
|
115
115
|
it "maps term with IRI value" do
|
116
|
-
subject.parse({
|
116
|
+
expect(subject.parse({
|
117
117
|
"foo" => "http://example.com/"
|
118
|
-
}).mappings.
|
118
|
+
}).send(:mappings)).to produce({
|
119
119
|
"foo" => "http://example.com/"
|
120
120
|
}, @debug)
|
121
121
|
end
|
122
122
|
|
123
123
|
it "maps term with @id" do
|
124
|
-
subject.parse({
|
124
|
+
expect(subject.parse({
|
125
125
|
"foo" => {"@id" => "http://example.com/"}
|
126
|
-
}).mappings.
|
126
|
+
}).send(:mappings)).to produce({
|
127
127
|
"foo" => "http://example.com/"
|
128
128
|
}, @debug)
|
129
129
|
end
|
130
130
|
|
131
131
|
it "associates @list container mapping with predicate" do
|
132
|
-
subject.parse({
|
132
|
+
expect(subject.parse({
|
133
133
|
"foo" => {"@id" => "http://example.com/", "@container" => "@list"}
|
134
|
-
}).containers.
|
134
|
+
}).containers).to produce({
|
135
135
|
"foo" => '@list'
|
136
136
|
}, @debug)
|
137
137
|
end
|
138
138
|
|
139
139
|
it "associates @set container mapping with predicate" do
|
140
|
-
subject.parse({
|
140
|
+
expect(subject.parse({
|
141
141
|
"foo" => {"@id" => "http://example.com/", "@container" => "@set"}
|
142
|
-
}).containers.
|
142
|
+
}).containers).to produce({
|
143
143
|
"foo" => '@set'
|
144
144
|
}, @debug)
|
145
145
|
end
|
146
146
|
|
147
147
|
it "associates @id container mapping with predicate" do
|
148
|
-
subject.parse({
|
148
|
+
expect(subject.parse({
|
149
149
|
"foo" => {"@id" => "http://example.com/", "@type" => "@id"}
|
150
|
-
}).coercions.
|
150
|
+
}).coercions).to produce({
|
151
151
|
"foo" => "@id"
|
152
152
|
}, @debug)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "associates type mapping with predicate" do
|
156
|
-
subject.parse({
|
156
|
+
expect(subject.parse({
|
157
157
|
"foo" => {"@id" => "http://example.com/", "@type" => RDF::XSD.string.to_s}
|
158
|
-
}).coercions.
|
159
|
-
"foo" => RDF::XSD.string
|
158
|
+
}).coercions).to produce({
|
159
|
+
"foo" => RDF::XSD.string
|
160
160
|
}, @debug)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "associates language mapping with predicate" do
|
164
|
-
subject.parse({
|
164
|
+
expect(subject.parse({
|
165
165
|
"foo" => {"@id" => "http://example.com/", "@language" => "en"}
|
166
|
-
}).languages.
|
166
|
+
}).send(:languages)).to produce({
|
167
167
|
"foo" => "en"
|
168
168
|
}, @debug)
|
169
169
|
end
|
170
170
|
|
171
171
|
it "expands chains of term definition/use with string values" do
|
172
|
-
subject.parse({
|
172
|
+
expect(subject.parse({
|
173
173
|
"foo" => "bar",
|
174
174
|
"bar" => "baz",
|
175
175
|
"baz" => "http://example.com/"
|
176
|
-
}).mappings.
|
176
|
+
}).send(:mappings)).to produce({
|
177
177
|
"foo" => "http://example.com/",
|
178
178
|
"bar" => "http://example.com/",
|
179
179
|
"baz" => "http://example.com/"
|
@@ -181,58 +181,58 @@ describe JSON::LD::Context do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it "expands terms using @vocab" do
|
184
|
-
subject.parse({
|
184
|
+
expect(subject.parse({
|
185
185
|
"foo" => "bar",
|
186
186
|
"@vocab" => "http://example.com/"
|
187
|
-
}).mappings.
|
187
|
+
}).send(:mappings)).to produce({
|
188
188
|
"foo" => "http://example.com/bar"
|
189
189
|
}, @debug)
|
190
190
|
end
|
191
191
|
|
192
192
|
context "with null" do
|
193
193
|
it "removes @language if set to null" do
|
194
|
-
subject.parse([
|
194
|
+
expect(subject.parse([
|
195
195
|
{
|
196
196
|
"@language" => "en"
|
197
197
|
},
|
198
198
|
{
|
199
199
|
"@language" => nil
|
200
200
|
}
|
201
|
-
]).default_language.
|
201
|
+
]).default_language).to produce(nil, @debug)
|
202
202
|
end
|
203
203
|
|
204
204
|
it "removes @vocab if set to null" do
|
205
|
-
subject.parse([
|
205
|
+
expect(subject.parse([
|
206
206
|
{
|
207
207
|
"@vocab" => "http://schema.org/"
|
208
208
|
},
|
209
209
|
{
|
210
210
|
"@vocab" => nil
|
211
211
|
}
|
212
|
-
]).vocab.
|
212
|
+
]).vocab).to produce(nil, @debug)
|
213
213
|
end
|
214
214
|
|
215
215
|
it "removes term if set to null with @vocab" do
|
216
|
-
subject.parse([
|
216
|
+
expect(subject.parse([
|
217
217
|
{
|
218
218
|
"@vocab" => "http://schema.org/",
|
219
219
|
"term" => nil
|
220
220
|
}
|
221
|
-
]).mappings.
|
221
|
+
]).send(:mappings)).to produce({"term" => nil}, @debug)
|
222
222
|
end
|
223
223
|
|
224
224
|
it "loads initial context" do
|
225
225
|
init_ec = JSON::LD::Context.new
|
226
226
|
nil_ec = subject.parse(nil)
|
227
|
-
nil_ec.default_language.
|
228
|
-
nil_ec.languages.
|
229
|
-
nil_ec.mappings.
|
230
|
-
nil_ec.coercions.
|
231
|
-
nil_ec.containers.
|
227
|
+
expect(nil_ec.default_language).to eq init_ec.default_language
|
228
|
+
expect(nil_ec.send(:languages)).to eq init_ec.send(:languages)
|
229
|
+
expect(nil_ec.send(:mappings)).to eq init_ec.send(:mappings)
|
230
|
+
expect(nil_ec.coercions).to eq init_ec.coercions
|
231
|
+
expect(nil_ec.containers).to eq init_ec.containers
|
232
232
|
end
|
233
233
|
|
234
234
|
it "removes a term definition" do
|
235
|
-
subject.parse({"name" => nil}).mapping
|
235
|
+
expect(subject.parse({"name" => nil}).send(:mapping, "name")).to be_nil
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -256,26 +256,26 @@ describe JSON::LD::Context do
|
|
256
256
|
"@vocab as @id" => {"@vocab" => {"@id" => "http://example.com/"}},
|
257
257
|
}.each do |title, context|
|
258
258
|
it title do
|
259
|
-
|
259
|
+
expect {
|
260
260
|
ec = subject.parse(context)
|
261
|
-
ec.serialize.
|
262
|
-
}.
|
261
|
+
expect(ec.serialize).to produce({}, @debug)
|
262
|
+
}.to raise_error(JSON::LD::JsonLdError)
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
266
|
(JSON::LD::KEYWORDS - %w(@base @language @vocab)).each do |kw|
|
267
267
|
it "does not redefine #{kw} as a string" do
|
268
|
-
|
268
|
+
expect {
|
269
269
|
ec = subject.parse({kw => "http://example.com/"})
|
270
|
-
ec.serialize.
|
271
|
-
}.
|
270
|
+
expect(ec.serialize).to produce({}, @debug)
|
271
|
+
}.to raise_error(JSON::LD::JsonLdError)
|
272
272
|
end
|
273
273
|
|
274
274
|
it "does not redefine #{kw} with an @id" do
|
275
|
-
|
275
|
+
expect {
|
276
276
|
ec = subject.parse({kw => {"@id" => "http://example.com/"}})
|
277
|
-
ec.serialize.
|
278
|
-
}.
|
277
|
+
expect(ec.serialize).to produce({}, @debug)
|
278
|
+
}.to raise_error(JSON::LD::JsonLdError)
|
279
279
|
end
|
280
280
|
end
|
281
281
|
end
|
@@ -283,9 +283,9 @@ describe JSON::LD::Context do
|
|
283
283
|
|
284
284
|
describe "#serialize" do
|
285
285
|
it "context document" do
|
286
|
-
JSON::LD::API.
|
286
|
+
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context").and_yield(remote_doc)
|
287
287
|
ec = subject.parse("http://example.com/context")
|
288
|
-
ec.serialize.
|
288
|
+
expect(ec.serialize).to produce({
|
289
289
|
"@context" => "http://example.com/context"
|
290
290
|
}, @debug)
|
291
291
|
end
|
@@ -294,14 +294,14 @@ describe JSON::LD::Context do
|
|
294
294
|
ctx = {"foo" => "http://example.com/"}
|
295
295
|
|
296
296
|
ec = subject.parse(ctx)
|
297
|
-
ec.serialize.
|
297
|
+
expect(ec.serialize).to produce({
|
298
298
|
"@context" => ctx
|
299
299
|
}, @debug)
|
300
300
|
end
|
301
301
|
|
302
302
|
it "@language" do
|
303
303
|
subject.default_language = "en"
|
304
|
-
subject.serialize.
|
304
|
+
expect(subject.serialize).to produce({
|
305
305
|
"@context" => {
|
306
306
|
"@language" => "en"
|
307
307
|
}
|
@@ -310,7 +310,7 @@ describe JSON::LD::Context do
|
|
310
310
|
|
311
311
|
it "@vocab" do
|
312
312
|
subject.vocab = "http://example.com/"
|
313
|
-
subject.serialize.
|
313
|
+
expect(subject.serialize).to produce({
|
314
314
|
"@context" => {
|
315
315
|
"@vocab" => "http://example.com/"
|
316
316
|
}
|
@@ -318,9 +318,9 @@ describe JSON::LD::Context do
|
|
318
318
|
end
|
319
319
|
|
320
320
|
it "term mappings" do
|
321
|
-
subject.
|
321
|
+
expect(subject.
|
322
322
|
parse({'foo' => "http://example.com/"}).send(:clear_provided_context).
|
323
|
-
serialize.
|
323
|
+
serialize).to produce({
|
324
324
|
"@context" => {
|
325
325
|
"foo" => "http://example.com/"
|
326
326
|
}
|
@@ -328,25 +328,25 @@ describe JSON::LD::Context do
|
|
328
328
|
end
|
329
329
|
|
330
330
|
it "@type with dependent prefixes in a single context" do
|
331
|
-
subject.parse({
|
331
|
+
expect(subject.parse({
|
332
332
|
'xsd' => "http://www.w3.org/2001/XMLSchema#",
|
333
333
|
'homepage' => {'@id' => RDF::FOAF.homepage.to_s, '@type' => '@id'}
|
334
334
|
}).
|
335
335
|
send(:clear_provided_context).
|
336
|
-
serialize.
|
336
|
+
serialize).to produce({
|
337
337
|
"@context" => {
|
338
|
-
"xsd" => RDF::XSD.to_uri,
|
338
|
+
"xsd" => RDF::XSD.to_uri.to_s,
|
339
339
|
"homepage" => {"@id" => RDF::FOAF.homepage.to_s, "@type" => "@id"}
|
340
340
|
}
|
341
341
|
}, @debug)
|
342
342
|
end
|
343
343
|
|
344
344
|
it "@list with @id definition in a single context" do
|
345
|
-
subject.parse({
|
345
|
+
expect(subject.parse({
|
346
346
|
'knows' => {'@id' => RDF::FOAF.knows.to_s, '@container' => '@list'}
|
347
347
|
}).
|
348
348
|
send(:clear_provided_context).
|
349
|
-
serialize.
|
349
|
+
serialize).to produce({
|
350
350
|
"@context" => {
|
351
351
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
|
352
352
|
}
|
@@ -354,11 +354,11 @@ describe JSON::LD::Context do
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it "@set with @id definition in a single context" do
|
357
|
-
subject.parse({
|
357
|
+
expect(subject.parse({
|
358
358
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
|
359
359
|
}).
|
360
360
|
send(:clear_provided_context).
|
361
|
-
serialize.
|
361
|
+
serialize).to produce({
|
362
362
|
"@context" => {
|
363
363
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
|
364
364
|
}
|
@@ -366,11 +366,11 @@ describe JSON::LD::Context do
|
|
366
366
|
end
|
367
367
|
|
368
368
|
it "@language with @id definition in a single context" do
|
369
|
-
subject.parse({
|
369
|
+
expect(subject.parse({
|
370
370
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
|
371
371
|
}).
|
372
372
|
send(:clear_provided_context).
|
373
|
-
serialize.
|
373
|
+
serialize).to produce({
|
374
374
|
"@context" => {
|
375
375
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
|
376
376
|
}
|
@@ -378,12 +378,12 @@ describe JSON::LD::Context do
|
|
378
378
|
end
|
379
379
|
|
380
380
|
it "@language with @id definition in a single context and equivalent default" do
|
381
|
-
subject.parse({
|
381
|
+
expect(subject.parse({
|
382
382
|
"@language" => 'en',
|
383
383
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
|
384
384
|
}).
|
385
385
|
send(:clear_provided_context).
|
386
|
-
serialize.
|
386
|
+
serialize).to produce({
|
387
387
|
"@context" => {
|
388
388
|
"@language" => 'en',
|
389
389
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
|
@@ -392,12 +392,12 @@ describe JSON::LD::Context do
|
|
392
392
|
end
|
393
393
|
|
394
394
|
it "@language with @id definition in a single context and different default" do
|
395
|
-
subject.parse({
|
395
|
+
expect(subject.parse({
|
396
396
|
"@language" => 'en',
|
397
397
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
|
398
398
|
}).
|
399
399
|
send(:clear_provided_context).
|
400
|
-
serialize.
|
400
|
+
serialize).to produce({
|
401
401
|
"@context" => {
|
402
402
|
"@language" => 'en',
|
403
403
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
|
@@ -406,12 +406,12 @@ describe JSON::LD::Context do
|
|
406
406
|
end
|
407
407
|
|
408
408
|
it "null @language with @id definition in a single context and default" do
|
409
|
-
subject.parse({
|
409
|
+
expect(subject.parse({
|
410
410
|
"@language" => 'en',
|
411
411
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
|
412
412
|
}).
|
413
413
|
send(:clear_provided_context).
|
414
|
-
serialize.
|
414
|
+
serialize).to produce({
|
415
415
|
"@context" => {
|
416
416
|
"@language" => 'en',
|
417
417
|
"name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
|
@@ -420,11 +420,11 @@ describe JSON::LD::Context do
|
|
420
420
|
end
|
421
421
|
|
422
422
|
it "prefix with @type and @list" do
|
423
|
-
subject.parse({
|
423
|
+
expect(subject.parse({
|
424
424
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
425
425
|
}).
|
426
426
|
send(:clear_provided_context).
|
427
|
-
serialize.
|
427
|
+
serialize).to produce({
|
428
428
|
"@context" => {
|
429
429
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
430
430
|
}
|
@@ -432,11 +432,11 @@ describe JSON::LD::Context do
|
|
432
432
|
end
|
433
433
|
|
434
434
|
it "prefix with @type and @set" do
|
435
|
-
subject.parse({
|
435
|
+
expect(subject.parse({
|
436
436
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
437
437
|
}).
|
438
438
|
send(:clear_provided_context).
|
439
|
-
serialize.
|
439
|
+
serialize).to produce({
|
440
440
|
"@context" => {
|
441
441
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
442
442
|
}
|
@@ -444,15 +444,14 @@ describe JSON::LD::Context do
|
|
444
444
|
end
|
445
445
|
|
446
446
|
it "CURIE with @type" do
|
447
|
-
subject.parse({
|
447
|
+
expect(subject.parse({
|
448
448
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
449
449
|
"foaf:knows" => {
|
450
|
-
"@id" => RDF::FOAF.knows.to_s,
|
451
450
|
"@container" => "@list"
|
452
451
|
}
|
453
452
|
}).
|
454
453
|
send(:clear_provided_context).
|
455
|
-
serialize.
|
454
|
+
serialize).to produce({
|
456
455
|
"@context" => {
|
457
456
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
458
457
|
"foaf:knows" => {
|
@@ -463,12 +462,12 @@ describe JSON::LD::Context do
|
|
463
462
|
end
|
464
463
|
|
465
464
|
it "does not use aliased @id in key position" do
|
466
|
-
subject.parse({
|
465
|
+
expect(subject.parse({
|
467
466
|
"id" => "@id",
|
468
467
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
|
469
468
|
}).
|
470
469
|
send(:clear_provided_context).
|
471
|
-
serialize.
|
470
|
+
serialize).to produce({
|
472
471
|
"@context" => {
|
473
472
|
"id" => "@id",
|
474
473
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
|
@@ -477,16 +476,15 @@ describe JSON::LD::Context do
|
|
477
476
|
end
|
478
477
|
|
479
478
|
it "does not use aliased @id in value position" do
|
480
|
-
subject.parse({
|
479
|
+
expect(subject.parse({
|
481
480
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
482
481
|
"id" => "@id",
|
483
482
|
"foaf:homepage" => {
|
484
|
-
"@id" => RDF::FOAF.homepage.to_s,
|
485
483
|
"@type" => "@id"
|
486
484
|
}
|
487
485
|
}).
|
488
486
|
send(:clear_provided_context).
|
489
|
-
serialize.
|
487
|
+
serialize).to produce({
|
490
488
|
"@context" => {
|
491
489
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
492
490
|
"id" => "@id",
|
@@ -498,13 +496,13 @@ describe JSON::LD::Context do
|
|
498
496
|
end
|
499
497
|
|
500
498
|
it "does not use aliased @type" do
|
501
|
-
subject.parse({
|
499
|
+
expect(subject.parse({
|
502
500
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
503
501
|
"type" => "@type",
|
504
502
|
"foaf:homepage" => {"@type" => "@id"}
|
505
503
|
}).
|
506
504
|
send(:clear_provided_context).
|
507
|
-
serialize.
|
505
|
+
serialize).to produce({
|
508
506
|
"@context" => {
|
509
507
|
"foaf" => RDF::FOAF.to_uri.to_s,
|
510
508
|
"type" => "@type",
|
@@ -514,12 +512,12 @@ describe JSON::LD::Context do
|
|
514
512
|
end
|
515
513
|
|
516
514
|
it "does not use aliased @container" do
|
517
|
-
subject.parse({
|
515
|
+
expect(subject.parse({
|
518
516
|
"container" => "@container",
|
519
517
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
|
520
518
|
}).
|
521
519
|
send(:clear_provided_context).
|
522
|
-
serialize.
|
520
|
+
serialize).to produce({
|
523
521
|
"@context" => {
|
524
522
|
"container" => "@container",
|
525
523
|
"knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
|
@@ -528,12 +526,12 @@ describe JSON::LD::Context do
|
|
528
526
|
end
|
529
527
|
|
530
528
|
it "compacts IRIs to CURIEs" do
|
531
|
-
subject.parse({
|
529
|
+
expect(subject.parse({
|
532
530
|
"ex" => 'http://example.org/',
|
533
531
|
"term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
|
534
532
|
}).
|
535
533
|
send(:clear_provided_context).
|
536
|
-
serialize.
|
534
|
+
serialize).to produce({
|
537
535
|
"@context" => {
|
538
536
|
"ex" => 'http://example.org/',
|
539
537
|
"term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
|
@@ -542,15 +540,15 @@ describe JSON::LD::Context do
|
|
542
540
|
end
|
543
541
|
|
544
542
|
it "compacts IRIs using @vocab" do
|
545
|
-
subject.parse({
|
543
|
+
expect(subject.parse({
|
546
544
|
"@vocab" => 'http://example.org/',
|
547
545
|
"term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
|
548
546
|
}).
|
549
547
|
send(:clear_provided_context).
|
550
|
-
serialize.
|
548
|
+
serialize).to produce({
|
551
549
|
"@context" => {
|
552
550
|
"@vocab" => 'http://example.org/',
|
553
|
-
"term" => {"@
|
551
|
+
"term" => {"@type" => "datatype"}
|
554
552
|
}
|
555
553
|
}, @debug)
|
556
554
|
end
|
@@ -564,7 +562,7 @@ describe JSON::LD::Context do
|
|
564
562
|
}.each do |title, params|
|
565
563
|
it title do
|
566
564
|
ec = subject.parse(params[:input])
|
567
|
-
ec.serialize.
|
565
|
+
expect(ec.serialize).to produce(params[:result], @debug)
|
568
566
|
end
|
569
567
|
end
|
570
568
|
end
|
@@ -583,14 +581,14 @@ describe JSON::LD::Context do
|
|
583
581
|
}
|
584
582
|
|
585
583
|
it "bnode" do
|
586
|
-
subject.expand_iri("_:a").
|
584
|
+
expect(subject.expand_iri("_:a")).to be_a(RDF::Node)
|
587
585
|
end
|
588
586
|
|
589
587
|
context "keywords" do
|
590
588
|
%w(id type).each do |kw|
|
591
589
|
it "expands #{kw} to @#{kw}" do
|
592
590
|
subject.set_mapping(kw, "@#{kw}")
|
593
|
-
subject.expand_iri(kw, :vocab => true).
|
591
|
+
expect(subject.expand_iri(kw, :vocab => true)).to produce("@#{kw}", @debug)
|
594
592
|
end
|
595
593
|
end
|
596
594
|
end
|
@@ -612,7 +610,7 @@ describe JSON::LD::Context do
|
|
612
610
|
"_" => ["_", RDF::URI("_")],
|
613
611
|
}.each do |title, (input, result)|
|
614
612
|
it title do
|
615
|
-
subject.expand_iri(input).
|
613
|
+
expect(subject.expand_iri(input)).to produce(result, @debug)
|
616
614
|
end
|
617
615
|
end
|
618
616
|
end
|
@@ -633,7 +631,7 @@ describe JSON::LD::Context do
|
|
633
631
|
"_" => ["_", RDF::URI("http://base/_")],
|
634
632
|
}.each do |title, (input, result)|
|
635
633
|
it title do
|
636
|
-
subject.expand_iri(input, :documentRelative => true).
|
634
|
+
expect(subject.expand_iri(input, :documentRelative => true)).to produce(result, @debug)
|
637
635
|
end
|
638
636
|
end
|
639
637
|
end
|
@@ -654,7 +652,7 @@ describe JSON::LD::Context do
|
|
654
652
|
"_" => ["_", RDF::URI("http://underscore/")],
|
655
653
|
}.each do |title, (input, result)|
|
656
654
|
it title do
|
657
|
-
subject.expand_iri(input, :vocab => true).
|
655
|
+
expect(subject.expand_iri(input, :vocab => true)).to produce(result, @debug)
|
658
656
|
end
|
659
657
|
end
|
660
658
|
end
|
@@ -664,14 +662,16 @@ describe JSON::LD::Context do
|
|
664
662
|
describe "#compact_iri" do
|
665
663
|
subject {
|
666
664
|
c = context.parse({
|
667
|
-
'@base'
|
668
|
-
"xsd"
|
669
|
-
'ex'
|
670
|
-
''
|
671
|
-
'_'
|
672
|
-
'rex'
|
673
|
-
'lex'
|
674
|
-
'tex'
|
665
|
+
'@base' => 'http://base/',
|
666
|
+
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
667
|
+
'ex' => 'http://example.org/',
|
668
|
+
'' => 'http://empty/',
|
669
|
+
'_' => 'http://underscore/',
|
670
|
+
'rex' => {'@reverse' => "ex"},
|
671
|
+
'lex' => {'@id' => 'ex', '@language' => 'en'},
|
672
|
+
'tex' => {'@id' => 'ex', '@type' => 'xsd:string'},
|
673
|
+
'exp' => {'@id' => 'ex:pert'},
|
674
|
+
'experts' => {'@id' => 'ex:perts'}
|
675
675
|
})
|
676
676
|
@debug.clear
|
677
677
|
c
|
@@ -685,10 +685,11 @@ describe JSON::LD::Context do
|
|
685
685
|
"empty" => [":suffix", "http://empty/suffix"],
|
686
686
|
"unmapped" => ["foo", "foo"],
|
687
687
|
"bnode" => ["_:a", RDF::Node("a")],
|
688
|
-
"relative" => ["foo/bar", "http://base/foo/bar"]
|
688
|
+
"relative" => ["foo/bar", "http://base/foo/bar"],
|
689
|
+
"odd CURIE" => ["exp:s", "http://example.org/perts"]
|
689
690
|
}.each do |title, (result, input)|
|
690
691
|
it title do
|
691
|
-
subject.compact_iri(input).
|
692
|
+
expect(subject.compact_iri(input)).to produce(result, @debug)
|
692
693
|
end
|
693
694
|
end
|
694
695
|
|
@@ -700,10 +701,11 @@ describe JSON::LD::Context do
|
|
700
701
|
"empty" => [":suffix", "http://empty/suffix"],
|
701
702
|
"unmapped" => ["foo", "foo"],
|
702
703
|
"bnode" => ["_:a", RDF::Node("a")],
|
703
|
-
"relative" => ["http://base/foo/bar", "http://base/foo/bar"]
|
704
|
+
"relative" => ["http://base/foo/bar", "http://base/foo/bar"],
|
705
|
+
"odd CURIE" => ["experts", "http://example.org/perts"]
|
704
706
|
}.each do |title, (result, input)|
|
705
707
|
it title do
|
706
|
-
subject.compact_iri(input, :vocab => true).
|
708
|
+
expect(subject.compact_iri(input, :vocab => true)).to produce(result, @debug)
|
707
709
|
end
|
708
710
|
end
|
709
711
|
end
|
@@ -718,18 +720,19 @@ describe JSON::LD::Context do
|
|
718
720
|
"empty" => [":suffix", "http://empty/suffix"],
|
719
721
|
"unmapped" => ["foo", "foo"],
|
720
722
|
"bnode" => ["_:a", RDF::Node("a")],
|
721
|
-
"relative" => ["http://base/foo/bar", "http://base/foo/bar"]
|
723
|
+
"relative" => ["http://base/foo/bar", "http://base/foo/bar"],
|
724
|
+
"odd CURIE" => ["experts", "http://example.org/perts"]
|
722
725
|
}.each do |title, (result, input)|
|
723
726
|
it title do
|
724
|
-
subject.compact_iri(input, :vocab => true).
|
727
|
+
expect(subject.compact_iri(input, :vocab => true)).to produce(result, @debug)
|
725
728
|
end
|
726
729
|
end
|
727
730
|
|
728
731
|
it "does not use @vocab if it would collide with a term" do
|
729
732
|
subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
|
730
733
|
subject.set_mapping("ex", nil)
|
731
|
-
subject.compact_iri("http://example.org/name", :position => :predicate).
|
732
|
-
|
734
|
+
expect(subject.compact_iri("http://example.org/name", :position => :predicate)).
|
735
|
+
to produce("lex:name", @debug)
|
733
736
|
end
|
734
737
|
end
|
735
738
|
|
@@ -772,7 +775,8 @@ describe JSON::LD::Context do
|
|
772
775
|
context "uses #{prop}" do
|
773
776
|
values.each do |value|
|
774
777
|
it "for #{value.inspect}" do
|
775
|
-
ctx.compact_iri("http://example.com/#{prop.sub('set', '')}", :value => value, :vocab => true).
|
778
|
+
expect(ctx.compact_iri("http://example.com/#{prop.sub('set', '')}", :value => value, :vocab => true)).
|
779
|
+
to produce(prop, @debug)
|
776
780
|
end
|
777
781
|
end
|
778
782
|
end
|
@@ -800,7 +804,8 @@ describe JSON::LD::Context do
|
|
800
804
|
context "uses #{prop}" do
|
801
805
|
values.each do |value|
|
802
806
|
it "for #{{"@list" => value}.inspect}" do
|
803
|
-
ctx.compact_iri("http://example.com/#{prop.sub('list', '')}", :value => {"@list" => value}, :vocab => true).
|
807
|
+
expect(ctx.compact_iri("http://example.com/#{prop.sub('list', '')}", :value => {"@list" => value}, :vocab => true)).
|
808
|
+
to produce(prop, @debug)
|
804
809
|
end
|
805
810
|
end
|
806
811
|
end
|
@@ -808,6 +813,46 @@ describe JSON::LD::Context do
|
|
808
813
|
end
|
809
814
|
end
|
810
815
|
|
816
|
+
context "with :simple_compact_iris" do
|
817
|
+
before(:each) { subject.instance_variable_get(:@options)[:simple_compact_iris] = true}
|
818
|
+
|
819
|
+
{
|
820
|
+
"nil" => [nil, nil],
|
821
|
+
"absolute IRI" => ["http://example.com/", "http://example.com/"],
|
822
|
+
"prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
|
823
|
+
"keyword" => ["@type", "@type"],
|
824
|
+
"empty" => [":suffix", "http://empty/suffix"],
|
825
|
+
"unmapped" => ["foo", "foo"],
|
826
|
+
"bnode" => ["_:a", RDF::Node("a")],
|
827
|
+
"relative" => ["foo/bar", "http://base/foo/bar"],
|
828
|
+
"odd CURIE" => ["exp:s", "http://example.org/perts"],
|
829
|
+
"odd CURIE" => ["ex:perts", "http://example.org/perts"]
|
830
|
+
}.each do |title, (result, input)|
|
831
|
+
it title do
|
832
|
+
expect(subject.compact_iri(input)).to produce(result, @debug)
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
context "and @vocab" do
|
837
|
+
before(:each) { subject.vocab = "http://example.org/"}
|
838
|
+
|
839
|
+
{
|
840
|
+
"absolute IRI" => ["http://example.com/", "http://example.com/"],
|
841
|
+
"prefix:suffix" => ["suffix", "http://example.org/suffix"],
|
842
|
+
"keyword" => ["@type", "@type"],
|
843
|
+
"empty" => [":suffix", "http://empty/suffix"],
|
844
|
+
"unmapped" => ["foo", "foo"],
|
845
|
+
"bnode" => ["_:a", RDF::Node("a")],
|
846
|
+
"relative" => ["http://base/foo/bar", "http://base/foo/bar"],
|
847
|
+
"odd CURIE" => ["experts", "http://example.org/perts"]
|
848
|
+
}.each do |title, (result, input)|
|
849
|
+
it title do
|
850
|
+
expect(subject.compact_iri(input, :vocab => true)).to produce(result, @debug)
|
851
|
+
end
|
852
|
+
end
|
853
|
+
end
|
854
|
+
end
|
855
|
+
|
811
856
|
context "compact-0018" do
|
812
857
|
let(:ctx) do
|
813
858
|
subject.parse(JSON.parse %({
|
@@ -907,8 +952,8 @@ describe JSON::LD::Context do
|
|
907
952
|
}.each do |term, value|
|
908
953
|
[value].flatten.each do |v|
|
909
954
|
it "Uses #{term} for #{v}" do
|
910
|
-
ctx.compact_iri("http://example.com/term", :value => JSON.parse(v), :vocab => true).
|
911
|
-
|
955
|
+
expect(ctx.compact_iri("http://example.com/term", :value => JSON.parse(v), :vocab => true)).
|
956
|
+
to produce(term, @debug)
|
912
957
|
end
|
913
958
|
end
|
914
959
|
end
|
@@ -922,8 +967,8 @@ describe JSON::LD::Context do
|
|
922
967
|
})
|
923
968
|
end
|
924
969
|
it "Compact @id that is a property IRI when @container is @list" do
|
925
|
-
ctx.compact_iri("http://example.org/ns#property", :position => :subject).
|
926
|
-
|
970
|
+
expect(ctx.compact_iri("http://example.org/ns#property", :position => :subject)).
|
971
|
+
to produce("ex:property", @debug)
|
927
972
|
end
|
928
973
|
end
|
929
974
|
|
@@ -932,10 +977,10 @@ describe JSON::LD::Context do
|
|
932
977
|
subject.parse({"name" => {"@id" => "http://example.com/property", "@container" => "@list"}})
|
933
978
|
end
|
934
979
|
it "Does not use @list with @index" do
|
935
|
-
ctx.compact_iri("http://example.com/property", :value => {
|
980
|
+
expect(ctx.compact_iri("http://example.com/property", :value => {
|
936
981
|
"@list" => ["one item"],
|
937
982
|
"@index" => "an annotation"
|
938
|
-
}).
|
983
|
+
})).to produce("http://example.com/property", @debug)
|
939
984
|
end
|
940
985
|
end
|
941
986
|
end
|
@@ -960,7 +1005,7 @@ describe JSON::LD::Context do
|
|
960
1005
|
|
961
1006
|
%w(boolean integer string dateTime date time).each do |dt|
|
962
1007
|
it "expands datatype xsd:#{dt}" do
|
963
|
-
subject.expand_value("foo", RDF::XSD[dt]).
|
1008
|
+
expect(subject.expand_value("foo", RDF::XSD[dt])).to produce({"@id" => "http://www.w3.org/2001/XMLSchema##{dt}"}, @debug)
|
964
1009
|
end
|
965
1010
|
end
|
966
1011
|
|
@@ -989,7 +1034,7 @@ describe JSON::LD::Context do
|
|
989
1034
|
"rdf float" => ["foo", RDF::Literal::Float.new(1.0), {"@value" => "1.0", "@type" => RDF::XSD.float}],
|
990
1035
|
}.each do |title, (key, compacted, expanded)|
|
991
1036
|
it title do
|
992
|
-
subject.expand_value(key, compacted).
|
1037
|
+
expect(subject.expand_value(key, compacted)).to produce(expanded, @debug)
|
993
1038
|
end
|
994
1039
|
end
|
995
1040
|
|
@@ -1004,7 +1049,7 @@ describe JSON::LD::Context do
|
|
1004
1049
|
"native double" => ["foo", 1.1, {"@value" => 1.1}],
|
1005
1050
|
}.each do |title, (key, compacted, expanded)|
|
1006
1051
|
it title do
|
1007
|
-
subject.expand_value(key, compacted).
|
1052
|
+
expect(subject.expand_value(key, compacted)).to produce(expanded, @debug)
|
1008
1053
|
end
|
1009
1054
|
end
|
1010
1055
|
end
|
@@ -1026,13 +1071,13 @@ describe JSON::LD::Context do
|
|
1026
1071
|
"string-integer" => ["foaf:age", "foo", {"@value" => "foo", "@type" => RDF::XSD.integer.to_s}],
|
1027
1072
|
}.each do |title, (key, compacted, expanded)|
|
1028
1073
|
it title do
|
1029
|
-
subject.expand_value(key, compacted).
|
1074
|
+
expect(subject.expand_value(key, compacted)).to produce(expanded, @debug)
|
1030
1075
|
end
|
1031
1076
|
end
|
1032
1077
|
end
|
1033
1078
|
end
|
1034
1079
|
|
1035
|
-
describe "compact_value" do
|
1080
|
+
describe "#compact_value" do
|
1036
1081
|
let(:ctx) do
|
1037
1082
|
c = context.parse({
|
1038
1083
|
"dc" => RDF::DC.to_uri.to_s,
|
@@ -1069,7 +1114,7 @@ describe JSON::LD::Context do
|
|
1069
1114
|
"native double" => ["foo", 1.1e1, {"@value" => 1.1E1}],
|
1070
1115
|
}.each do |title, (key, compacted, expanded)|
|
1071
1116
|
it title do
|
1072
|
-
subject.compact_value(key, expanded).
|
1117
|
+
expect(subject.compact_value(key, expanded)).to produce(compacted, @debug)
|
1073
1118
|
end
|
1074
1119
|
end
|
1075
1120
|
|
@@ -1096,7 +1141,7 @@ describe JSON::LD::Context do
|
|
1096
1141
|
}.each do |title, (key, compacted, expanded)|
|
1097
1142
|
it title do
|
1098
1143
|
subject.default_language = "en"
|
1099
|
-
subject.compact_value(key, expanded).
|
1144
|
+
expect(subject.compact_value(key, expanded)).to produce(compacted, @debug)
|
1100
1145
|
end
|
1101
1146
|
end
|
1102
1147
|
end
|
@@ -1118,9 +1163,102 @@ describe JSON::LD::Context do
|
|
1118
1163
|
"@value" => [{"literal" => "foo", "language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
|
1119
1164
|
}.each do |title, (compacted, expanded)|
|
1120
1165
|
it title do
|
1121
|
-
subject.compact_value("foo", expanded).
|
1166
|
+
expect(subject.compact_value("foo", expanded)).to produce(compacted, @debug)
|
1122
1167
|
end
|
1123
1168
|
end
|
1124
1169
|
end
|
1125
1170
|
end
|
1171
|
+
|
1172
|
+
describe "#from_vocabulary" do
|
1173
|
+
it "must be described"
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
describe "#container" do
|
1177
|
+
subject {
|
1178
|
+
ctx = context.parse({
|
1179
|
+
"ex" => "http://example.org/",
|
1180
|
+
"list" => {"@id" => "ex:list", "@container" => "@list"},
|
1181
|
+
"set" => {"@id" => "ex:set", "@container" => "@set"},
|
1182
|
+
"ndx" => {"@id" => "ex:ndx", "@container" => "@index"},
|
1183
|
+
})
|
1184
|
+
@debug.clear
|
1185
|
+
ctx
|
1186
|
+
}
|
1187
|
+
it "uses TermDefinition" do
|
1188
|
+
expect(subject.container(subject.term_definitions['ex'])).to be_nil
|
1189
|
+
expect(subject.container(subject.term_definitions['list'])).to eq '@list'
|
1190
|
+
expect(subject.container(subject.term_definitions['set'])).to eq '@set'
|
1191
|
+
expect(subject.container(subject.term_definitions['ndx'])).to eq '@index'
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
it "uses string" do
|
1195
|
+
expect(subject.container('ex')).to be_nil
|
1196
|
+
expect(subject.container('list')).to eq '@list'
|
1197
|
+
expect(subject.container('set')).to eq '@set'
|
1198
|
+
expect(subject.container('ndx')).to eq '@index'
|
1199
|
+
end
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
describe "#language" do
|
1203
|
+
subject {
|
1204
|
+
ctx = context.parse({
|
1205
|
+
"ex" => "http://example.org/",
|
1206
|
+
"nil" => {"@id" => "ex:nil", "@language" => nil},
|
1207
|
+
"en" => {"@id" => "ex:en", "@language" => "en"},
|
1208
|
+
})
|
1209
|
+
@debug.clear
|
1210
|
+
ctx
|
1211
|
+
}
|
1212
|
+
it "uses TermDefinition" do
|
1213
|
+
expect(subject.language(subject.term_definitions['ex'])).to be_falsey
|
1214
|
+
expect(subject.language(subject.term_definitions['nil'])).to be_falsey
|
1215
|
+
expect(subject.language(subject.term_definitions['en'])).to eq 'en'
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
it "uses string" do
|
1219
|
+
expect(subject.language('ex')).to be_falsey
|
1220
|
+
expect(subject.language('nil')).to be_falsey
|
1221
|
+
expect(subject.language('en')).to eq 'en'
|
1222
|
+
end
|
1223
|
+
end
|
1224
|
+
|
1225
|
+
describe "#reverse?" do
|
1226
|
+
subject {
|
1227
|
+
ctx = context.parse({
|
1228
|
+
"ex" => "http://example.org/",
|
1229
|
+
"reverse" => {"@reverse" => "ex:reverse"},
|
1230
|
+
})
|
1231
|
+
@debug.clear
|
1232
|
+
ctx
|
1233
|
+
}
|
1234
|
+
it "uses TermDefinition" do
|
1235
|
+
expect(subject.reverse?(subject.term_definitions['ex'])).to be_falsey
|
1236
|
+
expect(subject.reverse?(subject.term_definitions['reverse'])).to be_truthy
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
it "uses string" do
|
1240
|
+
expect(subject.reverse?('ex')).to be_falsey
|
1241
|
+
expect(subject.reverse?('reverse')).to be_truthy
|
1242
|
+
end
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
describe "#reverse_term" do
|
1246
|
+
subject {
|
1247
|
+
ctx = context.parse({
|
1248
|
+
"ex" => "http://example.org/",
|
1249
|
+
"reverse" => {"@reverse" => "ex"},
|
1250
|
+
})
|
1251
|
+
@debug.clear
|
1252
|
+
ctx
|
1253
|
+
}
|
1254
|
+
it "uses TermDefinition" do
|
1255
|
+
expect(subject.reverse_term(subject.term_definitions['ex'])).to eql subject.term_definitions['reverse']
|
1256
|
+
expect(subject.reverse_term(subject.term_definitions['reverse'])).to eql subject.term_definitions['ex']
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it "uses string" do
|
1260
|
+
expect(subject.reverse_term('ex')).to eql subject.term_definitions['reverse']
|
1261
|
+
expect(subject.reverse_term('reverse')).to eql subject.term_definitions['ex']
|
1262
|
+
end
|
1263
|
+
end
|
1126
1264
|
end
|