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
@@ -5,18 +5,21 @@ require 'spec_helper'
5
5
  describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/compact-manifest.jsonld')
9
- describe m.name, :pending => "Major update" do
8
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/compact-manifest.jsonld")
9
+ describe m.name do
10
10
  m.entries.each do |t|
11
11
  specify "#{t.property('input')}: #{t.name}" do
12
12
  begin
13
- case t.property('input')
14
- when /compact-(0032|0033|0034)/
15
- pending("undesireable property generator corner cases")
16
- end
13
+ #case t.property('input')
14
+ #when /compact-(0032|0033|0034)/
15
+ # pending("undesireable property generator corner cases")
16
+ #end
17
17
  t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
18
- t.debug << "context: #{t.context.read}" if t.property('context')
19
- result = JSON::LD::API.compact(t.input, t.context, nil,
18
+ if t.property('context')
19
+ t.debug << "context: #{t.context.read}"
20
+ t.context.rewind
21
+ end
22
+ result = JSON::LD::API.compact(t.input, t.context,
20
23
  :base => t.base,
21
24
  :debug => t.debug)
22
25
  expected = JSON.load(t.expect)
@@ -0,0 +1,23 @@
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("#{Fixtures::SuiteTest::SUITE}tests/error-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
+ t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
14
+ t.debug << "context: #{t.context.read}" if t.property('context')
15
+ lambda {
16
+ JSON::LD::API.expand(t.input, nil, :base => t.base, :validate => true)
17
+ }.should raise_error
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end unless ENV['CI']
@@ -5,18 +5,14 @@ require 'spec_helper'
5
5
  describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/expand-manifest.jsonld')
9
- describe m.name, :pending => "Major update" do
8
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/expand-manifest.jsonld")
9
+ describe m.name do
10
10
  m.entries.each do |t|
11
11
  specify "#{t.property('input')}: #{t.name}" do
12
12
  begin
13
- case t.property('input')
14
- when /expand-(0039)/
15
- pending("As if!")
16
- end
17
13
  t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
18
14
  t.debug << "context: #{t.context.read}" if t.property('context')
19
- result = JSON::LD::API.expand(t.input, nil, nil,
15
+ result = JSON::LD::API.expand(t.input, nil,
20
16
  :base => t.base,
21
17
  :debug => t.debug)
22
18
  expected = JSON.load(t.expect)
@@ -6,14 +6,14 @@ describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
8
  require 'suite_helper'
9
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/flatten-manifest.jsonld')
10
- describe m.name, :pending => "New flattening algorithm" do
9
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/flatten-manifest.jsonld")
10
+ describe m.name do
11
11
  m.entries.each do |t|
12
12
  specify "#{t.property('input')}: #{t.name}" do
13
13
  begin
14
14
  t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
15
15
  t.debug << "frame: #{t.frame.read}" if t.property('frame')
16
- result = JSON::LD::API.flatten(t.input, nil, t.context, nil,
16
+ result = JSON::LD::API.flatten(t.input, t.context,
17
17
  :base => t.base,
18
18
  :debug => t.debug)
19
19
  expected = JSON.load(t.expect)
@@ -6,24 +6,24 @@ describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
8
  require 'suite_helper'
9
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/frame-manifest.jsonld')
10
- describe m.name, :pending => "New framing algorithm" do
9
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/frame-manifest.jsonld")
10
+ describe m.name do
11
11
  m.entries.each do |t|
12
12
  specify "#{t.property('input')}: #{t.name}" do
13
13
  begin
14
14
  t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
15
15
  t.debug << "frame: #{t.frame.read}" if t.property('frame')
16
- result = JSON::LD::API.frame(t.input, t.frame, nil,
16
+ result = JSON::LD::API.frame(t.input, t.frame,
17
17
  :base => t.base,
18
18
  :debug => t.debug)
19
19
  expected = JSON.load(t.expect)
20
20
  result.should produce(expected, t.debug)
21
21
  rescue JSON::LD::ProcessingError => e
22
- fail("Processing error: #{e.message}")
22
+ fail("Processing error: #{e.message}\n#{t.debug.join("\n")}\n#{e.backtrace.join("\n")}}")
23
23
  rescue JSON::LD::InvalidContext => e
24
- fail("Invalid Context: #{e.message}")
24
+ fail("Invalid Context: #{e.message}\n#{t.debug.join("\n")}\n#{e.backtrace.join("\n")}}")
25
25
  rescue JSON::LD::InvalidFrame => e
26
- fail("Invalid Frame: #{e.message}")
26
+ fail("Invalid Frame: #{e.message}\n#{t.debug.join("\n")}\n#{e.backtrace.join("\n")}}")
27
27
  end
28
28
  end
29
29
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/fromRdf-manifest.jsonld')
8
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/fromRdf-manifest.jsonld")
9
9
  describe m.name do
10
10
  m.entries.each do |t|
11
11
  specify "#{t.property('input')}: #{t.name}" do
@@ -14,8 +14,8 @@ describe JSON::LD do
14
14
  t.input.rewind
15
15
  t.debug << "result: #{t.expect.read}"
16
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,
17
+ t.debug << "repo: #{repo.dump(t.id == '#t0012' ? :nquads : :trig)}"
18
+ result = JSON::LD::API.fromRDF(repo.each_statement.to_a,
19
19
  :debug => t.debug)
20
20
  expected = JSON.load(t.expect)
21
21
  result.should produce(expected, t.debug)
@@ -48,11 +48,10 @@ module RDF::Util
48
48
  else
49
49
  Kernel.open(filename_or_url.to_s, &block)
50
50
  end
51
- rescue Errno::ENOENT
51
+ rescue Errno::ENOENT #, OpenURI::HTTPError
52
52
  # Not there, don't run tests
53
53
  StringIO.new("")
54
54
  end
55
- else
56
55
  end
57
56
  end
58
57
  end
@@ -66,7 +65,11 @@ module Fixtures
66
65
  #puts "open: #{file}"
67
66
  RDF::Util::File.open_file(file) do |f|
68
67
  json = JSON.parse(f.read)
69
- self.from_jsonld(json)
68
+ if block_given?
69
+ yield self.from_jsonld(json)
70
+ else
71
+ self.from_jsonld(json)
72
+ end
70
73
  end
71
74
  end
72
75
 
@@ -94,11 +97,15 @@ module Fixtures
94
97
 
95
98
  # Alias input, context, expect and frame
96
99
  %w(input context expect frame).each do |m|
97
- define_method(m.to_sym) {RDF::Util::File.open_file "#{SUITE}tests/#{property(m)}"}
100
+ define_method(m.to_sym) {property(m) && RDF::Util::File.open_file("#{SUITE}tests/#{property(m)}")}
101
+ end
102
+
103
+ def testType
104
+ property('@type').reject {|t| t =~ /EvaluationTest/}.first
98
105
  end
99
106
 
100
- def positiveTest
101
- property('positiveTest') == 'true'
107
+ def positiveTest?
108
+ property('@type').include?('jld:PositiveEvaluationTest')
102
109
  end
103
110
 
104
111
  def trace; @debug.join("\n"); end
@@ -5,17 +5,17 @@ require 'spec_helper'
5
5
  describe JSON::LD do
6
6
  describe "test suite" do
7
7
  require 'suite_helper'
8
- m = Fixtures::SuiteTest::Manifest.open('http://json-ld.org/test-suite/tests/toRdf-manifest.jsonld')
9
- describe m.name, :pending => "Major update" do
8
+ m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}tests/toRdf-manifest.jsonld")
9
+ describe m.name do
10
10
  m.entries.each do |t|
11
11
  specify "#{t.property('input')}: #{t.name}" do
12
12
  begin
13
13
  t.debug = ["test: #{t.inspect}", "source: #{t.input.read}"]
14
- quads = []
15
- JSON::LD::API.toRDF(t.input, nil, nil,
16
- :base => t.base,
17
- :debug => t.debug) do |statement|
18
- quads << to_quad(statement)
14
+ quads = JSON::LD::API.toRDF(t.input, nil,
15
+ :base => t.base,
16
+ :debug => t.debug
17
+ ).map do |statement|
18
+ to_quad(statement)
19
19
  end
20
20
 
21
21
  sorted_expected = t.expect.readlines.sort.join("")
@@ -51,9 +51,15 @@ describe JSON::LD do
51
51
  %("#{i}.#{f}E#{e}"^^<http://www.w3.org/2001/XMLSchema#double>)
52
52
  end
53
53
  when RDF::Literal
54
- quoted(escaped(thing.value)) +
55
- (thing.datatype? ? "^^<#{thing.datatype}>" : "") +
56
- (thing.language? ? "@#{thing.language}" : "")
54
+ v = quoted(escaped(thing.value))
55
+ case thing.datatype
56
+ when nil, "http://www.w3.org/2001/XMLSchema#string", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
57
+ # Ignore these
58
+ else
59
+ v += "^^<#{thing.datatype}>"
60
+ end
61
+ v += "@#{thing.language}" if thing.language
62
+ v
57
63
  when RDF::Statement
58
64
  thing.to_quad.map {|r| to_quad(r)}.compact.join(" ") + " .\n"
59
65
  end
@@ -1,7 +1,8 @@
1
1
  @prefix avatar: <http://xmlns.com/foaf/0.1/avatar> .
2
2
  @prefix homepage: <http://xmlns.com/foaf/0.1/homepage> .
3
3
  @prefix name: <http://xmlns.com/foaf/0.1/name> .
4
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4
5
 
5
- [ avatar: "http://twitter.com/account/profile_image/manusporny";
6
- homepage: "http://manu.sporny.org/";
7
- name: "Manu Sporny"] .
6
+ [ avatar: "http://twitter.com/account/profile_image/manusporny"^^xsd:string;
7
+ homepage: "http://manu.sporny.org/"^^xsd:string;
8
+ name: "Manu Sporny"^^xsd:string] .
@@ -1,7 +1,8 @@
1
1
  @prefix age: <http://xmlns.com/foaf/0.1/age> .
2
2
  @prefix homepage: <http://xmlns.com/foaf/0.1/homepage> .
3
3
  @prefix name: <http://xmlns.com/foaf/0.1/name> .
4
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4
5
 
5
6
  [ age: 41;
6
7
  homepage: <http://manu.sporny.org/>;
7
- name: "Manu Sporny"] .
8
+ name: "Manu Sporny"^^xsd:string] .
@@ -6,5 +6,5 @@
6
6
  "@id": ":#me",
7
7
  "@type": "foaf:Person",
8
8
  "foaf:name": "Manu Sporny",
9
- "foaf:homepage": { "@id": "" }
9
+ "foaf:homepage": { "@id": "http://manu.sporny.org/" }
10
10
  }
@@ -1,6 +1,7 @@
1
1
  @prefix foaf: <http://xmlns.com/foaf/0.1/> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
2
3
 
3
4
  <http://manu.sporny.org/#me> a foaf:Person;
4
5
  foaf:knows [ a foaf:Person;
5
- foaf:name "Gregg Kellogg"];
6
- foaf:name "Manu Sporny" .
6
+ foaf:name "Gregg Kellogg"^^xsd:string];
7
+ foaf:name "Manu Sporny"^^xsd:string .
@@ -1,5 +1,6 @@
1
1
  @prefix foaf: <http://xmlns.com/foaf/0.1/> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
2
3
 
3
4
  <http://example.org/people#joebob> a foaf:Person;
4
- foaf:name "Joe Bob";
5
- foaf:nick ("joe" "bob" "jaybe") .
5
+ foaf:name "Joe Bob"^^xsd:string;
6
+ foaf:nick ("joe"^^xsd:string "bob"^^xsd:string "jaybe"^^xsd:string) .
@@ -2,19 +2,19 @@
2
2
  "@context": { "foaf": "http://xmlns.com/foaf/0.1/" },
3
3
  "@graph": [
4
4
  {
5
- "@id": "_:t0",
5
+ "@id": "_:bnode1",
6
6
  "@type": "foaf:Person",
7
7
  "foaf:homepage": "http://example.com/bob/",
8
8
  "foaf:name": "Bob"
9
9
  },
10
10
  {
11
- "@id": "_:t1",
11
+ "@id": "_:bnode2",
12
12
  "@type": "foaf:Person",
13
13
  "foaf:homepage": "http://example.com/eve/",
14
14
  "foaf:name": "Eve"
15
15
  },
16
16
  {
17
- "@id": "_:t2",
17
+ "@id": "_:bnode3",
18
18
  "@type": "foaf:Person",
19
19
  "foaf:homepage": "http://example.com/manu/",
20
20
  "foaf:name": "Manu"
@@ -1,18 +1,18 @@
1
1
  [
2
2
  {
3
- "@id": "_:t0",
3
+ "@id": "_:bnode1",
4
4
  "@type": ["http://xmlns.com/foaf/0.1/Person"],
5
5
  "http://xmlns.com/foaf/0.1/homepage": [{"@value": "http://example.com/bob/"}],
6
6
  "http://xmlns.com/foaf/0.1/name": [{"@value": "Bob"}]
7
7
  },
8
8
  {
9
- "@id": "_:t1",
9
+ "@id": "_:bnode2",
10
10
  "@type": ["http://xmlns.com/foaf/0.1/Person"],
11
11
  "http://xmlns.com/foaf/0.1/homepage": [{"@value": "http://example.com/eve/"}],
12
12
  "http://xmlns.com/foaf/0.1/name": [{"@value": "Eve"}]
13
13
  },
14
14
  {
15
- "@id": "_:t2",
15
+ "@id": "_:bnode3",
16
16
  "@type": ["http://xmlns.com/foaf/0.1/Person"],
17
17
  "http://xmlns.com/foaf/0.1/homepage": [{"@value": "http://example.com/manu/"}],
18
18
  "http://xmlns.com/foaf/0.1/name": [{"@value": "Manu"}]
@@ -1,13 +1,14 @@
1
1
  @prefix foaf: <http://xmlns.com/foaf/0.1/> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
2
3
 
3
4
  [ a foaf:Person;
4
- foaf:homepage "http://example.com/manu/";
5
- foaf:name "Manu"] .
5
+ foaf:homepage "http://example.com/manu/"^^xsd:string;
6
+ foaf:name "Manu"^^xsd:string] .
6
7
 
7
8
  [ a foaf:Person;
8
- foaf:homepage "http://example.com/eve/";
9
- foaf:name "Eve"] .
9
+ foaf:homepage "http://example.com/eve/"^^xsd:string;
10
+ foaf:name "Eve"^^xsd:string] .
10
11
 
11
12
  [ a foaf:Person;
12
- foaf:homepage "http://example.com/bob/";
13
- foaf:name "Bob"] .
13
+ foaf:homepage "http://example.com/bob/"^^xsd:string;
14
+ foaf:name "Bob"^^xsd:string] .
@@ -10,7 +10,7 @@
10
10
  "term5": {"@id": "http://example.com/term", "@language": null},
11
11
  "@language": "de"
12
12
  },
13
- "@id": "id1",
13
+ "@id": "http://example.com/id1",
14
14
  "@type": "t1",
15
15
  "term1": "v1",
16
16
  "term2": "v2",
@@ -12,18 +12,19 @@ describe JSON::LD::API do
12
12
  %q({
13
13
  "http://example.com/foo": "bar"
14
14
  }),
15
- %q([ <http://example.com/foo> "bar"] .)
15
+ %q([ <http://example.com/foo> "bar"^^xsd:string] .)
16
16
  ],
17
17
  "@id with _:a" => [
18
18
  %q({
19
19
  "@id": "_:a",
20
20
  "http://example.com/foo": "bar"
21
21
  }),
22
- %q([ <http://example.com/foo> "bar"] .)
22
+ %q([ <http://example.com/foo> "bar"^^xsd:string] .)
23
23
  ],
24
- }.each do |title, (js, nt)|
24
+ }.each do |title, (js, ttl)|
25
25
  it title do
26
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
26
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
27
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
27
28
  end
28
29
  end
29
30
  end
@@ -37,17 +38,10 @@ describe JSON::LD::API do
37
38
  }),
38
39
  %q(<http://example.com/a> <http://example.com/foo> "bar" .)
39
40
  ],
40
- "with empty term" => [
41
- %({
42
- "@context": {"": "http://example.com/"},
43
- "@id": "",
44
- "@type": "#{RDF::RDFS.Resource}"
45
- }),
46
- %(<http://example.com/> a <#{RDF::RDFS.Resource}>)
47
- ],
48
- }.each do |title, (js, nt)|
41
+ }.each do |title, (js, ttl)|
49
42
  it title do
50
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
43
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
44
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
51
45
  end
52
46
  end
53
47
 
@@ -74,9 +68,10 @@ describe JSON::LD::API do
74
68
  }),
75
69
  %(<http://example.org/#a> a <#{RDF::RDFS.Resource}>)
76
70
  ],
77
- }.each do |title, (js, nt)|
71
+ }.each do |title, (js, ttl)|
78
72
  it title do
79
- parse(js, :base => "http://example.org/").should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
73
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
74
+ parse(js, :base => "http://example.org/").should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
80
75
  end
81
76
  end
82
77
  end
@@ -102,9 +97,10 @@ describe JSON::LD::API do
102
97
  }),
103
98
  %q([ a _:foo ] .)
104
99
  ]
105
- }.each do |title, (js, nt)|
100
+ }.each do |title, (js, ttl)|
106
101
  it title do
107
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
102
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
103
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
108
104
  end
109
105
  end
110
106
  end
@@ -115,13 +111,13 @@ describe JSON::LD::API do
115
111
  %q({
116
112
  "http://example.com/foo": "bar"
117
113
  }),
118
- %q([ <http://example.com/foo> "bar" ] .)
114
+ %q([ <http://example.com/foo> "bar"^^xsd:string ] .)
119
115
  ],
120
116
  "strings" => [
121
117
  %q({
122
118
  "http://example.com/foo": ["bar", "baz"]
123
119
  }),
124
- %q([ <http://example.com/foo> "bar", "baz" ] .)
120
+ %q([ <http://example.com/foo> "bar"^^xsd:string, "baz"^^xsd:string ] .)
125
121
  ],
126
122
  "IRI" => [
127
123
  %q({
@@ -135,9 +131,10 @@ describe JSON::LD::API do
135
131
  }),
136
132
  %q([ <http://example.com/foo> <http://example.com/bar>, <http://example.com/baz> ] .)
137
133
  ],
138
- }.each do |title, (js, nt)|
134
+ }.each do |title, (js, ttl)|
139
135
  it title do
140
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
136
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
137
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
141
138
  end
142
139
  end
143
140
  end
@@ -152,7 +149,7 @@ describe JSON::LD::API do
152
149
  "explicit plain literal" =>
153
150
  [
154
151
  %q({"http://xmlns.com/foaf/0.1/name": {"@value": "Gregg Kellogg"}}),
155
- %q(_:a <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .)
152
+ %q(_:a <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg"^^xsd:string .)
156
153
  ],
157
154
  "language tagged literal" =>
158
155
  [
@@ -183,9 +180,10 @@ describe JSON::LD::API do
183
180
  <http://greggkellogg.net/foaf#me> <http://purl.org/dc/terms/created> "1957-02-27"^^<http://www.w3.org/2001/XMLSchema#date> .
184
181
  )
185
182
  ],
186
- }.each do |title, (js, nt)|
183
+ }.each do |title, (js, ttl)|
187
184
  it title do
188
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
185
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
186
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
189
187
  end
190
188
  end
191
189
  end
@@ -194,19 +192,20 @@ describe JSON::LD::API do
194
192
  {
195
193
  "empty prefix" => [
196
194
  %q({"@context": {"": "http://example.com/default#"}, ":foo": "bar"}),
197
- %q(_:a <http://example.com/default#foo> "bar" .)
195
+ %q(_:a <http://example.com/default#foo> "bar"^^xsd:string .)
198
196
  ],
199
197
  "empty suffix" => [
200
198
  %q({"@context": {"prefix": "http://example.com/default#"}, "prefix:": "bar"}),
201
- %q(_:a <http://example.com/default#> "bar" .)
199
+ %q(_:a <http://example.com/default#> "bar"^^xsd:string .)
202
200
  ],
203
201
  "prefix:suffix" => [
204
202
  %q({"@context": {"prefix": "http://example.com/default#"}, "prefix:foo": "bar"}),
205
- %q(_:a <http://example.com/default#foo> "bar" .)
203
+ %q(_:a <http://example.com/default#foo> "bar"^^xsd:string .)
206
204
  ]
207
- }.each_pair do |title, (js, nt)|
205
+ }.each_pair do |title, (js, ttl)|
208
206
  it title do
209
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
207
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
208
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
210
209
  end
211
210
  end
212
211
  end
@@ -222,12 +221,13 @@ describe JSON::LD::API do
222
221
  }),
223
222
  %q(
224
223
  <http://example.com/about#gregg> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
225
- <http://example.com/about#gregg> <http://schema.org/name> "Gregg Kellogg" .
224
+ <http://example.com/about#gregg> <http://schema.org/name> "Gregg Kellogg"^^xsd:string .
226
225
  )
227
226
  ],
228
- }.each do |title, (js, nt)|
227
+ }.each do |title, (js, ttl)|
229
228
  it title do
230
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
229
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
230
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
231
231
  end
232
232
  end
233
233
  end
@@ -260,12 +260,13 @@ describe JSON::LD::API do
260
260
  }),
261
261
  %q(
262
262
  <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/knows> _:a .
263
- _:a <http://xmlns.com/foaf/0.1/name> "Manu Sporny" .
263
+ _:a <http://xmlns.com/foaf/0.1/name> "Manu Sporny"^^xsd:string .
264
264
  )
265
265
  ],
266
- }.each do |title, (js, nt)|
266
+ }.each do |title, (js, ttl)|
267
267
  it title do
268
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
268
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
269
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
269
270
  end
270
271
  end
271
272
  end
@@ -284,9 +285,10 @@ describe JSON::LD::API do
284
285
  <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/knows> "Ivan Herman" .
285
286
  )
286
287
  ],
287
- }.each do |title, (js, nt)|
288
+ }.each do |title, (js, ttl)|
288
289
  it title do
289
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
290
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
291
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
290
292
  end
291
293
  end
292
294
  end
@@ -313,7 +315,7 @@ describe JSON::LD::API do
313
315
  }),
314
316
  %q(
315
317
  <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/knows> _:a .
316
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny" .
318
+ _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny"^^xsd:string .
317
319
  _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
318
320
  )
319
321
  ],
@@ -329,7 +331,7 @@ describe JSON::LD::API do
329
331
  }),
330
332
  %q(
331
333
  <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/knows> _:a .
332
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny" .
334
+ _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny"^^xsd:string .
333
335
  _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
334
336
  )
335
337
  ],
@@ -342,15 +344,16 @@ describe JSON::LD::API do
342
344
  }),
343
345
  %q(
344
346
  <http://greggkellogg.net/foaf#me> <http://xmlns.com/foaf/0.1/knows> _:a .
345
- _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny" .
347
+ _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Manu Sporny"^^xsd:string .
346
348
  _:a <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:b .
347
- _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Dave Longley" .
349
+ _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> "Dave Longley"^^xsd:string .
348
350
  _:b <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
349
351
  )
350
352
  ],
351
- }.each do |title, (js, nt)|
353
+ }.each do |title, (js, ttl)|
352
354
  it title do
353
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
355
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
356
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
354
357
  end
355
358
  end
356
359
  end
@@ -395,7 +398,7 @@ describe JSON::LD::API do
395
398
  }),
396
399
  %q(
397
400
  _:a <http://example.com/foo> _:b .
398
- _:b <http://example.org/foo> "bar" .
401
+ _:b <http://example.org/foo> "bar"^^xsd:string .
399
402
  )
400
403
  ],
401
404
  "contexts with a list processed in order" => [
@@ -407,7 +410,7 @@ describe JSON::LD::API do
407
410
  "foo": "bar"
408
411
  }),
409
412
  %q(
410
- _:b <http://example.org/foo> "bar" .
413
+ _:b <http://example.org/foo> "bar"^^xsd:string .
411
414
  )
412
415
  ],
413
416
  "term definition resolves term as IRI" => [
@@ -419,7 +422,7 @@ describe JSON::LD::API do
419
422
  "bar": "bar"
420
423
  }),
421
424
  %q(
422
- _:b <http://example.com/foo> "bar" .
425
+ _:b <http://example.com/foo> "bar"^^xsd:string .
423
426
  )
424
427
  ],
425
428
  "term definition resolves prefix as IRI" => [
@@ -431,22 +434,7 @@ describe JSON::LD::API do
431
434
  "bar": "bar"
432
435
  }),
433
436
  %q(
434
- _:b <http://example.com/foo#bar> "bar" .
435
- )
436
- ],
437
- "IRI resolution uses term from current context, not active context" => [
438
- %q({
439
- "@context": [
440
- {"foo": "not-this#"},
441
- {
442
- "foo": "http://example.com/foo#",
443
- "bar": "foo:bar"
444
- }
445
- ],
446
- "bar": "bar"
447
- }),
448
- %q(
449
- _:b <http://example.com/foo#bar> "bar" .
437
+ _:b <http://example.com/foo#bar> "bar"^^xsd:string .
450
438
  )
451
439
  ],
452
440
  "@language" => [
@@ -482,12 +470,13 @@ describe JSON::LD::API do
482
470
  "foo:bar": {"@value": "baz"}
483
471
  }),
484
472
  %q(
485
- _:a <http://example.com/foo#bar> "baz" .
473
+ _:a <http://example.com/foo#bar> "baz"^^xsd:string .
486
474
  )
487
475
  ],
488
- }.each do |title, (js, nt)|
476
+ }.each do |title, (js, ttl)|
489
477
  it title do
490
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
478
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
479
+ parse(js).should be_equivalent_graph(ttl, :base => "http://example/", :trace => @debug, :inputDocument => js)
491
480
  end
492
481
  end
493
482
 
@@ -537,9 +526,10 @@ describe JSON::LD::API do
537
526
  [ dc:date "2011-11-23"^^xsd:date] .
538
527
  )
539
528
  ],
540
- }.each do |title, (js, nt)|
529
+ }.each do |title, (js, ttl)|
541
530
  it title do
542
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
531
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
532
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
543
533
  end
544
534
  end
545
535
  end
@@ -572,9 +562,10 @@ describe JSON::LD::API do
572
562
  _:a <http://example.org/foo#bar> (<http://example.org/foo#bar>) .
573
563
  )
574
564
  ],
575
- }.each do |title, (js, nt)|
565
+ }.each do |title, (js, ttl)|
576
566
  it title do
577
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
567
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
568
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
578
569
  end
579
570
  end
580
571
  end
@@ -586,12 +577,12 @@ describe JSON::LD::API do
586
577
  "number syntax (decimal)" =>
587
578
  [
588
579
  %q({"@context": { "measure": "http://example/measure#"}, "measure:cups": 5.3}),
589
- %q(_:a <http://example/measure#cups> "5.3"^^<http://www.w3.org/2001/XMLSchema#double> .)
580
+ %q(_:a <http://example/measure#cups> "5.3E0"^^<http://www.w3.org/2001/XMLSchema#double> .)
590
581
  ],
591
582
  "number syntax (double)" =>
592
583
  [
593
584
  %q({"@context": { "measure": "http://example/measure#"}, "measure:cups": 5.3e0}),
594
- %q(_:a <http://example/measure#cups> "5.3"^^<http://www.w3.org/2001/XMLSchema#double> .)
585
+ %q(_:a <http://example/measure#cups> "5.3E0"^^<http://www.w3.org/2001/XMLSchema#double> .)
595
586
  ],
596
587
  "number syntax (integer)" =>
597
588
  [
@@ -628,9 +619,10 @@ describe JSON::LD::API do
628
619
  <http://example.com/#you> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
629
620
  )
630
621
  ],
631
- }.each do |title, (js, nt)|
622
+ }.each do |title, (js, ttl)|
632
623
  it title do
633
- parse(js).should be_equivalent_graph(nt, :trace => @debug, :inputDocument => js)
624
+ ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
625
+ parse(js).should be_equivalent_graph(ttl, :trace => @debug, :inputDocument => js)
634
626
  end
635
627
  end
636
628
  end
@@ -640,7 +632,7 @@ describe JSON::LD::API do
640
632
  @debug = []
641
633
  graph = options[:graph] || RDF::Graph.new
642
634
  options = {:debug => @debug, :validate => true, :canonicalize => false}.merge(options)
643
- JSON::LD::API.toRDF(StringIO.new(input), nil, nil, options) {|st| graph << st}
635
+ JSON::LD::API.toRDF(StringIO.new(input), nil, options) {|st| graph << st}
644
636
  graph
645
637
  end
646
638
  end