json-ld 0.9.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/{README.markdown → README.md} +15 -3
  2. data/VERSION +1 -1
  3. data/lib/json/ld.rb +50 -87
  4. data/lib/json/ld/api.rb +85 -96
  5. data/lib/json/ld/compact.rb +103 -170
  6. data/lib/json/ld/context.rb +1137 -0
  7. data/lib/json/ld/expand.rb +212 -171
  8. data/lib/json/ld/extensions.rb +17 -1
  9. data/lib/json/ld/flatten.rb +145 -78
  10. data/lib/json/ld/frame.rb +1 -1
  11. data/lib/json/ld/from_rdf.rb +73 -103
  12. data/lib/json/ld/reader.rb +3 -1
  13. data/lib/json/ld/resource.rb +3 -3
  14. data/lib/json/ld/to_rdf.rb +98 -109
  15. data/lib/json/ld/utils.rb +54 -4
  16. data/lib/json/ld/writer.rb +5 -5
  17. data/spec/api_spec.rb +3 -28
  18. data/spec/compact_spec.rb +76 -113
  19. data/spec/{evaluation_context_spec.rb → context_spec.rb} +307 -563
  20. data/spec/expand_spec.rb +163 -187
  21. data/spec/flatten_spec.rb +119 -114
  22. data/spec/frame_spec.rb +5 -5
  23. data/spec/from_rdf_spec.rb +44 -24
  24. data/spec/suite_compact_spec.rb +11 -8
  25. data/spec/suite_error_expand_spec.rb +23 -0
  26. data/spec/suite_expand_spec.rb +3 -7
  27. data/spec/suite_flatten_spec.rb +3 -3
  28. data/spec/suite_frame_spec.rb +6 -6
  29. data/spec/suite_from_rdf_spec.rb +3 -3
  30. data/spec/suite_helper.rb +13 -6
  31. data/spec/suite_to_rdf_spec.rb +16 -10
  32. data/spec/test-files/test-1-rdf.ttl +4 -3
  33. data/spec/test-files/test-3-rdf.ttl +2 -1
  34. data/spec/test-files/test-4-compacted.json +1 -1
  35. data/spec/test-files/test-5-rdf.ttl +3 -2
  36. data/spec/test-files/test-6-rdf.ttl +3 -2
  37. data/spec/test-files/test-7-compacted.json +3 -3
  38. data/spec/test-files/test-7-expanded.json +3 -3
  39. data/spec/test-files/test-7-rdf.ttl +7 -6
  40. data/spec/test-files/test-9-compacted.json +1 -1
  41. data/spec/to_rdf_spec.rb +67 -75
  42. data/spec/writer_spec.rb +2 -0
  43. metadata +36 -24
  44. checksums.yaml +0 -15
  45. data/lib/json/ld/evaluation_context.rb +0 -984
@@ -58,7 +58,7 @@ describe JSON::LD::API do
58
58
  "@id" => {
59
59
  :input => {"@id" => "http://example.org/test#example"},
60
60
  :context => {},
61
- :output => {"@graph" => []}
61
+ :output => {}
62
62
  },
63
63
  "@id coercion" => {
64
64
  :input => {
@@ -136,18 +136,6 @@ describe JSON::LD::API do
136
136
  "b" => []
137
137
  }
138
138
  },
139
- "empty term" => {
140
- :input => {
141
- "@id" => "http://example.com/",
142
- "@type" => "#{RDF::RDFS.Resource}"
143
- },
144
- :context => {"" => "http://example.com/"},
145
- :output => {
146
- "@context" => {"" => "http://example.com/"},
147
- "@id" => "",
148
- "@type" => "#{RDF::RDFS.Resource}"
149
- },
150
- },
151
139
  "@type with string @id" => {
152
140
  :input => {
153
141
  "@id" => "http://example.com/",
@@ -191,7 +179,7 @@ describe JSON::LD::API do
191
179
  },
192
180
  }.each_pair do |title, params|
193
181
  it title do
194
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
182
+ jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
195
183
  jld.should produce(params[:output], @debug)
196
184
  end
197
185
  end
@@ -254,7 +242,7 @@ describe JSON::LD::API do
254
242
  },
255
243
  }.each do |title, params|
256
244
  it title do
257
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
245
+ jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
258
246
  jld.should produce(params[:output], @debug)
259
247
  end
260
248
  end
@@ -264,7 +252,7 @@ describe JSON::LD::API do
264
252
  {
265
253
  "Uses term with nil language when two terms conflict on language" => {
266
254
  :input => [{
267
- "http://example.com/term" => {"@value" => "v1", "@language" => nil}
255
+ "http://example.com/term" => {"@value" => "v1"}
268
256
  }],
269
257
  :context => {
270
258
  "term5" => {"@id" => "http://example.com/term","@language" => nil},
@@ -292,16 +280,80 @@ describe JSON::LD::API do
292
280
  "id1" => "http://example.com/id1",
293
281
  "@language" => "de"
294
282
  },
295
- "@id" => "id1",
283
+ "@id" => "http://example.com/id1",
296
284
  "id1" => "foo"
297
285
  }
286
+ },
287
+ "compact-0007" => {
288
+ :input => ::JSON.parse(%(
289
+ {"http://example.org/vocab#contains": "this-is-not-an-IRI"}
290
+ )),
291
+ :context => ::JSON.parse(%({
292
+ "ex": "http://example.org/vocab#",
293
+ "ex:contains": {"@type": "@id"}
294
+ })),
295
+ :output => ::JSON.parse(%({
296
+ "@context": {
297
+ "ex": "http://example.org/vocab#",
298
+ "ex:contains": {"@type": "@id"}
299
+ },
300
+ "http://example.org/vocab#contains": "this-is-not-an-IRI"
301
+ }))
298
302
  }
299
303
  }.each_pair do |title, params|
300
304
  it title do
301
305
  input = params[:input].is_a?(String) ? JSON.parse(params[:input]) : params[:input]
302
306
  ctx = params[:context].is_a?(String) ? JSON.parse(params[:context]) : params[:context]
303
307
  output = params[:output].is_a?(String) ? JSON.parse(params[:output]) : params[:output]
304
- jld = JSON::LD::API.compact(input, ctx, nil, :debug => @debug)
308
+ jld = JSON::LD::API.compact(input, ctx, :debug => @debug)
309
+ jld.should produce(output, @debug)
310
+ end
311
+ end
312
+ end
313
+
314
+ context "@reverse" do
315
+ {
316
+ "compact-0033" => {
317
+ :input => %([
318
+ {
319
+ "@id": "http://example.com/people/markus",
320
+ "@reverse": {
321
+ "http://xmlns.com/foaf/0.1/knows": [
322
+ {
323
+ "@id": "http://example.com/people/dave",
324
+ "http://xmlns.com/foaf/0.1/name": [ { "@value": "Dave Longley" } ]
325
+ }
326
+ ]
327
+ },
328
+ "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ]
329
+ }
330
+ ]),
331
+ :context => %({
332
+ "name": "http://xmlns.com/foaf/0.1/name",
333
+ "isKnownBy": { "@reverse": "http://xmlns.com/foaf/0.1/knows" }
334
+ }),
335
+ :output => %({
336
+ "@context": {
337
+ "name": "http://xmlns.com/foaf/0.1/name",
338
+ "isKnownBy": {
339
+ "@reverse": "http://xmlns.com/foaf/0.1/knows",
340
+ "@type": "@id"
341
+ }
342
+ },
343
+ "@id": "http://example.com/people/markus",
344
+ "name": "Markus Lanthaler",
345
+ "isKnownBy": {
346
+ "@id": "http://example.com/people/dave",
347
+ "name": "Dave Longley"
348
+ }
349
+ })
350
+ }
351
+ }.each_pair do |title, params|
352
+ it title do
353
+ input = params[:input].is_a?(String) ? JSON.parse(params[:input]) : params[:input]
354
+ ctx = params[:context].is_a?(String) ? JSON.parse(params[:context]) : params[:context]
355
+ output = params[:output].is_a?(String) ? JSON.parse(params[:output]) : params[:output]
356
+ jld = JSON::LD::API.compact(input, ctx, :debug => @debug)
305
357
  jld.should produce(output, @debug)
306
358
  end
307
359
  end
@@ -321,7 +373,7 @@ describe JSON::LD::API do
321
373
  },
322
374
  "foo" => "bar"
323
375
  }
324
- jld = JSON::LD::API.compact(input, ctx, nil, :debug => @debug, :validate => true)
376
+ jld = JSON::LD::API.compact(input, ctx, :debug => @debug, :validate => true)
325
377
  jld.should produce(expected, @debug)
326
378
  end
327
379
  end
@@ -337,7 +389,7 @@ describe JSON::LD::API do
337
389
  "b" => "c"
338
390
  }
339
391
  RDF::Util::File.stub(:open_file).with("http://example.com/context").and_yield(ctx)
340
- jld = JSON::LD::API.compact(input, "http://example.com/context", nil, :debug => @debug, :validate => true)
392
+ jld = JSON::LD::API.compact(input, "http://example.com/context", :debug => @debug, :validate => true)
341
393
  jld.should produce(expected, @debug)
342
394
  end
343
395
  end
@@ -366,7 +418,7 @@ describe JSON::LD::API do
366
418
  },
367
419
  }.each_pair do |title, params|
368
420
  it title do
369
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
421
+ jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
370
422
  jld.should produce(params[:output], @debug)
371
423
  end
372
424
  end
@@ -403,96 +455,7 @@ describe JSON::LD::API do
403
455
  },
404
456
  }.each_pair do |title, params|
405
457
  it title do
406
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
407
- jld.should produce(params[:output], @debug)
408
- end
409
- end
410
- end
411
-
412
- context "property generators" do
413
- {
414
- "exactly matching" => {
415
- :input => [{
416
- "http://example.com/foo" => [{"@value" => "baz"}],
417
- "http://example.com/bar"=> [{"@value" => "baz"}],
418
- }],
419
- :context => {
420
- "foobar" => {"@id" => ["http://example.com/foo", "http://example.com/bar"]}
421
- },
422
- :output => {
423
- "@context" => {
424
- "foobar" => {"@id" => ["http://example.com/foo", "http://example.com/bar"]}
425
- },
426
- "foobar" => "baz"
427
- }
428
- },
429
- "overlapping" => {
430
- :input => [{
431
- "http://example.com/foo" => [{"@value" => "baz"}, {"@value" => "baz1"}],
432
- "http://example.com/bar"=> [{"@value" => "baz"}, {"@value" => "baz2"}],
433
- }],
434
- :context => {
435
- "foobar" => {"@id" => ["http://example.com/foo", "http://example.com/bar"]}
436
- },
437
- :output => {
438
- "@context" => {
439
- "foobar" => {"@id" => ["http://example.com/foo", "http://example.com/bar"]}
440
- },
441
- "foobar" => "baz",
442
- "http://example.com/foo" => "baz1",
443
- "http://example.com/bar" => "baz2"
444
- }
445
- },
446
- "compact-0031" => {
447
- :input => JSON.parse(%q([{
448
- "@id": "http://example.com/node/1",
449
- "http://example.com/vocab/field_related": [{
450
- "@id": "http://example.com/node/this-is-related-news"
451
- }],
452
- "http://schema.org/about": [{
453
- "@id": "http://example.com/node/this-is-related-news"
454
- }, {
455
- "@id": "http://example.com/term/this-is-a-tag"
456
- }],
457
- "http://example.com/vocab/field_tags": [{
458
- "@id": "http://example.com/term/this-is-a-tag"
459
- }]
460
- }])),
461
- :context => JSON.parse(%q({
462
- "site": "http://example.com/",
463
- "field_tags": {
464
- "@id": [ "site:vocab/field_tags", "http://schema.org/about" ],
465
- "@container": "@set"
466
- },
467
- "field_related": {
468
- "@id": [ "site:vocab/field_related", "http://schema.org/about" ]
469
- }
470
- })),
471
- :output => JSON.parse(%q({
472
- "@context": {
473
- "site": "http://example.com/",
474
- "field_tags": {
475
- "@id": [
476
- "site:vocab/field_tags",
477
- "http://schema.org/about"
478
- ],
479
- "@container": "@set"
480
- },
481
- "field_related": {
482
- "@id": [
483
- "site:vocab/field_related",
484
- "http://schema.org/about"
485
- ]
486
- }
487
- },
488
- "@id": "site:node/1",
489
- "field_tags": [{"@id": "site:term/this-is-a-tag"}],
490
- "field_related": {"@id": "site:node/this-is-related-news"}
491
- })),
492
- },
493
- }.each_pair do |title, params|
494
- it title do
495
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
458
+ jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
496
459
  jld.should produce(params[:output], @debug)
497
460
  end
498
461
  end
@@ -516,7 +479,7 @@ describe JSON::LD::API do
516
479
  },
517
480
  }.each_pair do |title, params|
518
481
  it title do
519
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
482
+ jld = JSON::LD::API.compact(params[:input], params[:context], :debug => @debug)
520
483
  jld.should produce(params[:output], @debug)
521
484
  end
522
485
  end
@@ -539,7 +502,7 @@ describe JSON::LD::API do
539
502
  },
540
503
  }.each do |title, params|
541
504
  it title do
542
- lambda {JSON::LD::API.compact(params[:input], {}, nil)}.should raise_error(params[:exception])
505
+ lambda {JSON::LD::API.compact(params[:input], {})}.should raise_error(params[:exception])
543
506
  end
544
507
  end
545
508
  end
@@ -4,20 +4,40 @@ require 'spec_helper'
4
4
  require 'rdf/xsd'
5
5
  require 'rdf/spec/reader'
6
6
 
7
- describe JSON::LD::EvaluationContext do
7
+ # Add for testing
8
+ class JSON::LD::Context
9
+ # Retrieve type mappings
10
+ def coercions
11
+ term_definitions.inject({}) do |memo, (t,td)|
12
+ memo[t] = td.type_mapping
13
+ memo
14
+ end
15
+ end
16
+
17
+ def containers
18
+ term_definitions.inject({}) do |memo, (t,td)|
19
+ memo[t] = td.container_mapping
20
+ memo
21
+ end
22
+ end
23
+ end
24
+
25
+ describe JSON::LD::Context do
8
26
  before(:each) {
9
27
  @debug = []
10
28
  @ctx_json = %q({
11
29
  "@context": {
30
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
12
31
  "name": "http://xmlns.com/foaf/0.1/name",
13
32
  "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
14
33
  "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
15
34
  }
16
35
  })
17
36
  }
18
- subject { JSON::LD::EvaluationContext.new(:debug => @debug, :validate => true)}
37
+ let(:context) {JSON::LD::Context.new(:debug => @debug, :validate => true)}
38
+ subject {context}
19
39
 
20
- describe "#parse", :pending => "Major update" do
40
+ describe "#parse" do
21
41
  context "remote" do
22
42
  before(:each) do
23
43
  @ctx = StringIO.new(@ctx_json)
@@ -32,13 +52,14 @@ describe JSON::LD::EvaluationContext do
32
52
 
33
53
  it "fails given a missing remote @context" do
34
54
  RDF::Util::File.stub(:open_file).with("http://example.com/context").and_raise(IOError)
35
- lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::InvalidContext, /Failed to retrieve remote context/)
55
+ lambda {subject.parse("http://example.com/context")}.should raise_error(JSON::LD::InvalidContext::InvalidRemoteContext, "http://example.com/context")
36
56
  end
37
57
 
38
58
  it "creates mappings" do
39
59
  RDF::Util::File.stub(:open_file).with("http://example.com/context").and_yield(@ctx)
40
60
  ec = subject.parse("http://example.com/context")
41
61
  ec.mappings.should produce({
62
+ "xsd" => "http://www.w3.org/2001/XMLSchema#",
42
63
  "name" => "http://xmlns.com/foaf/0.1/name",
43
64
  "homepage" => "http://xmlns.com/foaf/0.1/homepage",
44
65
  "avatar" => "http://xmlns.com/foaf/0.1/avatar"
@@ -55,17 +76,7 @@ describe JSON::LD::EvaluationContext do
55
76
  RDF::Util::File.stub(:open_file).with("http://example.com/context").and_yield(@ctx)
56
77
  ec = subject.parse("http://example.com/c1")
57
78
  ec.mappings.should produce({
58
- "name" => "http://xmlns.com/foaf/0.1/name",
59
- "homepage" => "http://xmlns.com/foaf/0.1/homepage",
60
- "avatar" => "http://xmlns.com/foaf/0.1/avatar"
61
- }, @debug)
62
- end
63
- end
64
-
65
- context "EvaluationContext" do
66
- it "uses a duplicate of that provided" do
67
- ec = subject.parse(StringIO.new(@ctx_json))
68
- ec.mappings.should produce({
79
+ "xsd" => "http://www.w3.org/2001/XMLSchema#",
69
80
  "name" => "http://xmlns.com/foaf/0.1/name",
70
81
  "homepage" => "http://xmlns.com/foaf/0.1/homepage",
71
82
  "avatar" => "http://xmlns.com/foaf/0.1/avatar"
@@ -119,7 +130,7 @@ describe JSON::LD::EvaluationContext do
119
130
  }, @debug)
120
131
  end
121
132
 
122
- it "associates @list coercion with predicate" do
133
+ it "associates @list container mapping with predicate" do
123
134
  subject.parse({
124
135
  "foo" => {"@id" => "http://example.com/", "@container" => "@list"}
125
136
  }).containers.should produce({
@@ -127,7 +138,7 @@ describe JSON::LD::EvaluationContext do
127
138
  }, @debug)
128
139
  end
129
140
 
130
- it "associates @set coercion with predicate" do
141
+ it "associates @set container mapping with predicate" do
131
142
  subject.parse({
132
143
  "foo" => {"@id" => "http://example.com/", "@container" => "@set"}
133
144
  }).containers.should produce({
@@ -135,7 +146,7 @@ describe JSON::LD::EvaluationContext do
135
146
  }, @debug)
136
147
  end
137
148
 
138
- it "associates @id coercion with predicate" do
149
+ it "associates @id container mapping with predicate" do
139
150
  subject.parse({
140
151
  "foo" => {"@id" => "http://example.com/", "@type" => "@id"}
141
152
  }).coercions.should produce({
@@ -143,7 +154,7 @@ describe JSON::LD::EvaluationContext do
143
154
  }, @debug)
144
155
  end
145
156
 
146
- it "associates datatype coercion with predicate" do
157
+ it "associates type mapping with predicate" do
147
158
  subject.parse({
148
159
  "foo" => {"@id" => "http://example.com/", "@type" => RDF::XSD.string.to_s}
149
160
  }).coercions.should produce({
@@ -151,7 +162,7 @@ describe JSON::LD::EvaluationContext do
151
162
  }, @debug)
152
163
  end
153
164
 
154
- it "associates language coercion with predicate" do
165
+ it "associates language mapping with predicate" do
155
166
  subject.parse({
156
167
  "foo" => {"@id" => "http://example.com/", "@language" => "en"}
157
168
  }).languages.should produce({
@@ -213,7 +224,7 @@ describe JSON::LD::EvaluationContext do
213
224
  end
214
225
 
215
226
  it "loads initial context" do
216
- init_ec = JSON::LD::EvaluationContext.new
227
+ init_ec = JSON::LD::Context.new
217
228
  nil_ec = subject.parse(nil)
218
229
  nil_ec.default_language.should == init_ec.default_language
219
230
  nil_ec.languages.should == init_ec.languages
@@ -226,25 +237,6 @@ describe JSON::LD::EvaluationContext do
226
237
  subject.parse({"name" => nil}).mapping("name").should be_nil
227
238
  end
228
239
  end
229
-
230
- context "property generator" do
231
- {
232
- "empty" => [
233
- {"term" => {"@id" => []}},
234
- []
235
- ],
236
- "single" => [
237
- {"term" => {"@id" => ["http://example.com/"]}},
238
- ["http://example.com/"]
239
- ],
240
- "multiple" => [
241
- {"term" => {"@id" => ["http://example.com/", "http://example.org/"]}},
242
- ["http://example.com/", "http://example.org/"]
243
- ],
244
- }.each do |title, (input, result)|
245
- specify(title) {subject.parse(input).mapping("term").should produce(result, @debug)}
246
- end
247
- end
248
240
  end
249
241
 
250
242
  describe "Syntax Errors" do
@@ -269,23 +261,23 @@ describe JSON::LD::EvaluationContext do
269
261
  lambda {
270
262
  ec = subject.parse(context)
271
263
  ec.serialize.should produce({}, @debug)
272
- }.should raise_error(JSON::LD::InvalidContext::Syntax)
264
+ }.should raise_error(JSON::LD::InvalidContext)
273
265
  end
274
266
  end
275
267
 
276
- (JSON::LD::KEYWORDS - %w(@language @vocab)).each do |kw|
268
+ (JSON::LD::KEYWORDS - %w(@base @language @vocab)).each do |kw|
277
269
  it "does not redefine #{kw} as a string" do
278
270
  lambda {
279
271
  ec = subject.parse({kw => "http://example.com/"})
280
272
  ec.serialize.should produce({}, @debug)
281
- }.should raise_error(JSON::LD::InvalidContext::Syntax)
273
+ }.should raise_error(JSON::LD::InvalidContext)
282
274
  end
283
275
 
284
276
  it "does not redefine #{kw} with an @id" do
285
277
  lambda {
286
278
  ec = subject.parse({kw => {"@id" => "http://example.com/"}})
287
279
  ec.serialize.should produce({}, @debug)
288
- }.should raise_error(JSON::LD::InvalidContext::Syntax)
280
+ }.should raise_error(JSON::LD::InvalidContext)
289
281
  end
290
282
  end
291
283
  end
@@ -295,7 +287,7 @@ describe JSON::LD::EvaluationContext do
295
287
  "fixme" => "FIXME",
296
288
  }.each do |title, context|
297
289
  it title do
298
- lambda { subject.parse(context) }.should raise_error(JSON::LD::InvalidContext::LoadError)
290
+ lambda { subject.parse(context) }.should raise_error(JSON::LD::InvalidContext::InvalidRemoteContext)
299
291
  end
300
292
  end
301
293
  end
@@ -313,18 +305,6 @@ describe JSON::LD::EvaluationContext do
313
305
  }, @debug)
314
306
  end
315
307
 
316
- it "context array", :pending => "Major update" do
317
- ctx = [
318
- {"foo" => "http://example.com/"},
319
- {"baz" => "bob"}
320
- ]
321
-
322
- ec = subject.parse(ctx)
323
- ec.serialize.should produce({
324
- "@context" => ctx
325
- }, @debug)
326
- end
327
-
328
308
  it "context hash" do
329
309
  ctx = {"foo" => "http://example.com/"}
330
310
 
@@ -353,28 +333,22 @@ describe JSON::LD::EvaluationContext do
353
333
  end
354
334
 
355
335
  it "term mappings" do
356
- subject.set_mapping("foo", "http://example.com/")
357
- subject.serialize.should produce({
336
+ subject.
337
+ parse({'foo' => "http://example.com/"}).send(:clear_provided_context).
338
+ serialize.should produce({
358
339
  "@context" => {
359
340
  "foo" => "http://example.com/"
360
341
  }
361
342
  }, @debug)
362
343
  end
363
344
 
364
- it "property generator" do
365
- subject.set_mapping("foo", ["http://example.com/", "http://example.org/"])
366
- subject.serialize.should produce({
367
- "@context" => {
368
- "foo" => ["http://example.com/", "http://example.org/"]
369
- }
370
- }, @debug)
371
- end
372
-
373
345
  it "@type with dependent prefixes in a single context" do
374
- subject.set_mapping("xsd", RDF::XSD.to_uri.to_s)
375
- subject.set_mapping("homepage", RDF::FOAF.homepage.to_s)
376
- subject.set_coerce("homepage", "@id")
377
- subject.serialize.should produce({
346
+ subject.parse({
347
+ 'xsd' => "http://www.w3.org/2001/XMLSchema#",
348
+ 'homepage' => {'@id' => RDF::FOAF.homepage.to_s, '@type' => '@id'}
349
+ }).
350
+ send(:clear_provided_context).
351
+ serialize.should produce({
378
352
  "@context" => {
379
353
  "xsd" => RDF::XSD.to_uri,
380
354
  "homepage" => {"@id" => RDF::FOAF.homepage.to_s, "@type" => "@id"}
@@ -383,9 +357,11 @@ describe JSON::LD::EvaluationContext do
383
357
  end
384
358
 
385
359
  it "@list with @id definition in a single context" do
386
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
387
- subject.set_container("knows", '@list')
388
- subject.serialize.should produce({
360
+ subject.parse({
361
+ 'knows' => {'@id' => RDF::FOAF.knows.to_s, '@container' => '@list'}
362
+ }).
363
+ send(:clear_provided_context).
364
+ serialize.should produce({
389
365
  "@context" => {
390
366
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
391
367
  }
@@ -393,9 +369,11 @@ describe JSON::LD::EvaluationContext do
393
369
  end
394
370
 
395
371
  it "@set with @id definition in a single context" do
396
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
397
- subject.set_container("knows", '@set')
398
- subject.serialize.should produce({
372
+ subject.parse({
373
+ "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
374
+ }).
375
+ send(:clear_provided_context).
376
+ serialize.should produce({
399
377
  "@context" => {
400
378
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@set"}
401
379
  }
@@ -403,9 +381,11 @@ describe JSON::LD::EvaluationContext do
403
381
  end
404
382
 
405
383
  it "@language with @id definition in a single context" do
406
- subject.set_mapping("name", RDF::FOAF.name.to_s)
407
- subject.set_language("name", 'en')
408
- subject.serialize.should produce({
384
+ subject.parse({
385
+ "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
386
+ }).
387
+ send(:clear_provided_context).
388
+ serialize.should produce({
409
389
  "@context" => {
410
390
  "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "en"}
411
391
  }
@@ -413,22 +393,26 @@ describe JSON::LD::EvaluationContext do
413
393
  end
414
394
 
415
395
  it "@language with @id definition in a single context and equivalent default" do
416
- subject.set_mapping("name", RDF::FOAF.name.to_s)
417
- subject.default_language = 'en'
418
- subject.set_language("name", 'en')
419
- subject.serialize.should produce({
396
+ subject.parse({
397
+ "@language" => 'en',
398
+ "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
399
+ }).
400
+ send(:clear_provided_context).
401
+ serialize.should produce({
420
402
  "@context" => {
421
403
  "@language" => 'en',
422
- "name" => {"@id" => RDF::FOAF.name.to_s}
404
+ "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => 'en'}
423
405
  }
424
406
  }, @debug)
425
407
  end
426
408
 
427
409
  it "@language with @id definition in a single context and different default" do
428
- subject.set_mapping("name", RDF::FOAF.name.to_s)
429
- subject.default_language = 'en'
430
- subject.set_language("name", 'de')
431
- subject.serialize.should produce({
410
+ subject.parse({
411
+ "@language" => 'en',
412
+ "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
413
+ }).
414
+ send(:clear_provided_context).
415
+ serialize.should produce({
432
416
  "@context" => {
433
417
  "@language" => 'en',
434
418
  "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => "de"}
@@ -437,10 +421,12 @@ describe JSON::LD::EvaluationContext do
437
421
  end
438
422
 
439
423
  it "null @language with @id definition in a single context and default" do
440
- subject.set_mapping("name", RDF::FOAF.name.to_s)
441
- subject.default_language = 'en'
442
- subject.set_language("name", nil)
443
- subject.serialize.should produce({
424
+ subject.parse({
425
+ "@language" => 'en',
426
+ "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
427
+ }).
428
+ send(:clear_provided_context).
429
+ serialize.should produce({
444
430
  "@context" => {
445
431
  "@language" => 'en',
446
432
  "name" => {"@id" => RDF::FOAF.name.to_s, "@language" => nil}
@@ -449,10 +435,11 @@ describe JSON::LD::EvaluationContext do
449
435
  end
450
436
 
451
437
  it "prefix with @type and @list" do
452
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
453
- subject.set_coerce("knows", "@id")
454
- subject.set_container("knows", '@list')
455
- subject.serialize.should produce({
438
+ subject.parse({
439
+ "knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
440
+ }).
441
+ send(:clear_provided_context).
442
+ serialize.should produce({
456
443
  "@context" => {
457
444
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
458
445
  }
@@ -460,10 +447,11 @@ describe JSON::LD::EvaluationContext do
460
447
  end
461
448
 
462
449
  it "prefix with @type and @set" do
463
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
464
- subject.set_coerce("knows", "@id")
465
- subject.set_container("knows", '@set')
466
- subject.serialize.should produce({
450
+ subject.parse({
451
+ "knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
452
+ }).
453
+ send(:clear_provided_context).
454
+ serialize.should produce({
467
455
  "@context" => {
468
456
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
469
457
  }
@@ -471,21 +459,31 @@ describe JSON::LD::EvaluationContext do
471
459
  end
472
460
 
473
461
  it "CURIE with @type" do
474
- subject.set_mapping("foaf", RDF::FOAF.to_uri.to_s)
475
- subject.set_container("foaf:knows", '@list')
476
- subject.serialize.should produce({
462
+ subject.parse({
463
+ "foaf" => RDF::FOAF.to_uri.to_s,
464
+ "foaf:knows" => {
465
+ "@id" => RDF::FOAF.knows.to_s,
466
+ "@container" => "@list"
467
+ }
468
+ }).
469
+ send(:clear_provided_context).
470
+ serialize.should produce({
477
471
  "@context" => {
478
- "foaf" => RDF::FOAF.to_uri,
479
- "foaf:knows" => {"@container" => "@list"}
472
+ "foaf" => RDF::FOAF.to_uri.to_s,
473
+ "foaf:knows" => {
474
+ "@container" => "@list"
475
+ }
480
476
  }
481
477
  }, @debug)
482
478
  end
483
479
 
484
480
  it "does not use aliased @id in key position" do
485
- subject.set_mapping("id", '@id')
486
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
487
- subject.set_container("knows", '@list')
488
- subject.serialize.should produce({
481
+ subject.parse({
482
+ "id" => "@id",
483
+ "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
484
+ }).
485
+ send(:clear_provided_context).
486
+ serialize.should produce({
489
487
  "@context" => {
490
488
  "id" => "@id",
491
489
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
@@ -494,23 +492,34 @@ describe JSON::LD::EvaluationContext do
494
492
  end
495
493
 
496
494
  it "does not use aliased @id in value position" do
497
- subject.set_mapping("id", "@id")
498
- subject.set_mapping("foaf", RDF::FOAF.to_uri.to_s)
499
- subject.set_coerce("foaf:homepage", "@id")
500
- subject.serialize.should produce({
495
+ subject.parse({
496
+ "foaf" => RDF::FOAF.to_uri.to_s,
497
+ "id" => "@id",
498
+ "foaf:homepage" => {
499
+ "@id" => RDF::FOAF.homepage.to_s,
500
+ "@type" => "@id"
501
+ }
502
+ }).
503
+ send(:clear_provided_context).
504
+ serialize.should produce({
501
505
  "@context" => {
502
506
  "foaf" => RDF::FOAF.to_uri.to_s,
503
507
  "id" => "@id",
504
- "foaf:homepage" => {"@type" => "@id"}
508
+ "foaf:homepage" => {
509
+ "@type" => "@id"
510
+ }
505
511
  }
506
512
  }, @debug)
507
513
  end
508
514
 
509
515
  it "does not use aliased @type" do
510
- subject.set_mapping("type", "@type")
511
- subject.set_mapping("foaf", RDF::FOAF.to_uri.to_s)
512
- subject.set_coerce("foaf:homepage", "@id")
513
- subject.serialize.should produce({
516
+ subject.parse({
517
+ "foaf" => RDF::FOAF.to_uri.to_s,
518
+ "type" => "@type",
519
+ "foaf:homepage" => {"@type" => "@id"}
520
+ }).
521
+ send(:clear_provided_context).
522
+ serialize.should produce({
514
523
  "@context" => {
515
524
  "foaf" => RDF::FOAF.to_uri.to_s,
516
525
  "type" => "@type",
@@ -520,10 +529,12 @@ describe JSON::LD::EvaluationContext do
520
529
  end
521
530
 
522
531
  it "does not use aliased @container" do
523
- subject.set_mapping("container", '@container')
524
- subject.set_mapping("knows", RDF::FOAF.knows.to_s)
525
- subject.set_container("knows", '@list')
526
- subject.serialize.should produce({
532
+ subject.parse({
533
+ "container" => "@container",
534
+ "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
535
+ }).
536
+ send(:clear_provided_context).
537
+ serialize.should produce({
527
538
  "@context" => {
528
539
  "container" => "@container",
529
540
  "knows" => {"@id" => RDF::FOAF.knows.to_s, "@container" => "@list"}
@@ -532,10 +543,12 @@ describe JSON::LD::EvaluationContext do
532
543
  end
533
544
 
534
545
  it "compacts IRIs to CURIEs" do
535
- subject.set_mapping("ex", 'http://example.org/')
536
- subject.set_mapping("term", 'http://example.org/term')
537
- subject.set_coerce("term", "http://example.org/datatype")
538
- subject.serialize.should produce({
546
+ subject.parse({
547
+ "ex" => 'http://example.org/',
548
+ "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
549
+ }).
550
+ send(:clear_provided_context).
551
+ serialize.should produce({
539
552
  "@context" => {
540
553
  "ex" => 'http://example.org/',
541
554
  "term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
@@ -544,10 +557,12 @@ describe JSON::LD::EvaluationContext do
544
557
  end
545
558
 
546
559
  it "compacts IRIs using @vocab" do
547
- subject.vocab = 'http://example.org/'
548
- subject.set_mapping("term", 'http://example.org/term')
549
- subject.set_coerce("term", "http://example.org/datatype")
550
- subject.serialize.should produce({
560
+ subject.parse({
561
+ "@vocab" => 'http://example.org/',
562
+ "term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
563
+ }).
564
+ send(:clear_provided_context).
565
+ serialize.should produce({
551
566
  "@context" => {
552
567
  "@vocab" => 'http://example.org/',
553
568
  "term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
@@ -555,11 +570,11 @@ describe JSON::LD::EvaluationContext do
555
570
  }, @debug)
556
571
  end
557
572
 
558
- context "extra keys or values", :pending => "Major update" do
573
+ context "extra keys or values" do
559
574
  {
560
575
  "extra key" => {
561
576
  :input => {"foo" => {"@id" => "http://example.com/foo", "@baz" => "foobar"}},
562
- :result => {"@context" => {"foo" => {"@id" => "http://example.com/foo", "@baz" => "foobar"}}}
577
+ :result => {"@context" => {"foo" => "http://example.com/foo"}}
563
578
  }
564
579
  }.each do |title, params|
565
580
  it title do
@@ -572,163 +587,156 @@ describe JSON::LD::EvaluationContext do
572
587
  end
573
588
 
574
589
  describe "#expand_iri" do
575
- before(:each) do
576
- subject.set_mapping("ex", "http://example.org/")
577
- subject.set_mapping("", "http://empty/")
578
- subject.set_mapping("_", "http://underscore/")
579
- end
590
+ subject {
591
+ context.parse({
592
+ '@base' => 'http://base/',
593
+ '@vocab' => 'http://vocab/',
594
+ 'ex' => 'http://example.org/',
595
+ '' => 'http://empty/',
596
+ '_' => 'http://underscore/'
597
+ })
598
+ }
580
599
 
581
600
  it "bnode" do
582
601
  subject.expand_iri("_:a").should be_a(RDF::Node)
583
602
  end
584
603
 
585
- context "keywords", :pending => "Major update" do
604
+ context "keywords" do
586
605
  %w(id type).each do |kw|
587
606
  it "expands #{kw} to @#{kw}" do
588
607
  subject.set_mapping(kw, "@#{kw}")
589
- subject.expand_iri(kw).should produce("@#{kw}", @debug)
608
+ subject.expand_iri(kw, :vocab => true).should produce("@#{kw}", @debug)
590
609
  end
591
610
  end
592
611
  end
593
612
 
594
- context "relative IRI", :pending => "Major update" do
595
- {
596
- :subject => true,
597
- :predicate => false,
598
- :type => false
599
- }.each do |position, r|
600
- context "as #{position}" do
601
- {
602
- "absolute IRI" => ["http://example.org/", "http://example.org/", true],
603
- "term" => ["ex", "http://example.org/", true],
604
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix", true],
605
- "keyword" => ["@type", "@type", true],
606
- "empty" => [":suffix", "http://empty/suffix", true],
607
- "unmapped" => ["foo", "foo", false],
608
- "empty term" => ["", "http://empty/", true],
609
- "another abs IRI"=>["ex://foo", "ex://foo", true],
610
- "absolute IRI looking like a curie" =>
611
- ["foo:bar", "foo:bar", true],
612
- "bnode" => ["_:foo", RDF::Node("foo"), true],
613
- "_" => ["_", "http://underscore/", true],
614
- }.each do |title, (input,result,abs)|
615
- result = nil unless r || abs
616
- result = nil if title == 'unmapped'
617
- it title do
618
- subject.expand_iri(input).should produce(result, @debug)
619
- end
613
+ context "relative IRI" do
614
+ context "with no options" do
615
+ {
616
+ "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
617
+ "term" => ["ex", RDF::URI("ex")],
618
+ "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
619
+ "keyword" => ["@type", "@type"],
620
+ "empty" => [":suffix", RDF::URI("http://empty/suffix")],
621
+ "unmapped" => ["foo", RDF::URI("foo")],
622
+ "empty term" => ["", RDF::URI("")],
623
+ "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
624
+ "absolute IRI looking like a curie" =>
625
+ ["foo:bar", RDF::URI("foo:bar")],
626
+ "bnode" => ["_:t0", RDF::Node("t0")],
627
+ "_" => ["_", RDF::URI("_")],
628
+ }.each do |title, (input, result)|
629
+ it title do
630
+ subject.expand_iri(input).should produce(result, @debug)
620
631
  end
621
632
  end
622
633
  end
623
634
 
624
635
  context "with base IRI" do
625
636
  {
626
- :subject => true,
627
- :predicate => false,
628
- :type => true
629
- }.each do |position, r|
630
- context "as #{position}" do
631
- before(:each) do
632
- subject.instance_variable_set(:@base, RDF::URI("http://example.org/"))
633
- subject.mappings.delete("")
634
- end
635
-
636
- {
637
- "base" => ["", RDF::URI("http://example.org/")],
638
- "relative" => ["a/b", RDF::URI("http://example.org/a/b")],
639
- "hash" => ["#a", RDF::URI("http://example.org/#a")],
640
- "absolute" => ["http://foo/", RDF::URI("http://foo/")]
641
- }.each do |title, (input,result)|
642
- result = nil unless r || title == 'absolute'
643
- it title do
644
- subject.expand_iri(input, :position => position).should produce(result, @debug)
645
- end
646
- end
637
+ "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
638
+ "term" => ["ex", RDF::URI("http://base/ex")],
639
+ "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
640
+ "keyword" => ["@type", "@type"],
641
+ "empty" => [":suffix", RDF::URI("http://empty/suffix")],
642
+ "unmapped" => ["foo", RDF::URI("http://base/foo")],
643
+ "empty term" => ["", RDF::URI("http://base/")],
644
+ "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
645
+ "absolute IRI looking like a curie" =>
646
+ ["foo:bar", RDF::URI("foo:bar")],
647
+ "bnode" => ["_:t0", RDF::Node("t0")],
648
+ "_" => ["_", RDF::URI("http://base/_")],
649
+ }.each do |title, (input, result)|
650
+ it title do
651
+ subject.expand_iri(input, :documentRelative => true).should produce(result, @debug)
647
652
  end
648
653
  end
649
654
  end
650
- end
651
655
 
652
- context "@vocab" do
653
- before(:each) { subject.vocab = "http://example.com/"}
654
- {
655
- :subject => false,
656
- :predicate => true,
657
- :type => true
658
- }.each do |position, r|
659
- context "as #{position}" do
660
- {
661
- "absolute IRI" => ["http://example.org/", "http://example.org/", true],
662
- "term" => ["ex", "http://example.org/", true],
663
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix", true],
664
- "keyword" => ["@type", "@type", true],
665
- "empty" => [":suffix", "http://empty/suffix", true],
666
- "unmapped" => ["foo", "http://example.com/foo", true],
667
- "empty term" => ["", "http://empty/", true],
668
- }.each do |title, (input,result,abs)|
669
- result = nil unless r || abs
670
- it title do
671
- subject.expand_iri(input).should produce(result, @debug)
672
- end
656
+ context "@vocab" do
657
+ {
658
+ "absolute IRI" => ["http://example.org/", RDF::URI("http://example.org/")],
659
+ "term" => ["ex", RDF::URI("http://example.org/")],
660
+ "prefix:suffix" => ["ex:suffix", RDF::URI("http://example.org/suffix")],
661
+ "keyword" => ["@type", "@type"],
662
+ "empty" => [":suffix", RDF::URI("http://empty/suffix")],
663
+ "unmapped" => ["foo", RDF::URI("http://vocab/foo")],
664
+ "empty term" => ["", RDF::URI("http://empty/")],
665
+ "another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
666
+ "absolute IRI looking like a curie" =>
667
+ ["foo:bar", RDF::URI("foo:bar")],
668
+ "bnode" => ["_:t0", RDF::Node("t0")],
669
+ "_" => ["_", RDF::URI("http://underscore/")],
670
+ }.each do |title, (input, result)|
671
+ it title do
672
+ subject.expand_iri(input, :vocab => true).should produce(result, @debug)
673
673
  end
674
674
  end
675
675
  end
676
-
677
- it "removes term if set to null with @vocab" do
678
- subject.set_mapping("term", nil)
679
- subject.expand_iri("term").should produce(nil, @debug)
680
- end
681
- end
682
-
683
- context "property generator" do
684
- before(:each) {subject.set_mapping("pg", ["http://a/", "http://b/"])}
685
- {
686
- "term" => ["pg", ["http://a/", "http://b/"]],
687
- "prefix:suffix" => ["pg:suffix", ["http://a/suffix", "http://b/suffix"]],
688
- }.each do |title, (input,result)|
689
- it title do
690
- subject.expand_iri(input).should produce(result, @debug)
691
- end
692
- end
693
676
  end
694
677
  end
695
678
 
696
679
  describe "#compact_iri" do
697
- before(:each) do
698
- subject.set_mapping("ex", "http://example.org/")
699
- subject.set_mapping("", "http://empty/")
700
- subject.set_mapping("http://example.com/null", nil)
701
- end
680
+ subject {
681
+ c = context.parse({
682
+ '@base' => 'http://base/',
683
+ "xsd" => "http://www.w3.org/2001/XMLSchema#",
684
+ 'ex' => 'http://example.org/',
685
+ '' => 'http://empty/',
686
+ '_' => 'http://underscore/',
687
+ 'rex' => {'@reverse' => "ex"},
688
+ 'lex' => {'@id' => 'ex', '@language' => 'en'},
689
+ 'tex' => {'@id' => 'ex', '@type' => 'xsd:string'}
690
+ })
691
+ @debug.clear
692
+ c
693
+ }
702
694
 
703
695
  {
704
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
705
- "term" => ["ex", "http://example.org/"],
696
+ "nil" => [nil, nil],
697
+ "absolute IRI" => ["http://example.com/", "http://example.com/"],
706
698
  "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
707
- "keyword" => ["@type", "@type"],
708
- "empty" => [":suffix", "http://empty/suffix"],
709
- "unmapped" => ["foo", "foo"],
710
- "bnode" => ["_:a", RDF::Node("a")],
711
- "null IRI" => [nil, "http://example.com/null"],
699
+ "keyword" => ["@type", "@type"],
700
+ "empty" => [":suffix", "http://empty/suffix"],
701
+ "unmapped" => ["foo", "foo"],
702
+ "bnode" => ["_:a", RDF::Node("a")],
703
+ "relative" => ["foo/bar", "http://base/foo/bar"]
712
704
  }.each do |title, (result, input)|
713
705
  it title do
714
706
  subject.compact_iri(input).should produce(result, @debug)
715
707
  end
716
708
  end
717
709
 
710
+ context "with :vocab option" do
711
+ {
712
+ "absolute IRI" => ["http://example.com/", "http://example.com/"],
713
+ "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
714
+ "keyword" => ["@type", "@type"],
715
+ "empty" => [":suffix", "http://empty/suffix"],
716
+ "unmapped" => ["foo", "foo"],
717
+ "bnode" => ["_:a", RDF::Node("a")],
718
+ "relative" => ["http://base/foo/bar", "http://base/foo/bar"]
719
+ }.each do |title, (result, input)|
720
+ it title do
721
+ subject.compact_iri(input, :vocab => true).should produce(result, @debug)
722
+ end
723
+ end
724
+ end
725
+
718
726
  context "with @vocab" do
719
727
  before(:each) { subject.vocab = "http://example.org/"}
720
728
 
721
729
  {
722
- "absolute IRI" => ["http://example.com/", "http://example.com/"],
723
- "term" => ["ex", "http://example.org/"],
724
- "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
725
- "keyword" => ["@type", "@type"],
726
- "empty" => [":suffix", "http://empty/suffix"],
727
- "unmapped" => ["foo", "foo"],
728
- "bnode" => ["_:a", RDF::Node("a")],
730
+ "absolute IRI" => ["http://example.com/", "http://example.com/"],
731
+ "prefix:suffix" => ["suffix", "http://example.org/suffix"],
732
+ "keyword" => ["@type", "@type"],
733
+ "empty" => [":suffix", "http://empty/suffix"],
734
+ "unmapped" => ["foo", "foo"],
735
+ "bnode" => ["_:a", RDF::Node("a")],
736
+ "relative" => ["http://base/foo/bar", "http://base/foo/bar"]
729
737
  }.each do |title, (result, input)|
730
738
  it title do
731
- subject.compact_iri(input).should produce(result, @debug)
739
+ subject.compact_iri(input, :vocab => true).should produce(result, @debug)
732
740
  end
733
741
  end
734
742
 
@@ -736,11 +744,11 @@ describe JSON::LD::EvaluationContext do
736
744
  subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
737
745
  subject.set_mapping("ex", nil)
738
746
  subject.compact_iri("http://example.org/name", :position => :predicate).
739
- should produce("http://example.org/name", @debug)
747
+ should produce("lex:name", @debug)
740
748
  end
741
749
  end
742
750
 
743
- context "with value", :pending => "Major update" do
751
+ context "with value" do
744
752
  let(:ctx) do
745
753
  c = subject.parse({
746
754
  "xsd" => RDF::XSD.to_s,
@@ -773,13 +781,13 @@ describe JSON::LD::EvaluationContext do
773
781
 
774
782
  {
775
783
  "langmap" => [{"@value" => "en", "@language" => "en"}],
776
- "plain" => [{"@value" => "foo"}],
777
- "setplain" => [{"@value" => "foo", "@language" => "pl"}] # looks like langmap
784
+ #"plain" => [{"@value" => "foo"}],
785
+ "setplain" => [{"@value" => "foo", "@language" => "pl"}]
778
786
  }.each do |prop, values|
779
787
  context "uses #{prop}" do
780
788
  values.each do |value|
781
789
  it "for #{value.inspect}" do
782
- ctx.compact_iri("http://example.com/#{prop.sub('set', '')}", :value => value).should produce(prop, @debug)
790
+ ctx.compact_iri("http://example.com/#{prop.sub('set', '')}", :value => value, :vocab => true).should produce(prop, @debug)
783
791
  end
784
792
  end
785
793
  end
@@ -795,17 +803,19 @@ describe JSON::LD::EvaluationContext do
795
803
  [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => true}],
796
804
  [{"@value" => "foo"}, {"@value" => "bar"}, {"@value" => 1}],
797
805
  [{"@value" => "de", "@language" => "de"}, {"@value" => "jp", "@language" => "jp"}],
806
+ [{"@value" => true}], [{"@value" => false}],
807
+ [[{"@value" => 1}], [{"@value" => 1.1}],
798
808
  ],
799
809
  "listlang" => [[{"@value" => "en", "@language" => "en"}]],
800
- "listbool" => [[{"@value" => true}], [{"@value" => false}], [{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}]],
801
- "listinteger" => [[{"@value" => 1}], [{"@value" => "1", "@type" => RDF::XSD.integer.to_s}]],
802
- "listdouble" => [[{"@value" => 1.1}], [{"@value" => "1", "@type" => RDF::XSD.double.to_s}]],
810
+ "listbool" => [[{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}]],
811
+ "listinteger" => [{"@value" => "1", "@type" => RDF::XSD.integer.to_s}]],
812
+ "listdouble" => [[{"@value" => "1", "@type" => RDF::XSD.double.to_s}]],
803
813
  "listdate" => [[{"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}]],
804
814
  }.each do |prop, values|
805
815
  context "uses #{prop}" do
806
816
  values.each do |value|
807
817
  it "for #{{"@list" => value}.inspect}" do
808
- ctx.compact_iri("http://example.com/#{prop.sub('list', '')}", :value => {"@list" => value}).should produce(prop, @debug)
818
+ ctx.compact_iri("http://example.com/#{prop.sub('list', '')}", :value => {"@list" => value}, :vocab => true).should produce(prop, @debug)
809
819
  end
810
820
  end
811
821
  end
@@ -813,7 +823,7 @@ describe JSON::LD::EvaluationContext do
813
823
  end
814
824
  end
815
825
 
816
- context "compact-0018", :pending => "Major update" do
826
+ context "compact-0018" do
817
827
  let(:ctx) do
818
828
  subject.parse(JSON.parse %({
819
829
  "id1": "http://example.com/id1",
@@ -912,7 +922,7 @@ describe JSON::LD::EvaluationContext do
912
922
  }.each do |term, value|
913
923
  [value].flatten.each do |v|
914
924
  it "Uses #{term} for #{v}" do
915
- ctx.compact_iri("http://example.com/term", :value => JSON.parse(v)).
925
+ ctx.compact_iri("http://example.com/term", :value => JSON.parse(v), :vocab => true).
916
926
  should produce(term, @debug)
917
927
  end
918
928
  end
@@ -932,19 +942,6 @@ describe JSON::LD::EvaluationContext do
932
942
  end
933
943
  end
934
944
 
935
- context "compact-0021" do
936
- let(:ctx) do
937
- subject.parse({
938
- "@vocab" => "http://example.com/",
939
- "sub" => "http://example.com/subdir/"
940
- })
941
- end
942
- it "Compact properties and types using @vocab" do
943
- ctx.compact_iri("http://example.com/subdir/id/1", :position => :subject).
944
- should produce("sub:id/1", @debug)
945
- end
946
- end
947
-
948
945
  context "compact-0041" do
949
946
  let(:ctx) do
950
947
  subject.parse({"name" => {"@id" => "http://example.com/property", "@container" => "@list"}})
@@ -958,268 +955,23 @@ describe JSON::LD::EvaluationContext do
958
955
  end
959
956
  end
960
957
 
961
- describe "#term_rank", :pending => "Major update" do
962
- {
963
- "no coercions" => {
964
- :defn => {},
965
- "boolean value" => {:value => {"@value" => true}, :rank => 2},
966
- "integer value" => {:value => {"@value" => 1}, :rank => 2},
967
- "double value" => {:value => {"@value" => 1.1}, :rank => 2},
968
- "string value" => {:value => {"@value" => "foo"}, :rank => 3},
969
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 1},
970
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 1},
971
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 1},
972
- "null" => {:value => nil, :rank => 3},
973
- },
974
- "boolean" => {
975
- :defn => {"@type" => RDF::XSD.boolean.to_s},
976
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
977
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
978
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
979
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
980
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
981
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
982
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
983
- "value boolean" => {:value => {"@value" => "true", "@type" => RDF::XSD.boolean.to_s}, :rank => 3},
984
- "null" => {:value => nil, :rank => 3},
985
- },
986
- "integer" => {
987
- :defn => {"@type" => RDF::XSD.integer.to_s},
988
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
989
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
990
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
991
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
992
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
993
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
994
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
995
- "value integer" => {:value => {"@value" => "1", "@type" => RDF::XSD.integer.to_s}, :rank => 3},
996
- "null" => {:value => nil, :rank => 3},
997
- },
998
- "double" => {
999
- :defn => {"@type" => RDF::XSD.double.to_s},
1000
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1001
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1002
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1003
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1004
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1005
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1006
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1007
- "value double" => {:value => {"@value" => "1.1", "@type" => RDF::XSD.double.to_s}, :rank => 3},
1008
- "null" => {:value => nil, :rank => 3},
1009
- },
1010
- "date" => {
1011
- :defn => {"@type" => RDF::XSD.date.to_s},
1012
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1013
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1014
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1015
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1016
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 3},
1017
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1018
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1019
- "null" => {:value => nil, :rank => 3},
1020
- },
1021
- "lang" => {
1022
- :defn => {"@language" => "en"},
1023
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1024
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1025
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1026
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1027
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1028
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 2},
1029
- "other lang" => {:value => {"@value" => "apple", "@language" => "de"}, :rank => 0},
1030
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1031
- "null" => {:value => nil, :rank => 3},
1032
- },
1033
- "id" => {
1034
- :defn => {"@type" => "@id"},
1035
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1036
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1037
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1038
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1039
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1040
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1041
- "other lang" => {:value => {"@value" => "apple", "@language" => "de"}, :rank => 0},
1042
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 3},
1043
- "null" => {:value => nil, :rank => 3},
1044
- },
1045
- }.each do |title, properties|
1046
- context title do
1047
- let(:ctx) do
1048
- subject.parse({
1049
- "term" => properties[:defn].merge("@id" => "http://example.org/term")
1050
- })
1051
- end
1052
- properties.each do |type, defn|
1053
- next unless type.is_a?(String)
1054
- it "returns #{defn[:rank]} for #{type}" do
1055
- ctx.send(:term_rank, "term", defn[:value]).should produce(defn[:rank], @debug)
1056
- end
1057
- end
1058
- end
1059
- end
1060
-
1061
- context "with default language" do
1062
- before(:each) {subject.default_language = "en"}
1063
- {
1064
- "no coercions" => {
1065
- :defn => {},
1066
- "boolean value" => {:value => {"@value" => true}, :rank => 2},
1067
- "integer value" => {:value => {"@value" => 1}, :rank => 2},
1068
- "double value" => {:value => {"@value" => 1.1}, :rank => 2},
1069
- "string value" => {:value => {"@value" => "foo"}, :rank => 2},
1070
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 1},
1071
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 2},
1072
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 1},
1073
- "value string" => {:value => {"@value" => "foo"}, :rank => 2},
1074
- "null" => {:value => nil, :rank => 3},
1075
- },
1076
- "boolean" => {
1077
- :defn => {"@type" => RDF::XSD.boolean.to_s},
1078
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1079
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1080
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1081
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1082
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1083
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1084
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1085
- "value boolean" => {:value => {"@value" => "true", "@type" => RDF::XSD.boolean.to_s}, :rank => 3},
1086
- "null" => {:value => nil, :rank => 3},
1087
- },
1088
- "integer" => {
1089
- :defn => {"@type" => RDF::XSD.integer.to_s},
1090
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1091
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1092
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1093
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1094
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1095
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1096
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1097
- "value integer" => {:value => {"@value" => "1", "@type" => RDF::XSD.integer.to_s}, :rank => 3},
1098
- "null" => {:value => nil, :rank => 3},
1099
- },
1100
- "double" => {
1101
- :defn => {"@type" => RDF::XSD.double.to_s},
1102
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1103
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1104
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1105
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1106
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1107
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1108
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1109
- "value double" => {:value => {"@value" => "1.1", "@type" => RDF::XSD.double.to_s}, :rank => 3},
1110
- "null" => {:value => nil, :rank => 3},
1111
- },
1112
- "date" => {
1113
- :defn => {"@type" => RDF::XSD.date.to_s},
1114
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1115
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1116
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1117
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1118
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 3},
1119
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1120
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1121
- "null" => {:value => nil, :rank => 3},
1122
- },
1123
- "lang" => {
1124
- :defn => {"@language" => "en"},
1125
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1126
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1127
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1128
- "string value" => {:value => {"@value" => "foo"}, :rank => 0},
1129
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1130
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 2},
1131
- "other lang" => {:value => {"@value" => "apple", "@language" => "de"}, :rank => 0},
1132
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1133
- "null" => {:value => nil, :rank => 3},
1134
- },
1135
- "null lang" => {
1136
- :defn => {"@language" => nil},
1137
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1138
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1139
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1140
- "string value" => {:value => {"@value" => "foo"}, :rank => 3},
1141
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1142
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1143
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 0},
1144
- "null" => {:value => nil, :rank => 3},
1145
- },
1146
- "id" => {
1147
- :defn => {"@type" => "@id"},
1148
- "boolean value" => {:value => {"@value" => true}, :rank => 1},
1149
- "integer value" => {:value => {"@value" => 1}, :rank => 1},
1150
- "double value" => {:value => {"@value" => 1.1}, :rank => 1},
1151
- "string" => {:value => {"@value" => "foo"}, :rank => 0},
1152
- "date" => {:value => {"@value" => "2012-04-17", "@type" => RDF::XSD.date.to_s}, :rank => 0},
1153
- "lang" => {:value => {"@value" => "apple", "@language" => "en"}, :rank => 0},
1154
- "other lang" => {:value => {"@value" => "apple", "@language" => "de"}, :rank => 0},
1155
- "id" => {:value => {"@id" => "http://example/id"}, :rank => 3},
1156
- "null" => {:value => nil, :rank => 3},
1157
- },
1158
- }.each do |title, properties|
1159
- context title do
1160
- let(:ctx) do
1161
- subject.parse({
1162
- "term" => properties[:defn].merge("@id" => "http://example.org/term")
1163
- })
1164
- end
1165
- properties.each do |type, defn|
1166
- next unless type.is_a?(String)
1167
- it "returns #{defn[:rank]} for #{type}" do
1168
- ctx.send(:term_rank, "term", defn[:value]).should produce(defn[:rank], @debug)
1169
- end
1170
- end
1171
- end
1172
- end
1173
-
1174
- context "compact-0018" do
1175
- let(:ctx) do
1176
- subject.parse({
1177
- "@language" => "de",
1178
- "term1" => {"@id" => "http://example/term"},
1179
- "term2" => {"@id" => "http://example/term", "@language" => "en"}
1180
- })
1181
- end
1182
- {
1183
- "v1.1" => [{"@value" => "v1.1", "@language" => "de"}, 2, 0],
1184
- "v1.2" => [{"@value" => "v1.2", "@language" => "de"}, 2, 0],
1185
- "v1.3" => [{"@value" => "v1.3", "@language" => "de"}, 2, 0],
1186
- "v1.4" => [{"@value" => 4}, 2, 1],
1187
- "v1.5" => [{"@value" => "v1.5", "@language" => "de"}, 2, 0],
1188
- "v1.6" => [{"@value" => "v1.6", "@language" => "en"}, 1, 2],
1189
- "v2.1" => [{"@value" => "v2.1", "@language" => "en"}, 1, 2],
1190
- "v2.2" => [{"@value" => "v2.2", "@language" => "en"}, 1, 2],
1191
- "v2.3" => [{"@value" => "v2.3", "@language" => "en"}, 1, 2],
1192
- "v2.4" => [{"@value" => 4}, 2, 1],
1193
- "v2.5" => [{"@value" => "v2.5", "@language" => "en"}, 1, 2],
1194
- "v2.6" => [{"@value" => "v2.6", "@language" => "de"}, 2, 0],
1195
- }.each do |label, (val, r1, r2)|
1196
- context label do
1197
- it "has rank #{r1} for term1" do
1198
- ctx.send(:term_rank, "term1", val).should produce(r1, @debug)
1199
- end
1200
-
1201
- it "has rank #{r2} for term2" do
1202
- ctx.send(:term_rank, "term2", val).should produce(r2, @debug)
1203
- end
1204
- end
1205
- end
1206
- end
1207
- end
1208
- end
1209
-
1210
958
  describe "#expand_value" do
1211
- before(:each) do
1212
- subject.set_mapping("dc", RDF::DC.to_uri.to_s)
1213
- subject.set_mapping("ex", "http://example.org/")
1214
- subject.set_mapping("foaf", RDF::FOAF.to_uri.to_s)
1215
- subject.set_mapping("xsd", RDF::XSD.to_uri.to_s)
1216
- subject.set_coerce("foaf:age", RDF::XSD.integer.to_s)
1217
- subject.set_coerce("foaf:knows", "@id")
1218
- subject.set_coerce("dc:created", RDF::XSD.date.to_s)
1219
- subject.set_coerce("ex:integer", RDF::XSD.integer.to_s)
1220
- subject.set_coerce("ex:double", RDF::XSD.double.to_s)
1221
- subject.set_coerce("ex:boolean", RDF::XSD.boolean.to_s)
1222
- end
959
+ subject {
960
+ ctx = context.parse({
961
+ "dc" => RDF::DC.to_uri.to_s,
962
+ "ex" => "http://example.org/",
963
+ "foaf" => RDF::FOAF.to_uri.to_s,
964
+ "xsd" => "http://www.w3.org/2001/XMLSchema#",
965
+ "foaf:age" => {"@type" => "xsd:integer"},
966
+ "foaf:knows" => {"@type" => "@id"},
967
+ "dc:created" => {"@type" => "xsd:date"},
968
+ "ex:integer" => {"@type" => "xsd:integer"},
969
+ "ex:double" => {"@type" => "xsd:double"},
970
+ "ex:boolean" => {"@type" => "xsd:boolean"},
971
+ })
972
+ @debug.clear
973
+ ctx
974
+ }
1223
975
 
1224
976
  %w(boolean integer string dateTime date time).each do |dt|
1225
977
  it "expands datatype xsd:#{dt}" do
@@ -1229,7 +981,7 @@ describe JSON::LD::EvaluationContext do
1229
981
 
1230
982
  {
1231
983
  "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1232
- "term" => ["foaf:knows", "ex", {"@id" => "http://example.org/"}],
984
+ "term" => ["foaf:knows", "ex", {"@id" => "ex"}],
1233
985
  "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1234
986
  "no IRI" => ["foo", "http://example.com/", {"@value" => "http://example.com/"}],
1235
987
  "no term" => ["foo", "ex", {"@value" => "ex"}],
@@ -1296,34 +1048,34 @@ describe JSON::LD::EvaluationContext do
1296
1048
  end
1297
1049
 
1298
1050
  describe "compact_value" do
1299
- before(:each) do
1300
- subject.set_mapping("dc", RDF::DC.to_uri.to_s)
1301
- subject.set_mapping("ex", "http://example.org/")
1302
- subject.set_mapping("foaf", RDF::FOAF.to_uri.to_s)
1303
- subject.set_mapping("xsd", RDF::XSD.to_uri.to_s)
1304
- subject.set_mapping("list", "http://example.org/list")
1305
- subject.set_mapping("nolang", "http://example.org/nolang")
1306
- subject.set_coerce("foaf:age", RDF::XSD.integer.to_s)
1307
- subject.set_coerce("foaf:knows", "@id")
1308
- subject.set_coerce("dc:created", RDF::XSD.date.to_s)
1309
- subject.set_container("list", "@list")
1310
- subject.set_language("nolang", nil)
1311
- subject.set_mapping("langmap", "http://example.org/langmap")
1312
- subject.set_container("langmap", "@language")
1051
+ let(:ctx) do
1052
+ c = context.parse({
1053
+ "dc" => RDF::DC.to_uri.to_s,
1054
+ "ex" => "http://example.org/",
1055
+ "foaf" => RDF::FOAF.to_uri.to_s,
1056
+ "xsd" => RDF::XSD.to_s,
1057
+ "langmap" => {"@id" => "http://example.com/langmap", "@container" => "@language"},
1058
+ "list" => {"@id" => "http://example.org/list", "@container" => "@list"},
1059
+ "nolang" => {"@id" => "http://example.org/nolang", "@language" => nil},
1060
+ "dc:created" => {"@type" => RDF::XSD.date.to_s},
1061
+ "foaf:age" => {"@type" => RDF::XSD.integer.to_s},
1062
+ "foaf:knows" => {"@type" => "@id"},
1063
+ })
1064
+ @debug.clear
1065
+ c
1313
1066
  end
1067
+ subject {ctx}
1314
1068
 
1315
1069
  {
1316
1070
  "absolute IRI" => ["foaf:knows", "http://example.com/", {"@id" => "http://example.com/"}],
1317
- "term" => ["foaf:knows", "ex", {"@id" => "http://example.org/"}],
1318
1071
  "prefix:suffix" => ["foaf:knows", "ex:suffix", {"@id" => "http://example.org/suffix"}],
1319
1072
  "integer" => ["foaf:age", "54", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1320
1073
  "date " => ["dc:created", "2011-12-27Z", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1321
1074
  "no IRI" => ["foo", {"@id" =>"http://example.com/"},{"@id" => "http://example.com/"}],
1322
- "no IRI (term)" => ["foo", {"@id" => "ex"}, {"@id" => "http://example.org/"}],
1323
- "no IRI (CURIE)" => ["foo", {"@id" => "foaf:Person"}, {"@id" => RDF::FOAF.Person.to_s}],
1324
- "no boolean" => ["foo", {"@value" => "true", "@type" => "xsd:boolean"},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
1325
- "no integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1326
- "no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => "xsd:date"}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1075
+ "no IRI (CURIE)" => ["foo", {"@id" => RDF::FOAF.Person.to_s}, {"@id" => RDF::FOAF.Person.to_s}],
1076
+ "no boolean" => ["foo", {"@value" => "true", "@type" => RDF::XSD.boolean.to_s},{"@value" => "true", "@type" => RDF::XSD.boolean.to_s}],
1077
+ "no integer" => ["foo", {"@value" => "54", "@type" => RDF::XSD.integer.to_s},{"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1078
+ "no date " => ["foo", {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}, {"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1327
1079
  "no string " => ["foo", "string", {"@value" => "string"}],
1328
1080
  "no lang " => ["nolang", "string", {"@value" => "string"}],
1329
1081
  "native boolean" => ["foo", true, {"@value" => true}],
@@ -1339,8 +1091,8 @@ describe JSON::LD::EvaluationContext do
1339
1091
  context "@language" do
1340
1092
  {
1341
1093
  "@id" => ["foo", {"@id" => "foo"}, {"@id" => "foo"}],
1342
- "integer" => ["foo", {"@value" => "54", "@type" => "xsd:integer"}, {"@value" => "54", "@type" => "xsd:integer"}],
1343
- "date" => ["foo", {"@value" => "2011-12-27Z","@type" => "xsd:date"},{"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1094
+ "integer" => ["foo", {"@value" => "54", "@type" => RDF::XSD.integer.to_s}, {"@value" => "54", "@type" => RDF::XSD.integer.to_s}],
1095
+ "date" => ["foo", {"@value" => "2011-12-27Z","@type" => RDF::XSD.date.to_s},{"@value" => "2011-12-27Z", "@type" => RDF::XSD.date.to_s}],
1344
1096
  "no lang" => ["foo", {"@value" => "foo" }, {"@value" => "foo"}],
1345
1097
  "same lang" => ["foo", "foo", {"@value" => "foo", "@language" => "en"}],
1346
1098
  "other lang" => ["foo", {"@value" => "foo", "@language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
@@ -1364,12 +1116,6 @@ describe JSON::LD::EvaluationContext do
1364
1116
  end
1365
1117
  end
1366
1118
 
1367
- [[], true, false, 1, 1.1, "string"].each do |v|
1368
- it "raises error given #{v.class}" do
1369
- lambda {subject.compact_value("foo", v)}.should raise_error(JSON::LD::ProcessingError::Lossy)
1370
- end
1371
- end
1372
-
1373
1119
  context "keywords" do
1374
1120
  before(:each) do
1375
1121
  subject.set_mapping("id", "@id")
@@ -1385,8 +1131,6 @@ describe JSON::LD::EvaluationContext do
1385
1131
  "@type" => [{"literal" => "foo", "type" => "http://example.com/"},
1386
1132
  {"@value" => "foo", "@type" => "http://example.com/"}],
1387
1133
  "@value" => [{"literal" => "foo", "language" => "bar"}, {"@value" => "foo", "@language" => "bar"}],
1388
- "@list" => [{"list" => ["foo"]}, {"@list" => ["foo"] }],
1389
- "@set" => [{"set" => ["foo"]}, {"@set" => ["foo"] }],
1390
1134
  }.each do |title, (compacted, expanded)|
1391
1135
  it title do
1392
1136
  subject.compact_value("foo", expanded).should produce(compacted, @debug)