json-ld 3.2.4 → 3.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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/VERSION +1 -1
  4. data/lib/json/ld/api.rb +807 -771
  5. data/lib/json/ld/compact.rb +304 -304
  6. data/lib/json/ld/conneg.rb +179 -161
  7. data/lib/json/ld/context.rb +2079 -1913
  8. data/lib/json/ld/expand.rb +745 -666
  9. data/lib/json/ld/extensions.rb +14 -13
  10. data/lib/json/ld/flatten.rb +257 -247
  11. data/lib/json/ld/format.rb +202 -194
  12. data/lib/json/ld/frame.rb +525 -502
  13. data/lib/json/ld/from_rdf.rb +223 -204
  14. data/lib/json/ld/html/nokogiri.rb +123 -121
  15. data/lib/json/ld/html/rexml.rb +151 -147
  16. data/lib/json/ld/reader.rb +107 -100
  17. data/lib/json/ld/resource.rb +224 -205
  18. data/lib/json/ld/streaming_reader.rb +574 -507
  19. data/lib/json/ld/streaming_writer.rb +93 -92
  20. data/lib/json/ld/to_rdf.rb +171 -169
  21. data/lib/json/ld/utils.rb +270 -264
  22. data/lib/json/ld/version.rb +24 -14
  23. data/lib/json/ld/writer.rb +334 -311
  24. data/lib/json/ld.rb +103 -96
  25. metadata +56 -225
  26. data/spec/api_spec.rb +0 -132
  27. data/spec/compact_spec.rb +0 -3482
  28. data/spec/conneg_spec.rb +0 -373
  29. data/spec/context_spec.rb +0 -2056
  30. data/spec/expand_spec.rb +0 -4496
  31. data/spec/flatten_spec.rb +0 -1203
  32. data/spec/format_spec.rb +0 -115
  33. data/spec/frame_spec.rb +0 -2541
  34. data/spec/from_rdf_spec.rb +0 -1072
  35. data/spec/matchers.rb +0 -20
  36. data/spec/rdfstar_spec.rb +0 -25
  37. data/spec/reader_spec.rb +0 -883
  38. data/spec/resource_spec.rb +0 -76
  39. data/spec/spec_helper.rb +0 -281
  40. data/spec/streaming_reader_spec.rb +0 -237
  41. data/spec/streaming_writer_spec.rb +0 -145
  42. data/spec/suite_compact_spec.rb +0 -22
  43. data/spec/suite_expand_spec.rb +0 -36
  44. data/spec/suite_flatten_spec.rb +0 -34
  45. data/spec/suite_frame_spec.rb +0 -29
  46. data/spec/suite_from_rdf_spec.rb +0 -22
  47. data/spec/suite_helper.rb +0 -411
  48. data/spec/suite_html_spec.rb +0 -22
  49. data/spec/suite_http_spec.rb +0 -35
  50. data/spec/suite_remote_doc_spec.rb +0 -22
  51. data/spec/suite_to_rdf_spec.rb +0 -30
  52. data/spec/support/extensions.rb +0 -44
  53. data/spec/test-files/test-1-compacted.jsonld +0 -10
  54. data/spec/test-files/test-1-context.jsonld +0 -7
  55. data/spec/test-files/test-1-expanded.jsonld +0 -5
  56. data/spec/test-files/test-1-input.jsonld +0 -10
  57. data/spec/test-files/test-1-rdf.ttl +0 -8
  58. data/spec/test-files/test-2-compacted.jsonld +0 -20
  59. data/spec/test-files/test-2-context.jsonld +0 -7
  60. data/spec/test-files/test-2-expanded.jsonld +0 -16
  61. data/spec/test-files/test-2-input.jsonld +0 -20
  62. data/spec/test-files/test-2-rdf.ttl +0 -14
  63. data/spec/test-files/test-3-compacted.jsonld +0 -11
  64. data/spec/test-files/test-3-context.jsonld +0 -8
  65. data/spec/test-files/test-3-expanded.jsonld +0 -10
  66. data/spec/test-files/test-3-input.jsonld +0 -11
  67. data/spec/test-files/test-3-rdf.ttl +0 -8
  68. data/spec/test-files/test-4-compacted.jsonld +0 -10
  69. data/spec/test-files/test-4-context.jsonld +0 -7
  70. data/spec/test-files/test-4-expanded.jsonld +0 -6
  71. data/spec/test-files/test-4-input.jsonld +0 -10
  72. data/spec/test-files/test-4-rdf.ttl +0 -5
  73. data/spec/test-files/test-5-compacted.jsonld +0 -13
  74. data/spec/test-files/test-5-context.jsonld +0 -7
  75. data/spec/test-files/test-5-expanded.jsonld +0 -9
  76. data/spec/test-files/test-5-input.jsonld +0 -13
  77. data/spec/test-files/test-5-rdf.ttl +0 -7
  78. data/spec/test-files/test-6-compacted.jsonld +0 -10
  79. data/spec/test-files/test-6-context.jsonld +0 -7
  80. data/spec/test-files/test-6-expanded.jsonld +0 -10
  81. data/spec/test-files/test-6-input.jsonld +0 -10
  82. data/spec/test-files/test-6-rdf.ttl +0 -6
  83. data/spec/test-files/test-7-compacted.jsonld +0 -23
  84. data/spec/test-files/test-7-context.jsonld +0 -4
  85. data/spec/test-files/test-7-expanded.jsonld +0 -20
  86. data/spec/test-files/test-7-input.jsonld +0 -23
  87. data/spec/test-files/test-7-rdf.ttl +0 -14
  88. data/spec/test-files/test-8-compacted.jsonld +0 -34
  89. data/spec/test-files/test-8-context.jsonld +0 -11
  90. data/spec/test-files/test-8-expanded.jsonld +0 -24
  91. data/spec/test-files/test-8-frame.jsonld +0 -18
  92. data/spec/test-files/test-8-framed.jsonld +0 -25
  93. data/spec/test-files/test-8-input.jsonld +0 -30
  94. data/spec/test-files/test-8-rdf.ttl +0 -15
  95. data/spec/test-files/test-9-compacted.jsonld +0 -20
  96. data/spec/test-files/test-9-context.jsonld +0 -13
  97. data/spec/test-files/test-9-expanded.jsonld +0 -14
  98. data/spec/test-files/test-9-input.jsonld +0 -12
  99. data/spec/to_rdf_spec.rb +0 -1684
  100. data/spec/writer_spec.rb +0 -427
@@ -1,145 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
- require 'rdf/spec/writer'
4
- require 'json/ld/streaming_writer'
5
-
6
- describe JSON::LD::StreamingWriter do
7
- let(:logger) {RDF::Spec.logger}
8
-
9
- after(:each) {|example| puts logger.to_s if example.exception}
10
-
11
- it_behaves_like 'an RDF::Writer' do
12
- let(:writer) {JSON::LD::Writer.new(StringIO.new(""), stream: true)}
13
- end
14
-
15
- context "simple tests" do
16
- it "should use full URIs without base" do
17
- input = %(<http://a/b> <http://a/c> <http://a/d> .)
18
- obj = serialize(input)
19
- expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
20
- expect(obj).to produce_jsonld([{
21
- '@id' => "http://a/b",
22
- "http://a/c" => [{"@id" => "http://a/d"}]
23
- }], logger)
24
- end
25
-
26
- it "writes multiple kinds of statements" do
27
- input = %(
28
- <https://senet.org/gm> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://vocab.org/frbr/core#Work> .
29
- <https://senet.org/gm> <http://purl.org/dc/terms/title> "Rhythm Paradise"@en .
30
- <https://senet.org/gm> <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en .
31
- <https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
32
- )
33
- obj = serialize(input)
34
- expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
35
- expect(obj).to eql JSON.parse(%{[{
36
- "@id": "https://senet.org/gm",
37
- "@type": ["http://vocab.org/frbr/core#Work"],
38
- "http://purl.org/dc/terms/title": [{"@value": "Rhythm Paradise", "@language": "en"}],
39
- "https://senet.org/ns#unofficialTitle": [{"@value": "Rhythm Tengoku", "@language": "en"}],
40
- "https://senet.org/ns#urlkey": [{"@value": "rhythm-tengoku"}]
41
- }]})
42
- end
43
-
44
- it "serializes multiple subjects" do
45
- input = %q(
46
- @prefix : <http://www.w3.org/2006/03/test-description#> .
47
- @prefix dc: <http://purl.org/dc/terms/> .
48
- <http://example.com/test-cases/0001> a :TestCase .
49
- <http://example.com/test-cases/0002> a :TestCase .
50
- )
51
- obj = serialize(input)
52
- expect(parse(obj.to_json, format: :jsonld)).to be_equivalent_graph(parse(input), logger: logger)
53
- expect(obj).to contain_exactly(*JSON.parse(%{[
54
- {"@id": "http://example.com/test-cases/0001", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]},
55
- {"@id": "http://example.com/test-cases/0002", "@type": ["http://www.w3.org/2006/03/test-description#TestCase"]}
56
- ]}))
57
- end
58
- end
59
-
60
- context "Named Graphs" do
61
- {
62
- "default" => [
63
- %q({<a> <b> <c> .}),
64
- %q([{"@id": "a", "b": [{"@id": "c"}]}])
65
- ],
66
- "named" => [
67
- %q(<C> {<a> <b> <c> .}),
68
- %q([{"@id" : "C", "@graph" : [{"@id": "a", "b": [{"@id": "c"}]}]}])
69
- ],
70
- "combo" => [
71
- %q(
72
- <a> <b> <c> .
73
- <C> {<A> <b> <c> .}
74
- ),
75
- %q([
76
- {"@id": "a", "b": [{"@id": "c"}]},
77
- {"@id": "C", "@graph": [{"@id": "A", "b": [{"@id": "c"}]}]}
78
- ])
79
- ],
80
- "combo with duplicated statement" => [
81
- %q(
82
- <a> <b> <c> .
83
- <C> {<a> <b> <c> .}
84
- ),
85
- %q([
86
- {"@id": "a", "b": [{"@id": "c"}]},
87
- {"@id": "C", "@graph": [{"@id": "a", "b": [{"@id": "c"}]}]}
88
- ])
89
- ],
90
- }.each_pair do |title, (input, matches)|
91
- context title do
92
- subject {serialize(input)}
93
- it "matches expected json" do
94
- expect(subject).to contain_exactly(*JSON.parse(matches))
95
- end
96
- end
97
- end
98
- end
99
-
100
-
101
- context "Writes fromRdf tests to isomorphic graph" do
102
- require 'suite_helper'
103
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
104
- [nil, {}].each do |ctx|
105
- context "with context #{ctx.inspect}" do
106
- describe m.name do
107
- m.entries.each do |t|
108
- next unless t.positiveTest? && !t.property('input').include?('0016')
109
- t.logger = RDF::Spec.logger
110
- t.logger.info "test: #{t.inspect}"
111
- t.logger.info "source: #{t.input}"
112
- specify "#{t.property('@id')}: #{t.name}" do
113
- repo = RDF::Repository.load(t.input_loc, format: :nquads)
114
- jsonld = JSON::LD::Writer.buffer(stream: true, context: ctx, logger: t.logger, **t.options) do |writer|
115
- writer << repo
116
- end
117
- t.logger.info "Generated: #{jsonld}"
118
-
119
- # And then, re-generate jsonld as RDF
120
- expect(parse(jsonld, format: :jsonld, **t.options)).to be_equivalent_graph(repo, t)
121
- end
122
- end
123
- end
124
- end
125
- end
126
- end unless ENV['CI']
127
-
128
- def parse(input, format: :trig, **options)
129
- reader = RDF::Reader.for(format)
130
- RDF::Repository.new << reader.new(input, **options)
131
- end
132
-
133
- # Serialize ntstr to a string and compare against regexps
134
- def serialize(ntstr, **options)
135
- g = ntstr.is_a?(String) ? parse(ntstr, **options) : ntstr
136
- logger = RDF::Spec.logger
137
- logger.info(g.dump(:ttl))
138
- result = JSON::LD::Writer.buffer(logger: logger, stream: true, **options) do |writer|
139
- writer << g
140
- end
141
- puts result if $verbose
142
-
143
- JSON.parse(result)
144
- end
145
- end
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}compact-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
11
- t.options[:ordered] = false
12
- expect{t.run self}.not_to write.to(:error)
13
- end
14
-
15
- specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
16
- t.options[:ordered] = true
17
- expect {t.run self}.not_to write.to(:error)
18
- end
19
- end
20
- end
21
- end
22
- end unless ENV['CI']
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}expand-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- # MultiJson use OJ, by default, which doesn't handle native numbers the same as the JSON gem.
11
- t.options[:adapter] = :json_gem if %w(#tjs12).include?(t.property('@id'))
12
- specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
13
- t.options[:ordered] = false
14
- if %w(#t0068).include?(t.property('@id'))
15
- expect{t.run self}.to write("[DEPRECATION]").to(:error)
16
- elsif %w(#t0005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #t0119 #t0120).include?(t.property('@id'))
17
- expect{t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
18
- else
19
- expect {t.run self}.not_to write.to(:error)
20
- end
21
- end
22
-
23
- specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
24
- t.options[:ordered] = true
25
- if %w(#t0068).include?(t.property('@id'))
26
- expect{t.run self}.to write("[DEPRECATION]").to(:error)
27
- elsif %w(#t0005 #tpr34 #tpr35 #tpr36 #tpr37 #tpr38 #tpr39 #t0119 #t0120).include?(t.property('@id'))
28
- expect{t.run self}.to write("beginning with '@' are reserved for future use").to(:error)
29
- else
30
- expect {t.run self}.not_to write.to(:error)
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end unless ENV['CI']
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}flatten-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- t.options[:remap_bnodes] = %w(#t0045).include?(t.property('@id'))
11
-
12
- specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
13
- t.options[:ordered] = false
14
- if %w(#t0005).include?(t.property('@id'))
15
- expect{t.run self}.to write("Terms beginning with '@' are reserved for future use").to(:error)
16
- else
17
- expect {t.run self}.not_to write.to(:error)
18
- end
19
- end
20
-
21
- # Skip ordered tests when remapping bnodes
22
- next if t.options[:remap_bnodes]
23
- specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
24
- t.options[:ordered] = true
25
- if %w(#t0005).include?(t.property('@id'))
26
- expect{t.run self}.to write("Terms beginning with '@' are reserved for future use").to(:error)
27
- else
28
- expect {t.run self}.not_to write.to(:error)
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end unless ENV['CI']
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::FRAME_SUITE}frame-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- t.options[:remap_bnodes] = %w(#t0021 #tp021).include?(t.property('@id'))
11
-
12
- specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
13
- t.options[:ordered] = false
14
- expect {t.run self}.not_to write.to(:error)
15
- end
16
-
17
- # Skip ordered tests when remapping bnodes
18
- next if t.options[:remap_bnodes]
19
- specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
20
- t.options[:ordered] = true
21
- if %w(#tp021).include?(t.property('@id'))
22
- pending("changes due to blank node reordering")
23
- end
24
- expect {t.run self}.not_to write.to(:error)
25
- end
26
- end
27
- end
28
- end
29
- end unless ENV['CI']
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- require_relative 'spec_helper'
3
-
4
- describe JSON::LD do
5
- describe "test suite" do
6
- require_relative 'suite_helper'
7
- m = Fixtures::SuiteTest::Manifest.open("#{Fixtures::SuiteTest::SUITE}fromRdf-manifest.jsonld")
8
- describe m.name do
9
- m.entries.each do |t|
10
- specify "#{t.property('@id')}: #{t.name} unordered#{' (negative test)' unless t.positiveTest?}" do
11
- t.options[:ordered] = false
12
- expect {t.run self}.not_to write.to(:error)
13
- end
14
-
15
- specify "#{t.property('@id')}: #{t.name} ordered#{' (negative test)' unless t.positiveTest?}" do
16
- t.options[:ordered] = true
17
- expect {t.run self}.not_to write.to(:error)
18
- end
19
- end
20
- end
21
- end
22
- end unless ENV['CI']