json-ld 0.1.6.1 → 0.3.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.
@@ -47,7 +47,7 @@ module JSON::LD
47
47
  active_subject = if element.fetch('@id', nil).is_a?(String)
48
48
  # 1.5 Subject
49
49
  # 1.5.1 Set active object (subject)
50
- context.expand_iri(element['@id'], :quite => true)
50
+ context.expand_iri(element['@id'], :quiet => true)
51
51
  else
52
52
  # 1.6) Generate a blank node identifier and set it as the active subject.
53
53
  node
@@ -73,7 +73,7 @@ module JSON::LD
73
73
  else
74
74
  # 1.7.1) If a key that is not @id, @graph, or @type, set the active property by
75
75
  # performing Property Processing on the key.
76
- context.expand_iri(key, :quite => true)
76
+ context.expand_iri(key, :quiet => true)
77
77
  end
78
78
 
79
79
  debug("statements[Step 1.7.4]")
@@ -171,7 +171,7 @@ module JSON::LD
171
171
  # @yieldparam [RDF::Statement] :statement
172
172
  def add_quad(path, subject, predicate, object, name)
173
173
  predicate = RDF.type if predicate == '@type'
174
- object = RDF::URI(object.to_s) if object.literal? && predicate == RDF.type
174
+ object = context.expand_iri(object.to_s, :quiet => true) if object.literal? && predicate == RDF.type
175
175
  statement = RDF::Statement.new(subject, predicate, object, :context => name)
176
176
  debug(path) {"statement: #{statement.to_nquads}"}
177
177
  yield statement
@@ -262,22 +262,22 @@ describe JSON::LD::API do
262
262
 
263
263
  context "term selection" do
264
264
  {
265
- #"Uses term with nil language when two terms conflict on language" => {
266
- # :input => [{
267
- # "http://example.com/term" => {"@value" => "v1", "@language" => nil}
268
- # }],
269
- # :context => {
270
- # "term5" => {"@id" => "http://example.com/term","@language" => nil},
271
- # "@language" => "de"
272
- # },
273
- # :output => {
274
- # "@context" => {
275
- # "term5" => {"@id" => "http://example.com/term","@language" => nil},
276
- # "@language" => "de"
277
- # },
278
- # "term5" => "v1",
279
- # }
280
- #},
265
+ "Uses term with nil language when two terms conflict on language" => {
266
+ :input => [{
267
+ "http://example.com/term" => {"@value" => "v1", "@language" => nil}
268
+ }],
269
+ :context => {
270
+ "term5" => {"@id" => "http://example.com/term","@language" => nil},
271
+ "@language" => "de"
272
+ },
273
+ :output => {
274
+ "@context" => {
275
+ "term5" => {"@id" => "http://example.com/term","@language" => nil},
276
+ "@language" => "de"
277
+ },
278
+ "term5" => "v1",
279
+ }
280
+ },
281
281
  "Uses subject alias" => {
282
282
  :input => [{
283
283
  "@id" => "http://example.com/id1"
@@ -314,10 +314,90 @@ describe JSON::LD::API do
314
314
  "comment_en" => "comment in english",
315
315
  }
316
316
  },
317
+ "compact-0018" => {
318
+ :context => %{{
319
+ "id1": "http://example.com/id1",
320
+ "type1": "http://example.com/t1",
321
+ "type2": "http://example.com/t2",
322
+ "@language": "de",
323
+ "term": { "@id": "http://example.com/term" },
324
+ "term1": { "@id": "http://example.com/term", "@container": "@list" },
325
+ "term2": { "@id": "http://example.com/term", "@container": "@list", "@language": "en" }
326
+ }},
327
+ :input => %{{
328
+ "http://example.com/term": [
329
+ {
330
+ "@list": [
331
+ { "@value": "v1.1", "@language": "de" },
332
+ { "@value": "v1.2", "@language": "de" },
333
+ { "@value": "v1.3", "@language": "de" },
334
+ 4,
335
+ { "@value": "v1.5", "@language": "de" },
336
+ { "@value": "v1.6", "@language": "en" }
337
+ ]
338
+ },
339
+ {
340
+ "@list": [
341
+ { "@value": "v2.1", "@language": "en" },
342
+ { "@value": "v2.2", "@language": "en" },
343
+ { "@value": "v2.3", "@language": "en" },
344
+ 4,
345
+ { "@value": "v2.5", "@language": "en" },
346
+ { "@value": "v2.6", "@language": "de" }
347
+ ]
348
+ }
349
+ ]
350
+ }},
351
+ :output => %q{{
352
+ "@context": {
353
+ "id1": "http://example.com/id1",
354
+ "type1": "http://example.com/t1",
355
+ "type2": "http://example.com/t2",
356
+ "@language": "de",
357
+ "term": {
358
+ "@id": "http://example.com/term"
359
+ },
360
+ "term1": {
361
+ "@id": "http://example.com/term",
362
+ "@container": "@list"
363
+ },
364
+ "term2": {
365
+ "@id": "http://example.com/term",
366
+ "@container": "@list",
367
+ "@language": "en"
368
+ }
369
+ },
370
+ "term1": [
371
+ "v1.1",
372
+ "v1.2",
373
+ "v1.3",
374
+ 4,
375
+ "v1.5",
376
+ {
377
+ "@value": "v1.6",
378
+ "@language": "en"
379
+ }
380
+ ],
381
+ "term2": [
382
+ "v2.1",
383
+ "v2.2",
384
+ "v2.3",
385
+ 4,
386
+ "v2.5",
387
+ {
388
+ "@value": "v2.6",
389
+ "@language": "de"
390
+ }
391
+ ]
392
+ }}
393
+ }
317
394
  }.each_pair do |title, params|
318
395
  it title do
319
- jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
320
- jld.should produce(params[:output], @debug)
396
+ input = params[:input].is_a?(String) ? JSON.parse(params[:input]) : params[:input]
397
+ ctx = params[:context].is_a?(String) ? JSON.parse(params[:context]) : params[:context]
398
+ output = params[:output].is_a?(String) ? JSON.parse(params[:output]) : params[:output]
399
+ jld = JSON::LD::API.compact(input, ctx, nil, :debug => @debug)
400
+ jld.should produce(output, @debug)
321
401
  end
322
402
  end
323
403
  end
@@ -357,6 +437,36 @@ describe JSON::LD::API do
357
437
  end
358
438
  end
359
439
 
440
+ context "@list" do
441
+ {
442
+ "1 term 2 lists 2 languages" => {
443
+ :input => [{
444
+ "http://example.com/foo" => [
445
+ {"@list" => [{"@value" => "en", "@language" => "en"}]},
446
+ {"@list" => [{"@value" => "de", "@language" => "de"}]}
447
+ ]
448
+ }],
449
+ :context => {
450
+ "foo_en" => {"@id" => "http://example.com/foo", "@container" => "@list", "@language" => "en"},
451
+ "foo_de" => {"@id" => "http://example.com/foo", "@container" => "@list", "@language" => "de"}
452
+ },
453
+ :output => {
454
+ "@context" => {
455
+ "foo_en" => {"@id" => "http://example.com/foo", "@container" => "@list", "@language" => "en"},
456
+ "foo_de" => {"@id" => "http://example.com/foo", "@container" => "@list", "@language" => "de"}
457
+ },
458
+ "foo_en" => ["en"],
459
+ "foo_de" => ["de"]
460
+ }
461
+ },
462
+ }.each_pair do |title, params|
463
+ it title do
464
+ jld = JSON::LD::API.compact(params[:input], params[:context], nil, :debug => @debug)
465
+ jld.should produce(params[:output], @debug)
466
+ end
467
+ end
468
+ end
469
+
360
470
  context "@graph" do
361
471
  {
362
472
  "Uses @graph given mutliple inputs" => {
@@ -513,7 +513,7 @@ describe JSON::LD::EvaluationContext do
513
513
  subject.serialize.should produce({
514
514
  "@context" => {
515
515
  "@vocab" => 'http://example.org/',
516
- "term" => {"@id" => "term", "@type" => "datatype"}
516
+ "term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
517
517
  }
518
518
  }, @debug)
519
519
  end
@@ -549,8 +549,7 @@ describe JSON::LD::EvaluationContext do
549
549
  {
550
550
  :subject => true,
551
551
  :predicate => false,
552
- :object => true,
553
- :datatype => false
552
+ :type => false
554
553
  }.each do |position, r|
555
554
  context "as #{position}" do
556
555
  {
@@ -580,8 +579,7 @@ describe JSON::LD::EvaluationContext do
580
579
  {
581
580
  :subject => true,
582
581
  :predicate => false,
583
- :object => true,
584
- :datatype => false
582
+ :type => false
585
583
  }.each do |position, r|
586
584
  context "as #{position}" do
587
585
  before(:each) do
@@ -610,8 +608,7 @@ describe JSON::LD::EvaluationContext do
610
608
  {
611
609
  :subject => false,
612
610
  :predicate => true,
613
- :object => false,
614
- :datatype => true
611
+ :type => true
615
612
  }.each do |position, r|
616
613
  context "as #{position}" do
617
614
  {
@@ -661,7 +658,7 @@ describe JSON::LD::EvaluationContext do
661
658
  {
662
659
  "absolute IRI" => ["http://example.com/", "http://example.com/"],
663
660
  "term" => ["ex", "http://example.org/"],
664
- "prefix:suffix" => ["suffix", "http://example.org/suffix"],
661
+ "prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
665
662
  "keyword" => ["@type", "@type"],
666
663
  "empty" => [":suffix", "http://empty/suffix"],
667
664
  "unmapped" => ["foo", "foo"],
@@ -750,6 +747,32 @@ describe JSON::LD::EvaluationContext do
750
747
  end
751
748
  end
752
749
  end
750
+
751
+ context "compact-0020" do
752
+ let(:ctx) do
753
+ subject.parse({
754
+ "ex" => "http://example.org/ns#",
755
+ "ex:property" => {"@container" => "@list"}
756
+ })
757
+ end
758
+ it "Compact @id that is a property IRI when @container is @list" do
759
+ ctx.compact_iri("http://example.org/ns#property", :position => :subject).
760
+ should produce("ex:property", @debug)
761
+ end
762
+ end
763
+
764
+ context "compact-0021" do
765
+ let(:ctx) do
766
+ subject.parse({
767
+ "@vocab" => "http://example.com/",
768
+ "sub" => "http://example.com/subdir/"
769
+ })
770
+ end
771
+ it "Compact properties and types using @vocab" do
772
+ ctx.compact_iri("http://example.com/subdir/id/1", :position => :subject).
773
+ should produce("sub:id/1", @debug)
774
+ end
775
+ end
753
776
  end
754
777
 
755
778
  describe "#term_rank" do
@@ -964,6 +987,40 @@ describe JSON::LD::EvaluationContext do
964
987
  end
965
988
  end
966
989
  end
990
+
991
+ context "compact-0018" do
992
+ let(:ctx) do
993
+ subject.parse({
994
+ "@language" => "de",
995
+ "term1" => {"@id" => "http://example/term"},
996
+ "term2" => {"@id" => "http://example/term", "@language" => "en"}
997
+ })
998
+ end
999
+ {
1000
+ "v1.1" => [{"@value" => "v1.1", "@language" => "de"}, 3, 0],
1001
+ "v1.2" => [{"@value" => "v1.2", "@language" => "de"}, 3, 0],
1002
+ "v1.3" => [{"@value" => "v1.3", "@language" => "de"}, 3, 0],
1003
+ "v1.4" => [{"@value" => 4}, 2, 1],
1004
+ "v1.5" => [{"@value" => "v1.5", "@language" => "de"}, 3, 0],
1005
+ "v1.6" => [{"@value" => "v1.6", "@language" => "en"}, 1, 3],
1006
+ "v2.1" => [{"@value" => "v2.1", "@language" => "en"}, 1, 3],
1007
+ "v2.2" => [{"@value" => "v2.2", "@language" => "en"}, 1, 3],
1008
+ "v2.3" => [{"@value" => "v2.3", "@language" => "en"}, 1, 3],
1009
+ "v2.4" => [{"@value" => 4}, 2, 1],
1010
+ "v2.5" => [{"@value" => "v2.5", "@language" => "en"}, 1, 3],
1011
+ "v2.6" => [{"@value" => "v2.6", "@language" => "de"}, 3, 0],
1012
+ }.each do |label, (val, r1, r2)|
1013
+ context label do
1014
+ it "has rank #{r1} for term1" do
1015
+ ctx.send(:term_rank, "term1", val).should produce(r1, @debug)
1016
+ end
1017
+
1018
+ it "has rank #{r2} for term2" do
1019
+ ctx.send(:term_rank, "term2", val).should produce(r2, @debug)
1020
+ end
1021
+ end
1022
+ end
1023
+ end
967
1024
  end
968
1025
  end
969
1026
 
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD::Resource do
6
+ it "is pending"
7
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD do
6
+ describe "test suite" do
7
+ require 'suite_helper'
8
+ m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/compact-manifest.jsonld')
9
+ describe m.name do
10
+ m.entries.each do |t|
11
+ specify "#{t.property('input')}: #{t.name}" do
12
+ begin
13
+ pending("resolution of term rank in compact-0018") if t.property('input') == 'compact-0018-in.jsonld'
14
+ t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
15
+ t.debug << "context: #{t.context.read}" if t.property('context')
16
+ result = JSON::LD::API.compact(t.input, t.context, nil,
17
+ :base => t.base,
18
+ :debug => t.debug)
19
+ expected = JSON.load(t.expect)
20
+ result.should produce(expected, t.debug)
21
+ rescue JSON::LD::ProcessingError => e
22
+ fail("Processing error: #{e.message}")
23
+ rescue JSON::LD::InvalidContext => e
24
+ fail("Invalid Context: #{e.message}")
25
+ rescue JSON::LD::InvalidFrame => e
26
+ fail("Invalid Frame: #{e.message}")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end unless ENV['CI']
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD do
6
+ describe "test suite" do
7
+ require 'suite_helper'
8
+ m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/expand-manifest.jsonld')
9
+ describe m.name do
10
+ m.entries.each do |t|
11
+ specify "#{t.property('input')}: #{t.name}" do
12
+ begin
13
+ case t.property('input')
14
+ when /expand-0029/
15
+ pending("resolution of @type resolution in expand-0029")
16
+ when /expand-0030/
17
+ pending("implementation of language maps")
18
+ end
19
+ t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
20
+ t.debug << "context: #{t.context.read}" if t.property('context')
21
+ result = JSON::LD::API.expand(t.input, nil, nil,
22
+ :base => t.base,
23
+ :debug => t.debug)
24
+ expected = JSON.load(t.expect)
25
+ result.should produce(expected, t.debug)
26
+ rescue JSON::LD::ProcessingError => e
27
+ fail("Processing error: #{e.message}")
28
+ rescue JSON::LD::InvalidContext => e
29
+ fail("Invalid Context: #{e.message}")
30
+ rescue JSON::LD::InvalidFrame => e
31
+ fail("Invalid Frame: #{e.message}")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end unless ENV['CI']
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD do
6
+ describe "test suite" do
7
+ require 'suite_helper'
8
+ require 'suite_helper'
9
+ m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/frame-manifest.jsonld')
10
+ describe m.name do
11
+ m.entries.each do |t|
12
+ specify "#{t.property('input')}: #{t.name}" do
13
+ begin
14
+ t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
15
+ t.debug << "frame: #{t.frame.read}" if t.property('frame')
16
+ result = JSON::LD::API.frame(t.input, t.frame, nil,
17
+ :base => t.base,
18
+ :debug => t.debug)
19
+ expected = JSON.load(t.expect)
20
+ result.should produce(expected, t.debug)
21
+ rescue JSON::LD::ProcessingError => e
22
+ fail("Processing error: #{e.message}")
23
+ rescue JSON::LD::InvalidContext => e
24
+ fail("Invalid Context: #{e.message}")
25
+ rescue JSON::LD::InvalidFrame => e
26
+ fail("Invalid Frame: #{e.message}")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end unless ENV['CI']
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+
5
+ describe JSON::LD do
6
+ describe "test suite" do
7
+ require 'suite_helper'
8
+ m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/fromRdf-manifest.jsonld')
9
+ describe m.name do
10
+ m.entries.each do |t|
11
+ specify "#{t.property('input')}: #{t.name}" do
12
+ begin
13
+ t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
14
+ t.input.rewind
15
+ t.debug << "result: #{t.expect.read}"
16
+ repo = RDF::Repository.load(t.base)
17
+ t.debug << "repo: #{repo.dump(:trig)}"
18
+ result = JSON::LD::API.fromRDF(repo.each_statement.to_a, nil,
19
+ :debug => t.debug)
20
+ expected = JSON.load(t.expect)
21
+ result.should produce(expected, t.debug)
22
+ rescue JSON::LD::ProcessingError => e
23
+ fail("Processing error: #{e.message}")
24
+ rescue JSON::LD::InvalidContext => e
25
+ fail("Invalid Context: #{e.message}")
26
+ rescue JSON::LD::InvalidFrame => e
27
+ fail("Invalid Frame: #{e.message}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end unless ENV['CI']