json-ld 3.2.4 → 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -771
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1913
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +223 -204
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -169
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +55 -198
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2056
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2541
- data/spec/from_rdf_spec.rb +0 -1072
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1684
- data/spec/writer_spec.rb +0 -427
data/spec/api_spec.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
|
2
|
-
# coding: utf-8
|
3
|
-
require_relative 'spec_helper'
|
4
|
-
|
5
|
-
describe JSON::LD::API do
|
6
|
-
let(:logger) {RDF::Spec.logger}
|
7
|
-
before {JSON::LD::Context::PRELOADED.clear}
|
8
|
-
|
9
|
-
describe "#initialize" do
|
10
|
-
context "with string input" do
|
11
|
-
let(:context) do
|
12
|
-
JSON::LD::API::RemoteDocument.new(%q({
|
13
|
-
"@context": {
|
14
|
-
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
15
|
-
"name": "http://xmlns.com/foaf/0.1/name",
|
16
|
-
"homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
|
17
|
-
"avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
|
18
|
-
}
|
19
|
-
}),
|
20
|
-
documentUrl: "http://example.com/context",
|
21
|
-
contentType: 'application/ld+json'
|
22
|
-
)
|
23
|
-
end
|
24
|
-
let(:remote_doc) do
|
25
|
-
JSON::LD::API::RemoteDocument.new(%q({"@id": "", "name": "foo"}),
|
26
|
-
documentUrl: "http://example.com/foo",
|
27
|
-
contentType: 'application/ld+json',
|
28
|
-
contextUrl: "http://example.com/context"
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "loads document with loader and loads context" do
|
33
|
-
expect(described_class).to receive(:documentLoader).with("http://example.com/foo", anything).and_yield(remote_doc)
|
34
|
-
expect(described_class).to receive(:documentLoader).with("http://example.com/context", anything).and_yield(context)
|
35
|
-
described_class.new("http://example.com/foo", nil)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when validating", pending: ("JRuby support for jsonlint" if RUBY_ENGINE == "jruby") do
|
41
|
-
it "detects invalid JSON" do
|
42
|
-
expect {described_class.new(StringIO.new(%({"a": "b", "a": "c"})), nil, validate: true)}.to raise_error(JSON::LD::JsonLdError::LoadingDocumentFailed)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "Test Files" do
|
47
|
-
%i(oj json_gem ok_json yajl).each do |adapter|
|
48
|
-
context "with MultiJson adapter #{adapter.inspect}" do
|
49
|
-
Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), 'test-files/*-input.*'))) do |filename|
|
50
|
-
test = File.basename(filename).sub(/-input\..*$/, '')
|
51
|
-
frame = filename.sub(/-input\..*$/, '-frame.jsonld')
|
52
|
-
framed = filename.sub(/-input\..*$/, '-framed.jsonld')
|
53
|
-
compacted = filename.sub(/-input\..*$/, '-compacted.jsonld')
|
54
|
-
context = filename.sub(/-input\..*$/, '-context.jsonld')
|
55
|
-
expanded = filename.sub(/-input\..*$/, '-expanded.jsonld')
|
56
|
-
ttl = filename.sub(/-input\..*$/, '-rdf.ttl')
|
57
|
-
|
58
|
-
context test, skip: ("Not supported in JRuby" if RUBY_ENGINE == "jruby" && %w(oj yajl).include?(adapter.to_s)) do
|
59
|
-
around do |example|
|
60
|
-
@file = File.open(filename)
|
61
|
-
case filename
|
62
|
-
when /.jsonld$/
|
63
|
-
@file.define_singleton_method(:content_type) {'application/ld+json'}
|
64
|
-
end
|
65
|
-
if context
|
66
|
-
@ctx_io = File.open(context)
|
67
|
-
case context
|
68
|
-
when /.jsonld$/
|
69
|
-
@ctx_io.define_singleton_method(:content_type) {'application/ld+json'}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
example.run
|
73
|
-
@file.close
|
74
|
-
@ctx_io.close if @ctx_io
|
75
|
-
end
|
76
|
-
|
77
|
-
if File.exist?(expanded)
|
78
|
-
it "expands" do
|
79
|
-
options = {logger: logger, adapter: adapter}
|
80
|
-
options[:expandContext] = @ctx_io if context
|
81
|
-
jld = described_class.expand(@file, **options)
|
82
|
-
expect(jld).to produce_jsonld(JSON.parse(File.read(expanded)), logger)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "expands with serializer" do
|
86
|
-
options = {logger: logger, adapter: adapter}
|
87
|
-
options[:expandContext] = @ctx_io if context
|
88
|
-
jld = described_class.expand(@file, serializer: JSON::LD::API.method(:serializer), **options)
|
89
|
-
expect(jld).to be_a(String)
|
90
|
-
expect(JSON.load(jld)).to produce_jsonld(JSON.parse(File.read(expanded)), logger)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
if File.exist?(compacted) && File.exist?(context)
|
95
|
-
it "compacts" do
|
96
|
-
jld = described_class.compact(@file, @ctx_io, adapter: adapter, logger: logger)
|
97
|
-
expect(jld).to produce_jsonld(JSON.parse(File.read(compacted)), logger)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "compacts with serializer" do
|
101
|
-
jld = described_class.compact(@file, @ctx_io, serializer: JSON::LD::API.method(:serializer), adapter: adapter, logger: logger)
|
102
|
-
expect(jld).to be_a(String)
|
103
|
-
expect(JSON.load(jld)).to produce_jsonld(JSON.parse(File.read(compacted)), logger)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
if File.exist?(framed) && File.exist?(frame)
|
108
|
-
it "frames" do
|
109
|
-
File.open(frame) do |frame_io|
|
110
|
-
jld = described_class.frame(@file, frame_io, adapter: adapter, logger: logger)
|
111
|
-
expect(jld).to produce_jsonld(JSON.parse(File.read(framed)), logger)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "frames with serializer" do
|
116
|
-
File.open(frame) do |frame_io|
|
117
|
-
jld = described_class.frame(@file, frame_io, serializer: JSON::LD::API.method(:serializer), adapter: adapter, logger: logger)
|
118
|
-
expect(jld).to be_a(String)
|
119
|
-
expect(JSON.load(jld)).to produce_jsonld(JSON.parse(File.read(framed)), logger)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it "toRdf" do
|
125
|
-
expect(RDF::Repository.load(filename, format: :jsonld, adapter: adapter, logger: logger)).to be_equivalent_graph(RDF::Repository.load(ttl), logger: logger)
|
126
|
-
end if File.exist?(ttl)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|