json-ld 3.1.0 → 3.1.5
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.
- checksums.yaml +4 -4
- data/README.md +66 -46
- data/VERSION +1 -1
- data/bin/jsonld +27 -30
- data/lib/json/ld.rb +12 -8
- data/lib/json/ld/api.rb +51 -43
- data/lib/json/ld/compact.rb +82 -68
- data/lib/json/ld/conneg.rb +1 -1
- data/lib/json/ld/context.rb +650 -542
- data/lib/json/ld/expand.rb +154 -87
- data/lib/json/ld/flatten.rb +1 -1
- data/lib/json/ld/format.rb +10 -6
- data/lib/json/ld/frame.rb +1 -2
- data/lib/json/ld/from_rdf.rb +7 -8
- data/lib/json/ld/html/nokogiri.rb +2 -1
- data/lib/json/ld/html/rexml.rb +2 -1
- data/lib/json/ld/reader.rb +20 -11
- data/lib/json/ld/streaming_reader.rb +578 -0
- data/lib/json/ld/to_rdf.rb +9 -3
- data/lib/json/ld/writer.rb +12 -5
- data/spec/compact_spec.rb +1 -0
- data/spec/context_spec.rb +63 -116
- data/spec/expand_spec.rb +29 -9
- data/spec/frame_spec.rb +44 -0
- data/spec/matchers.rb +1 -1
- data/spec/reader_spec.rb +33 -34
- data/spec/streaming_reader_spec.rb +237 -0
- data/spec/suite_expand_spec.rb +4 -2
- data/spec/suite_frame_spec.rb +0 -1
- data/spec/suite_helper.rb +23 -8
- data/spec/suite_to_rdf_spec.rb +1 -1
- data/spec/to_rdf_spec.rb +3 -3
- metadata +11 -8
data/lib/json/ld/to_rdf.rb
CHANGED
@@ -50,11 +50,11 @@ module JSON::LD
|
|
50
50
|
# Either serialize using a datatype, or a compound-literal
|
51
51
|
case @options[:rdfDirection]
|
52
52
|
when 'i18n-datatype'
|
53
|
-
datatype = RDF::URI("https://www.w3.org/ns/i18n##{item.fetch('@language', '')}_#{item['@direction']}")
|
53
|
+
datatype = RDF::URI("https://www.w3.org/ns/i18n##{item.fetch('@language', '').downcase}_#{item['@direction']}")
|
54
54
|
when 'compound-literal'
|
55
55
|
cl = RDF::Node.new
|
56
56
|
yield RDF::Statement(cl, RDF.value, item['@value'].to_s)
|
57
|
-
yield RDF::Statement(cl, RDF.to_uri + 'language', item['@language']) if item['@language']
|
57
|
+
yield RDF::Statement(cl, RDF.to_uri + 'language', item['@language'].downcase) if item['@language']
|
58
58
|
yield RDF::Statement(cl, RDF.to_uri + 'direction', item['@direction'])
|
59
59
|
return cl
|
60
60
|
end
|
@@ -76,7 +76,13 @@ module JSON::LD
|
|
76
76
|
return parse_list(item['@list'], graph_name: graph_name, &block)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
# Skip if '@id' is nil
|
80
|
+
subject = if item.has_key?('@id')
|
81
|
+
item['@id'].nil? ? nil : as_resource(item['@id'])
|
82
|
+
else
|
83
|
+
node
|
84
|
+
end
|
85
|
+
|
80
86
|
#log_debug("item_to_rdf") {"subject: #{subject.to_ntriples rescue 'malformed rdf'}"}
|
81
87
|
item.each do |property, values|
|
82
88
|
case property
|
data/lib/json/ld/writer.rb
CHANGED
@@ -93,7 +93,7 @@ module JSON::LD
|
|
93
93
|
datatype: RDF::URI,
|
94
94
|
control: :url2,
|
95
95
|
on: ["--context CONTEXT"],
|
96
|
-
description: "Context to use when compacting.") {|arg| RDF::URI(arg)},
|
96
|
+
description: "Context to use when compacting.") {|arg| RDF::URI(arg).absolute? ? RDF::URI(arg) : StringIO.new(File.read(arg))},
|
97
97
|
RDF::CLI::Option.new(
|
98
98
|
symbol: :embed,
|
99
99
|
datatype: %w(@always @once @never),
|
@@ -107,6 +107,13 @@ module JSON::LD
|
|
107
107
|
control: :checkbox,
|
108
108
|
on: ["--[no-]explicit"],
|
109
109
|
description: "Only include explicitly declared properties in output (false)") {|arg| arg},
|
110
|
+
RDF::CLI::Option.new(
|
111
|
+
symbol: :frame,
|
112
|
+
datatype: RDF::URI,
|
113
|
+
control: :url2,
|
114
|
+
use: :required,
|
115
|
+
on: ["--frame FRAME"],
|
116
|
+
description: "Frame to use when serializing.") {|arg| RDF::URI(arg).absolute? ? RDF::URI(arg) : StringIO.new(File.read(arg))},
|
110
117
|
RDF::CLI::Option.new(
|
111
118
|
symbol: :lowercaseLanguage,
|
112
119
|
datatype: TrueClass,
|
@@ -137,14 +144,14 @@ module JSON::LD
|
|
137
144
|
default: 'null',
|
138
145
|
control: :select,
|
139
146
|
on: ["--rdf-direction DIR", %w(i18n-datatype compound-literal)],
|
140
|
-
description: "How to serialize literal direction (i18n-datatype compound-literal)") {|arg|
|
147
|
+
description: "How to serialize literal direction (i18n-datatype compound-literal)") {|arg| arg},
|
141
148
|
RDF::CLI::Option.new(
|
142
149
|
symbol: :requireAll,
|
143
150
|
datatype: TrueClass,
|
144
151
|
default: true,
|
145
152
|
control: :checkbox,
|
146
|
-
on: ["--[no-]
|
147
|
-
description: "Require all properties to match (true). Default is `true` use --no-
|
153
|
+
on: ["--[no-]require-all"],
|
154
|
+
description: "Require all properties to match (true). Default is `true` use --no-require-all to disable.") {|arg| arg},
|
148
155
|
RDF::CLI::Option.new(
|
149
156
|
symbol: :stream,
|
150
157
|
datatype: TrueClass,
|
@@ -202,7 +209,7 @@ module JSON::LD
|
|
202
209
|
end
|
203
210
|
|
204
211
|
##
|
205
|
-
# Initializes the
|
212
|
+
# Initializes the JSON-LD writer instance.
|
206
213
|
#
|
207
214
|
# @param [IO, File] output
|
208
215
|
# the output stream
|
data/spec/compact_spec.rb
CHANGED
data/spec/context_spec.rb
CHANGED
@@ -56,15 +56,8 @@ describe JSON::LD::Context do
|
|
56
56
|
describe "#parse" do
|
57
57
|
context "remote" do
|
58
58
|
|
59
|
-
it "retrieves and parses a remote context document" do
|
60
|
-
JSON::LD::Context::PRELOADED.clear
|
61
|
-
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
62
|
-
ec = subject.parse("http://example.com/context")
|
63
|
-
expect(ec.provided_context).to produce("http://example.com/context", logger)
|
64
|
-
end
|
65
|
-
|
66
59
|
it "fails given a missing remote @context" do
|
67
|
-
JSON::LD::Context
|
60
|
+
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
68
61
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_raise(IOError)
|
69
62
|
expect {subject.parse("http://example.com/context")}.to raise_error(JSON::LD::JsonLdError::LoadingRemoteContextFailed, %r{http://example.com/context})
|
70
63
|
end
|
@@ -116,7 +109,7 @@ describe JSON::LD::Context do
|
|
116
109
|
documentUrl: "http://example.com/context",
|
117
110
|
contentType: "text/html")
|
118
111
|
|
119
|
-
JSON::LD::Context
|
112
|
+
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
120
113
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
121
114
|
ec = subject.parse("http://example.com/context")
|
122
115
|
expect(ec.send(:mappings)).to produce({
|
@@ -154,7 +147,7 @@ describe JSON::LD::Context do
|
|
154
147
|
),
|
155
148
|
documentUrl: "http://example.com/context",
|
156
149
|
contentType: "text/html")
|
157
|
-
JSON::LD::Context
|
150
|
+
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
158
151
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
159
152
|
ec = subject.parse("http://example.com/context")
|
160
153
|
expect(ec.send(:mappings)).to produce({
|
@@ -170,7 +163,7 @@ describe JSON::LD::Context do
|
|
170
163
|
end
|
171
164
|
|
172
165
|
it "parses a referenced context at a relative URI" do
|
173
|
-
JSON::LD::Context
|
166
|
+
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
174
167
|
rd1 = JSON::LD::API::RemoteDocument.new(%({"@context": "context"}), base_uri: "http://example.com/c1")
|
175
168
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/c1", anything).and_yield(rd1)
|
176
169
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
@@ -185,17 +178,11 @@ describe JSON::LD::Context do
|
|
185
178
|
|
186
179
|
context "remote with local mappings" do
|
187
180
|
let(:ctx) {["http://example.com/context", {"integer" => "xsd:integer"}]}
|
188
|
-
before {JSON::LD::Context
|
181
|
+
before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
|
189
182
|
it "retrieves and parses a remote context document" do
|
190
183
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
191
184
|
subject.parse(ctx)
|
192
185
|
end
|
193
|
-
|
194
|
-
it "does not use passed context as provided_context" do
|
195
|
-
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
196
|
-
ec = subject.parse(ctx)
|
197
|
-
expect(ec.provided_context).to produce(ctx, logger)
|
198
|
-
end
|
199
186
|
end
|
200
187
|
|
201
188
|
context "pre-loaded remote" do
|
@@ -206,7 +193,7 @@ describe JSON::LD::Context do
|
|
206
193
|
)
|
207
194
|
JSON::LD::Context.alias_preloaded("https://example.com/preloaded", "http://example.com/preloaded")
|
208
195
|
}
|
209
|
-
after(:all) {JSON::LD::Context
|
196
|
+
after(:all) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
|
210
197
|
|
211
198
|
it "does not load referenced context" do
|
212
199
|
expect(JSON::LD::API).not_to receive(:documentLoader).with(ctx, anything)
|
@@ -249,6 +236,7 @@ describe JSON::LD::Context do
|
|
249
236
|
end
|
250
237
|
|
251
238
|
it "merges definitions from remote contexts" do
|
239
|
+
JSON::LD::Context.instance_variable_set(:@cache, nil)
|
252
240
|
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
253
241
|
rd2 = JSON::LD::API::RemoteDocument.new(%q({
|
254
242
|
"@context": {
|
@@ -348,7 +336,7 @@ describe JSON::LD::Context do
|
|
348
336
|
expect(subject.parse({
|
349
337
|
"foo" => {"@id" => "http://example.com/", "@container" => "@list"}
|
350
338
|
}).containers).to produce({
|
351
|
-
"foo" =>
|
339
|
+
"foo" => Set["@list"]
|
352
340
|
}, logger)
|
353
341
|
end
|
354
342
|
|
@@ -356,7 +344,7 @@ describe JSON::LD::Context do
|
|
356
344
|
expect(subject.parse({
|
357
345
|
"foo" => {"@id" => "http://example.com/", "@container" => "@type"}
|
358
346
|
}).containers).to produce({
|
359
|
-
"foo" =>
|
347
|
+
"foo" => Set["@type"]
|
360
348
|
}, logger)
|
361
349
|
end
|
362
350
|
|
@@ -364,7 +352,7 @@ describe JSON::LD::Context do
|
|
364
352
|
expect(subject.parse({
|
365
353
|
"foo" => {"@id" => "http://example.com/", "@container" => "@id"}
|
366
354
|
}).containers).to produce({
|
367
|
-
"foo" =>
|
355
|
+
"foo" => Set["@id"]
|
368
356
|
}, logger)
|
369
357
|
end
|
370
358
|
|
@@ -476,7 +464,7 @@ describe JSON::LD::Context do
|
|
476
464
|
end
|
477
465
|
|
478
466
|
context "@import" do
|
479
|
-
before(:each) {JSON::LD::Context
|
467
|
+
before(:each) {JSON::LD::Context.instance_variable_set(:@cache, nil)}
|
480
468
|
it "generates an InvalidImportValue error if not a string" do
|
481
469
|
expect {subject.parse({'@version' => 1.1, '@import' => true})}.to raise_error(JSON::LD::JsonLdError::InvalidImportValue)
|
482
470
|
end
|
@@ -503,7 +491,7 @@ describe JSON::LD::Context do
|
|
503
491
|
"@type as object" => {"foo" => {"@type" => {}}},
|
504
492
|
"@type as array" => {"foo" => {"@type" => []}},
|
505
493
|
"@type as @list" => {"foo" => {"@type" => "@list"}},
|
506
|
-
"@type as @none" => {"@version"
|
494
|
+
"@type as @none" => {"@version" => 1.1, "foo" => {"@type" => "@none"}},
|
507
495
|
"@type as @set" => {"foo" => {"@type" => "@set"}},
|
508
496
|
"@container as object" => {"foo" => {"@container" => {}}},
|
509
497
|
"@container as empty array" => {"foo" => {"@container" => []}},
|
@@ -553,12 +541,12 @@ describe JSON::LD::Context do
|
|
553
541
|
end
|
554
542
|
end
|
555
543
|
|
556
|
-
it "generates
|
557
|
-
expect {context.parse({'@propagate' => true})}.to raise_error(JSON::LD::JsonLdError::
|
544
|
+
it "generates InvalidContextEntry if using @propagate" do
|
545
|
+
expect {context.parse({'@propagate' => true})}.to raise_error(JSON::LD::JsonLdError::InvalidContextEntry)
|
558
546
|
end
|
559
547
|
|
560
|
-
it "generates
|
561
|
-
expect {context.parse({'@import' => "location"})}.to raise_error(JSON::LD::JsonLdError::
|
548
|
+
it "generates InvalidContextEntry if using @import" do
|
549
|
+
expect {context.parse({'@import' => "location"})}.to raise_error(JSON::LD::JsonLdError::InvalidContextEntry)
|
562
550
|
end
|
563
551
|
|
564
552
|
(JSON::LD::KEYWORDS - %w(@base @language @version @protected @propagate @vocab)).each do |kw|
|
@@ -642,26 +630,8 @@ describe JSON::LD::Context do
|
|
642
630
|
end
|
643
631
|
end
|
644
632
|
|
645
|
-
describe "#merge!" do
|
646
|
-
it "updates context with components from new" do
|
647
|
-
c2 = JSON::LD::Context.parse({'foo' => "http://example.com/"})
|
648
|
-
cm = context.merge!(c2)
|
649
|
-
expect(cm).to equal context
|
650
|
-
expect(cm).not_to equal c2
|
651
|
-
expect(cm.term_definitions).to eq c2.term_definitions
|
652
|
-
end
|
653
|
-
end
|
654
|
-
|
655
633
|
describe "#serialize" do
|
656
|
-
before {JSON::LD::Context
|
657
|
-
it "context document" do
|
658
|
-
expect(JSON::LD::API).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(remote_doc)
|
659
|
-
ec = subject.parse("http://example.com/context")
|
660
|
-
expect(ec.serialize).to produce({
|
661
|
-
"@context" => "http://example.com/context"
|
662
|
-
}, logger)
|
663
|
-
end
|
664
|
-
|
634
|
+
before {JSON::LD::Context.instance_variable_set(:@cache, nil)}
|
665
635
|
it "context hash" do
|
666
636
|
ctx = {"foo" => "http://example.com/"}
|
667
637
|
|
@@ -693,7 +663,7 @@ describe JSON::LD::Context do
|
|
693
663
|
|
694
664
|
it "term mappings" do
|
695
665
|
c = subject.
|
696
|
-
parse({'foo' => "http://example.com/"})
|
666
|
+
parse({'foo' => "http://example.com/"})
|
697
667
|
expect(c.serialize).to produce({
|
698
668
|
"@context" => {
|
699
669
|
"foo" => "http://example.com/"
|
@@ -705,7 +675,7 @@ describe JSON::LD::Context do
|
|
705
675
|
it "@context" do
|
706
676
|
expect(subject.parse({
|
707
677
|
"foo" => {"@id" => "http://example.com/", "@context" => {"bar" => "http://example.com/baz"}}
|
708
|
-
}).
|
678
|
+
}).
|
709
679
|
serialize).to produce({
|
710
680
|
"@context" => {
|
711
681
|
"foo" => {
|
@@ -721,7 +691,6 @@ describe JSON::LD::Context do
|
|
721
691
|
'xsd' => "http://www.w3.org/2001/XMLSchema#",
|
722
692
|
'homepage' => {'@id' => RDF::Vocab::FOAF.homepage.to_s, '@type' => '@id'}
|
723
693
|
}).
|
724
|
-
send(:clear_provided_context).
|
725
694
|
serialize).to produce({
|
726
695
|
"@context" => {
|
727
696
|
"xsd" => RDF::XSD.to_uri.to_s,
|
@@ -734,7 +703,6 @@ describe JSON::LD::Context do
|
|
734
703
|
expect(subject.parse({
|
735
704
|
'knows' => {'@id' => RDF::Vocab::FOAF.knows.to_s, '@container' => '@list'}
|
736
705
|
}).
|
737
|
-
send(:clear_provided_context).
|
738
706
|
serialize).to produce({
|
739
707
|
"@context" => {
|
740
708
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
@@ -746,7 +714,6 @@ describe JSON::LD::Context do
|
|
746
714
|
expect(subject.parse({
|
747
715
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
|
748
716
|
}).
|
749
|
-
send(:clear_provided_context).
|
750
717
|
serialize).to produce({
|
751
718
|
"@context" => {
|
752
719
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@set"}
|
@@ -758,7 +725,6 @@ describe JSON::LD::Context do
|
|
758
725
|
expect(subject.parse({
|
759
726
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
|
760
727
|
}).
|
761
|
-
send(:clear_provided_context).
|
762
728
|
serialize).to produce({
|
763
729
|
"@context" => {
|
764
730
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "en"}
|
@@ -771,7 +737,6 @@ describe JSON::LD::Context do
|
|
771
737
|
"@language" => 'en',
|
772
738
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => 'en'}
|
773
739
|
}).
|
774
|
-
send(:clear_provided_context).
|
775
740
|
serialize).to produce({
|
776
741
|
"@context" => {
|
777
742
|
"@language" => 'en',
|
@@ -785,7 +750,6 @@ describe JSON::LD::Context do
|
|
785
750
|
"@language" => 'en',
|
786
751
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => "de"}
|
787
752
|
}).
|
788
|
-
send(:clear_provided_context).
|
789
753
|
serialize).to produce({
|
790
754
|
"@context" => {
|
791
755
|
"@language" => 'en',
|
@@ -799,7 +763,6 @@ describe JSON::LD::Context do
|
|
799
763
|
"@language" => 'en',
|
800
764
|
"name" => {"@id" => RDF::Vocab::FOAF.name.to_s, "@language" => nil}
|
801
765
|
}).
|
802
|
-
send(:clear_provided_context).
|
803
766
|
serialize).to produce({
|
804
767
|
"@context" => {
|
805
768
|
"@language" => 'en',
|
@@ -812,7 +775,6 @@ describe JSON::LD::Context do
|
|
812
775
|
expect(subject.parse({
|
813
776
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
814
777
|
}).
|
815
|
-
send(:clear_provided_context).
|
816
778
|
serialize).to produce({
|
817
779
|
"@context" => {
|
818
780
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@list"}
|
@@ -824,7 +786,6 @@ describe JSON::LD::Context do
|
|
824
786
|
expect(subject.parse({
|
825
787
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
826
788
|
}).
|
827
|
-
send(:clear_provided_context).
|
828
789
|
serialize).to produce({
|
829
790
|
"@context" => {
|
830
791
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@id", "@container" => "@set"}
|
@@ -836,7 +797,6 @@ describe JSON::LD::Context do
|
|
836
797
|
expect(subject.parse({
|
837
798
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
|
838
799
|
}).
|
839
|
-
send(:clear_provided_context).
|
840
800
|
serialize).to produce({
|
841
801
|
"@context" => {
|
842
802
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@type" => "@json"}
|
@@ -851,7 +811,6 @@ describe JSON::LD::Context do
|
|
851
811
|
"@container" => "@list"
|
852
812
|
}
|
853
813
|
}).
|
854
|
-
send(:clear_provided_context).
|
855
814
|
serialize).to produce({
|
856
815
|
"@context" => {
|
857
816
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -867,7 +826,6 @@ describe JSON::LD::Context do
|
|
867
826
|
"id" => "@id",
|
868
827
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
869
828
|
}).
|
870
|
-
send(:clear_provided_context).
|
871
829
|
serialize).to produce({
|
872
830
|
"@context" => {
|
873
831
|
"id" => "@id",
|
@@ -884,7 +842,6 @@ describe JSON::LD::Context do
|
|
884
842
|
"@type" => "@id"
|
885
843
|
}
|
886
844
|
}).
|
887
|
-
send(:clear_provided_context).
|
888
845
|
serialize).to produce({
|
889
846
|
"@context" => {
|
890
847
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -902,7 +859,6 @@ describe JSON::LD::Context do
|
|
902
859
|
"type" => "@type",
|
903
860
|
"foaf:homepage" => {"@type" => "@id"}
|
904
861
|
}).
|
905
|
-
send(:clear_provided_context).
|
906
862
|
serialize).to produce({
|
907
863
|
"@context" => {
|
908
864
|
"foaf" => RDF::Vocab::FOAF.to_uri.to_s,
|
@@ -917,7 +873,6 @@ describe JSON::LD::Context do
|
|
917
873
|
"container" => "@container",
|
918
874
|
"knows" => {"@id" => RDF::Vocab::FOAF.knows.to_s, "@container" => "@list"}
|
919
875
|
}).
|
920
|
-
send(:clear_provided_context).
|
921
876
|
serialize).to produce({
|
922
877
|
"@context" => {
|
923
878
|
"container" => "@container",
|
@@ -931,7 +886,6 @@ describe JSON::LD::Context do
|
|
931
886
|
"ex" => 'http://example.org/',
|
932
887
|
"term" => {"@id" => "ex:term", "@type" => "ex:datatype"}
|
933
888
|
}).
|
934
|
-
send(:clear_provided_context).
|
935
889
|
serialize).to produce({
|
936
890
|
"@context" => {
|
937
891
|
"ex" => 'http://example.org/',
|
@@ -945,7 +899,6 @@ describe JSON::LD::Context do
|
|
945
899
|
"@vocab" => 'http://example.org/',
|
946
900
|
"term" => {"@id" => "http://example.org/term", "@type" => "datatype"}
|
947
901
|
}).
|
948
|
-
send(:clear_provided_context).
|
949
902
|
serialize).to produce({
|
950
903
|
"@context" => {
|
951
904
|
"@vocab" => 'http://example.org/',
|
@@ -954,11 +907,13 @@ describe JSON::LD::Context do
|
|
954
907
|
}, logger)
|
955
908
|
end
|
956
909
|
|
957
|
-
context "
|
910
|
+
context "invalid term definitions" do
|
958
911
|
{
|
959
|
-
"
|
960
|
-
input: {"
|
961
|
-
|
912
|
+
"empty term": {
|
913
|
+
input: {"" => "http://blank-term/"}
|
914
|
+
},
|
915
|
+
"extra key": {
|
916
|
+
input: {"foo" => {"@id" => "http://example.com/foo", "@baz" => "foobar"}}
|
962
917
|
}
|
963
918
|
}.each do |title, params|
|
964
919
|
it title do
|
@@ -975,7 +930,6 @@ describe JSON::LD::Context do
|
|
975
930
|
'@base' => 'http://base/',
|
976
931
|
'@vocab' => 'http://vocab/',
|
977
932
|
'ex' => 'http://example.org/',
|
978
|
-
'' => 'http://empty/',
|
979
933
|
'_' => 'http://underscore/'
|
980
934
|
})
|
981
935
|
}
|
@@ -1039,7 +993,6 @@ describe JSON::LD::Context do
|
|
1039
993
|
'@base' => 'http://base/base',
|
1040
994
|
'@vocab' => 'http://vocab/',
|
1041
995
|
'ex' => 'http://example.org/',
|
1042
|
-
'' => 'http://empty/',
|
1043
996
|
'_' => 'http://underscore/'
|
1044
997
|
})
|
1045
998
|
}
|
@@ -1119,7 +1072,6 @@ describe JSON::LD::Context do
|
|
1119
1072
|
"unmapped" => ["foo", RDF::URI("http://vocab/foo")],
|
1120
1073
|
"relative" => ["foo/bar", RDF::URI("http://vocab/foo/bar")],
|
1121
1074
|
"dotseg" => ["../foo/bar", RDF::URI("http://vocab/../foo/bar")],
|
1122
|
-
"empty term" => ["", RDF::URI("http://empty/")],
|
1123
1075
|
"another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
|
1124
1076
|
"absolute IRI looking like a compact IRI" =>
|
1125
1077
|
["foo:bar", RDF::URI("foo:bar")],
|
@@ -1138,7 +1090,6 @@ describe JSON::LD::Context do
|
|
1138
1090
|
'@base' => 'http://base/base',
|
1139
1091
|
'@vocab' => '',
|
1140
1092
|
'ex' => 'http://example.org/',
|
1141
|
-
'' => 'http://empty/',
|
1142
1093
|
'_' => 'http://underscore/'
|
1143
1094
|
})
|
1144
1095
|
}
|
@@ -1153,7 +1104,6 @@ describe JSON::LD::Context do
|
|
1153
1104
|
"unmapped" => ["foo", RDF::URI("http://base/basefoo")],
|
1154
1105
|
"relative" => ["foo/bar", RDF::URI("http://base/basefoo/bar")],
|
1155
1106
|
"dotseg" => ["../foo/bar", RDF::URI("http://base/base../foo/bar")],
|
1156
|
-
"empty term" => ["", RDF::URI("http://empty/")],
|
1157
1107
|
"another abs IRI"=>["ex://foo", RDF::URI("ex://foo")],
|
1158
1108
|
"absolute IRI looking like a compact IRI" =>
|
1159
1109
|
["foo:bar", RDF::URI("foo:bar")],
|
@@ -1183,7 +1133,6 @@ describe JSON::LD::Context do
|
|
1183
1133
|
'@base' => 'http://base/',
|
1184
1134
|
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
1185
1135
|
'ex' => 'http://example.org/',
|
1186
|
-
'' => 'http://empty/',
|
1187
1136
|
'_' => 'http://underscore/',
|
1188
1137
|
'rex' => {'@reverse' => "ex"},
|
1189
1138
|
'lex' => {'@id' => 'ex', '@language' => 'en'},
|
@@ -1258,7 +1207,7 @@ describe JSON::LD::Context do
|
|
1258
1207
|
it "does not use @vocab if it would collide with a term" do
|
1259
1208
|
subject.set_mapping("name", "http://xmlns.com/foaf/0.1/name")
|
1260
1209
|
subject.set_mapping("ex", nil)
|
1261
|
-
expect(subject.compact_iri("http://example.org/name",
|
1210
|
+
expect(subject.compact_iri("http://example.org/name", vocab: true)).
|
1262
1211
|
not_to produce("name", logger)
|
1263
1212
|
end
|
1264
1213
|
|
@@ -1390,7 +1339,6 @@ describe JSON::LD::Context do
|
|
1390
1339
|
"absolute IRI" => ["http://example.com/", "http://example.com/"],
|
1391
1340
|
"prefix:suffix" => ["ex:suffix", "http://example.org/suffix"],
|
1392
1341
|
"keyword" => ["@type", "@type"],
|
1393
|
-
"empty" => [":suffix", "http://empty/suffix"],
|
1394
1342
|
"unmapped" => ["foo", "foo"],
|
1395
1343
|
"bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
|
1396
1344
|
"relative" => ["foo/bar", "http://base/foo/bar"],
|
@@ -1412,7 +1360,6 @@ describe JSON::LD::Context do
|
|
1412
1360
|
"absolute IRI" => ["http://example.com/", "http://example.com/"],
|
1413
1361
|
"prefix:suffix" => ["suffix", "http://example.org/suffix"],
|
1414
1362
|
"keyword" => ["@type", "@type"],
|
1415
|
-
"empty" => [":suffix", "http://empty/suffix"],
|
1416
1363
|
"unmapped" => ["foo", "foo"],
|
1417
1364
|
"bnode" => [JSON::LD::JsonLdError:: IRIConfusedWithPrefix, RDF::Node("a")],
|
1418
1365
|
"relative" => ["http://base/foo/bar", "http://base/foo/bar"],
|
@@ -1543,7 +1490,7 @@ describe JSON::LD::Context do
|
|
1543
1490
|
})
|
1544
1491
|
end
|
1545
1492
|
it "Compact @id that is a property IRI when @container is @list" do
|
1546
|
-
expect(ctx.compact_iri("http://example.org/ns#property",
|
1493
|
+
expect(ctx.compact_iri("http://example.org/ns#property", vocab: false)).
|
1547
1494
|
to produce("ex:property", logger)
|
1548
1495
|
end
|
1549
1496
|
end
|
@@ -1796,23 +1743,23 @@ describe JSON::LD::Context do
|
|
1796
1743
|
|
1797
1744
|
it "uses TermDefinition" do
|
1798
1745
|
{
|
1799
|
-
"ex" =>
|
1800
|
-
"graph" =>
|
1801
|
-
"graphSet" =>
|
1802
|
-
"graphId" =>
|
1803
|
-
"graphIdSet" =>
|
1804
|
-
"graphNdx" =>
|
1805
|
-
"graphNdxSet" =>
|
1806
|
-
"id" =>
|
1807
|
-
"idSet" =>
|
1808
|
-
"language" =>
|
1809
|
-
"langSet" =>
|
1810
|
-
"list" =>
|
1811
|
-
"ndx" =>
|
1812
|
-
"ndxSet" =>
|
1813
|
-
"set" =>
|
1814
|
-
"type" =>
|
1815
|
-
"typeSet" =>
|
1746
|
+
"ex" => Set.new,
|
1747
|
+
"graph" => Set["@graph"],
|
1748
|
+
"graphSet" => Set["@graph"],
|
1749
|
+
"graphId" => Set["@graph", "@id"],
|
1750
|
+
"graphIdSet" => Set["@graph", "@id"],
|
1751
|
+
"graphNdx" => Set["@graph", "@index"],
|
1752
|
+
"graphNdxSet" => Set["@graph", "@index"],
|
1753
|
+
"id" => Set['@id'],
|
1754
|
+
"idSet" => Set['@id'],
|
1755
|
+
"language" => Set['@language'],
|
1756
|
+
"langSet" => Set['@language'],
|
1757
|
+
"list" => Set['@list'],
|
1758
|
+
"ndx" => Set['@index'],
|
1759
|
+
"ndxSet" => Set['@index'],
|
1760
|
+
"set" => Set.new,
|
1761
|
+
"type" => Set['@type'],
|
1762
|
+
"typeSet" => Set['@type'],
|
1816
1763
|
}.each do |defn, container|
|
1817
1764
|
expect(subject.container(subject.term_definitions[defn])).to eq container
|
1818
1765
|
end
|
@@ -1844,23 +1791,23 @@ describe JSON::LD::Context do
|
|
1844
1791
|
|
1845
1792
|
it "uses array" do
|
1846
1793
|
{
|
1847
|
-
"ex" =>
|
1848
|
-
"graph" =>
|
1849
|
-
"graphSet" =>
|
1850
|
-
"graphId" =>
|
1851
|
-
"graphIdSet" =>
|
1852
|
-
"graphNdx" =>
|
1853
|
-
"graphNdxSet" =>
|
1854
|
-
"id" =>
|
1855
|
-
"idSet" =>
|
1856
|
-
"language" =>
|
1857
|
-
"langSet" =>
|
1858
|
-
"list" =>
|
1859
|
-
"ndx" =>
|
1860
|
-
"ndxSet" =>
|
1861
|
-
"set" =>
|
1862
|
-
"type" =>
|
1863
|
-
"typeSet" =>
|
1794
|
+
"ex" => Set.new,
|
1795
|
+
"graph" => Set["@graph"],
|
1796
|
+
"graphSet" => Set["@graph"],
|
1797
|
+
"graphId" => Set["@graph", "@id"],
|
1798
|
+
"graphIdSet" => Set["@graph", "@id"],
|
1799
|
+
"graphNdx" => Set["@graph", "@index"],
|
1800
|
+
"graphNdxSet" => Set["@graph", "@index"],
|
1801
|
+
"id" => Set['@id'],
|
1802
|
+
"idSet" => Set['@id'],
|
1803
|
+
"language" => Set['@language'],
|
1804
|
+
"langSet" => Set['@language'],
|
1805
|
+
"list" => Set['@list'],
|
1806
|
+
"ndx" => Set['@index'],
|
1807
|
+
"ndxSet" => Set['@index'],
|
1808
|
+
"set" => Set.new,
|
1809
|
+
"type" => Set['@type'],
|
1810
|
+
"typeSet" => Set['@type'],
|
1864
1811
|
}.each do |defn, container|
|
1865
1812
|
expect(subject.container(defn)).to eq container
|
1866
1813
|
end
|
@@ -2053,13 +2000,13 @@ describe JSON::LD::Context do
|
|
2053
2000
|
|
2054
2001
|
context "with container_mapping @id @set" do
|
2055
2002
|
subject {described_class.new("term", container_mapping: %w(@id @set))}
|
2056
|
-
its(:container_mapping) {is_expected.to eq
|
2003
|
+
its(:container_mapping) {is_expected.to eq Set['@id']}
|
2057
2004
|
its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: ["@id", "@set"]))}
|
2058
2005
|
end
|
2059
2006
|
|
2060
2007
|
context "with container_mapping @list" do
|
2061
2008
|
subject {described_class.new("term", container_mapping: "@list")}
|
2062
|
-
its(:container_mapping) {is_expected.to eq
|
2009
|
+
its(:container_mapping) {is_expected.to eq Set['@list']}
|
2063
2010
|
its(:to_rb) {is_expected.to eq %(TermDefinition.new("term", container_mapping: "@list"))}
|
2064
2011
|
end
|
2065
2012
|
|