json-ld 1.1.4 → 1.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/VERSION +1 -1
- data/lib/json/ld/api.rb +3 -1
- data/lib/json/ld/from_rdf.rb +1 -1
- data/lib/json/ld/resource.rb +1 -1
- data/lib/json/ld/utils.rb +17 -0
- data/lib/json/ld/writer.rb +8 -1
- data/spec/to_rdf_spec.rb +11 -4
- data/spec/writer_spec.rb +23 -19
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1c1389086ba31e386a000da8030526ae1ea6e8e
|
4
|
+
data.tar.gz: 499467568e4eceedea6d0617c5c1abef5416b532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5c24e2bc724dfa18413f801893b8bf2fdbd2cef0dc228f037f2b746c8dc9bf9a0de854a182467302d75f3716327b8058754615b479dc5855e2f51d695fd063
|
7
|
+
data.tar.gz: 71c39dc45f62e606fb49a43ef73f7b1f05316aca43d995dbd2f5bf93f617766c6dfb10f785187843915d344c3694b4e83049dd23331dfa407651c832f9b8ed51
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.5
|
data/lib/json/ld/api.rb
CHANGED
@@ -72,6 +72,8 @@ module JSON::LD
|
|
72
72
|
# If set to `true`, the JSON-LD processor will treat `rdf:type` like a normal property instead of using `@type`.
|
73
73
|
# @option options [Boolean] :rename_bnodes (true)
|
74
74
|
# Rename bnodes as part of expansion, or keep them the same.
|
75
|
+
# @option options [Boolean] :unique_bnodes (false)
|
76
|
+
# Use unique bnode identifiers, defaults to using the identifier which the node was originall initialized with (if any).
|
75
77
|
# @yield [api]
|
76
78
|
# @yieldparam [API]
|
77
79
|
def initialize(input, context, options = {}, &block)
|
@@ -79,7 +81,7 @@ module JSON::LD
|
|
79
81
|
@options[:validate] = true if @options[:processingMode] == "json-ld-1.0"
|
80
82
|
@options[:documentLoader] ||= self.class.method(:documentLoader)
|
81
83
|
options[:rename_bnodes] ||= true
|
82
|
-
@namer = options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new
|
84
|
+
@namer = options[:unique_bnodes] ? BlankNodeUniqer.new : (options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
|
83
85
|
@value = case input
|
84
86
|
when Array, Hash then input.dup
|
85
87
|
when IO, StringIO
|
data/lib/json/ld/from_rdf.rb
CHANGED
@@ -62,7 +62,7 @@ module JSON::LD
|
|
62
62
|
next unless nil_var = graph_object[RDF.nil.to_s]
|
63
63
|
|
64
64
|
# For each item usage in the usages member of nil, perform the following steps:
|
65
|
-
nil_var
|
65
|
+
nil_var.fetch(:usages, []).each do |usage|
|
66
66
|
node, property, head = usage[:node], usage[:property], usage[:value]
|
67
67
|
list, list_nodes = [], []
|
68
68
|
|
data/lib/json/ld/resource.rb
CHANGED
data/lib/json/ld/utils.rb
CHANGED
@@ -163,6 +163,23 @@ module JSON::LD
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
class BlankNodeUniqer < BlankNodeMapper
|
167
|
+
##
|
168
|
+
# Use the uniquely generated bnodes, rather than a sequence
|
169
|
+
# @param [String] old ("")
|
170
|
+
# @return [String]
|
171
|
+
def get_sym(old = "")
|
172
|
+
old = old.to_s.sub(/_:/, '')
|
173
|
+
if old && self.has_key?(old)
|
174
|
+
self[old]
|
175
|
+
elsif !old.empty?
|
176
|
+
self[old] = RDF::Node.new.to_unique_base[2..-1]
|
177
|
+
else
|
178
|
+
RDF::Node.new.to_unique_base[2..-1]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
166
183
|
class BlankNodeNamer < BlankNodeMapper
|
167
184
|
# @param [String] prefix
|
168
185
|
def initialize(prefix)
|
data/lib/json/ld/writer.rb
CHANGED
@@ -85,6 +85,8 @@ module JSON::LD
|
|
85
85
|
# Add standard prefixes to @prefixes, if necessary.
|
86
86
|
# @option options [IO, Array, Hash, String, Context] :context ({})
|
87
87
|
# context to use when serializing. Constructed context for native serialization.
|
88
|
+
# @option options [Boolean] :unique_bnodes (false)
|
89
|
+
# Use unique bnode identifiers, defaults to using the identifier which the node was originall initialized with (if any).
|
88
90
|
# @yield [writer] `self`
|
89
91
|
# @yieldparam [RDF::Writer] writer
|
90
92
|
# @yieldreturn [void]
|
@@ -160,7 +162,12 @@ module JSON::LD
|
|
160
162
|
end if @options[:prefixes]
|
161
163
|
ctx
|
162
164
|
end
|
163
|
-
|
165
|
+
|
166
|
+
# Rename BNodes to uniquify them, if necessary
|
167
|
+
if options[:unique_bnodes]
|
168
|
+
result = API.flatten(result, context, @options)
|
169
|
+
end
|
170
|
+
|
164
171
|
# Perform compaction, if we have a context
|
165
172
|
if context
|
166
173
|
debug("writer") { "compact result"}
|
data/spec/to_rdf_spec.rb
CHANGED
@@ -25,6 +25,13 @@ describe JSON::LD::API do
|
|
25
25
|
}),
|
26
26
|
%q([ <http://example.com/foo> "bar"^^xsd:string] .)
|
27
27
|
],
|
28
|
+
"@id with _:a and reference" => [
|
29
|
+
%q({
|
30
|
+
"@id": "_:a",
|
31
|
+
"http://example.com/foo": {"@id": "_:a"}
|
32
|
+
}),
|
33
|
+
%q(_:a <http://example.com/foo> _:a .)
|
34
|
+
],
|
28
35
|
}.each do |title, (js, ttl)|
|
29
36
|
it title do
|
30
37
|
ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
|
@@ -56,21 +63,21 @@ describe JSON::LD::API do
|
|
56
63
|
"@id": "",
|
57
64
|
"@type": "#{RDF::RDFS.Resource}"
|
58
65
|
}),
|
59
|
-
%(<http://example.org/> a <#{RDF::RDFS.Resource}>)
|
66
|
+
%(<http://example.org/> a <#{RDF::RDFS.Resource}> .)
|
60
67
|
],
|
61
68
|
"relative" => [
|
62
69
|
%({
|
63
70
|
"@id": "a/b",
|
64
71
|
"@type": "#{RDF::RDFS.Resource}"
|
65
72
|
}),
|
66
|
-
%(<http://example.org/a/b> a <#{RDF::RDFS.Resource}>)
|
73
|
+
%(<http://example.org/a/b> a <#{RDF::RDFS.Resource}> .)
|
67
74
|
],
|
68
75
|
"hash" => [
|
69
76
|
%({
|
70
77
|
"@id": "#a",
|
71
78
|
"@type": "#{RDF::RDFS.Resource}"
|
72
79
|
}),
|
73
|
-
%(<http://example.org/#a> a <#{RDF::RDFS.Resource}>)
|
80
|
+
%(<http://example.org/#a> a <#{RDF::RDFS.Resource}> .)
|
74
81
|
],
|
75
82
|
}.each do |title, (js, ttl)|
|
76
83
|
it title do
|
@@ -660,7 +667,7 @@ describe JSON::LD::API do
|
|
660
667
|
def parse(input, options = {})
|
661
668
|
@debug = []
|
662
669
|
graph = options[:graph] || RDF::Graph.new
|
663
|
-
options = {:
|
670
|
+
options = {debug: @debug, validate: true, canonicalize: false}.merge(options)
|
664
671
|
JSON::LD::API.toRdf(StringIO.new(input), options) {|st| graph << st}
|
665
672
|
graph
|
666
673
|
end
|
data/spec/writer_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe JSON::LD::Writer do
|
|
20
20
|
{:content_type => 'application/x-ld+json'},
|
21
21
|
].each do |arg|
|
22
22
|
it "discovers with #{arg.inspect}" do
|
23
|
-
RDF::Reader.for(arg).
|
23
|
+
expect(RDF::Reader.for(arg)).to eql JSON::LD::Reader
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -28,7 +28,7 @@ describe JSON::LD::Writer do
|
|
28
28
|
context "simple tests" do
|
29
29
|
it "should use full URIs without base" do
|
30
30
|
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
31
|
-
serialize(input).
|
31
|
+
expect(serialize(input)).to produce([{
|
32
32
|
'@id' => "http://a/b",
|
33
33
|
"http://a/c" => [{"@id" => "http://a/d"}]
|
34
34
|
}], @debug)
|
@@ -36,8 +36,7 @@ describe JSON::LD::Writer do
|
|
36
36
|
|
37
37
|
it "should use qname URIs with standard prefix" do
|
38
38
|
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
|
39
|
-
serialize(input, :standard_prefixes => true).
|
40
|
-
should produce({
|
39
|
+
expect(serialize(input, :standard_prefixes => true)).to produce({
|
41
40
|
'@context' => {
|
42
41
|
"foaf" => "http://xmlns.com/foaf/0.1/",
|
43
42
|
},
|
@@ -53,12 +52,11 @@ describe JSON::LD::Writer do
|
|
53
52
|
<https://senet.org/gm> <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en .
|
54
53
|
<https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
|
55
54
|
)
|
56
|
-
serialize(input, :prefixes => {
|
55
|
+
expect(serialize(input, :prefixes => {
|
57
56
|
:dc => "http://purl.org/dc/terms/",
|
58
57
|
:frbr => "http://vocab.org/frbr/core#",
|
59
58
|
:senet => "https://senet.org/ns#",
|
60
|
-
}).
|
61
|
-
should produce({
|
59
|
+
})).to produce({
|
62
60
|
'@context' => {
|
63
61
|
"dc" => "http://purl.org/dc/terms/",
|
64
62
|
"frbr" => "http://vocab.org/frbr/core#",
|
@@ -75,8 +73,8 @@ describe JSON::LD::Writer do
|
|
75
73
|
it "should use CURIEs with empty prefix" do
|
76
74
|
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
|
77
75
|
begin
|
78
|
-
serialize(input, :prefixes => { "" => RDF::FOAF}).
|
79
|
-
|
76
|
+
expect(serialize(input, :prefixes => { "" => RDF::FOAF})).
|
77
|
+
to produce({
|
80
78
|
"@context" => {
|
81
79
|
"" => "http://xmlns.com/foaf/0.1/"
|
82
80
|
},
|
@@ -92,8 +90,8 @@ describe JSON::LD::Writer do
|
|
92
90
|
|
93
91
|
it "should not use terms if no suffix" do
|
94
92
|
input = %(<http://xmlns.com/foaf/0.1/> <http://xmlns.com/foaf/0.1/> <http://xmlns.com/foaf/0.1/> .)
|
95
|
-
serialize(input, :standard_prefixes => true).
|
96
|
-
|
93
|
+
expect(serialize(input, :standard_prefixes => true)).
|
94
|
+
not_to produce({
|
97
95
|
"@context" => {"foaf" => "http://xmlns.com/foaf/0.1/"},
|
98
96
|
'@id' => "foaf",
|
99
97
|
"foaf" => {"@id" => "foaf"}
|
@@ -107,10 +105,10 @@ describe JSON::LD::Writer do
|
|
107
105
|
db:Michael_Jackson dbo:artistOf <http://dbpedia.org/resource/%28I_Can%27t_Make_It%29_Another_Day> .
|
108
106
|
)
|
109
107
|
|
110
|
-
serialize(input, :prefixes => {
|
108
|
+
expect(serialize(input, :prefixes => {
|
111
109
|
"db" => RDF::URI("http://dbpedia.org/resource/"),
|
112
|
-
"dbo" => RDF::URI("http://dbpedia.org/ontology/")}).
|
113
|
-
|
110
|
+
"dbo" => RDF::URI("http://dbpedia.org/ontology/")})).
|
111
|
+
to produce({
|
114
112
|
"@context" => {
|
115
113
|
"db" => "http://dbpedia.org/resource/",
|
116
114
|
"dbo" => "http://dbpedia.org/ontology/"
|
@@ -120,6 +118,12 @@ describe JSON::LD::Writer do
|
|
120
118
|
}, @debug)
|
121
119
|
end
|
122
120
|
|
121
|
+
it "should not use provided node identifiers if :unique_bnodes set" do
|
122
|
+
input = %(_:a <http://example.com/foo> _:b \.)
|
123
|
+
result = serialize(input, unique_bnodes: true, context: {})
|
124
|
+
expect(result.to_json).to match(%r(_:g\w+))
|
125
|
+
end
|
126
|
+
|
123
127
|
it "serializes multiple subjects" do
|
124
128
|
input = %q(
|
125
129
|
@prefix : <http://www.w3.org/2006/03/test-description#> .
|
@@ -127,8 +131,8 @@ describe JSON::LD::Writer do
|
|
127
131
|
<http://example.com/test-cases/0001> a :TestCase .
|
128
132
|
<http://example.com/test-cases/0002> a :TestCase .
|
129
133
|
)
|
130
|
-
serialize(input, :prefixes => {"" => "http://www.w3.org/2006/03/test-description#"}).
|
131
|
-
|
134
|
+
expect(serialize(input, :prefixes => {"" => "http://www.w3.org/2006/03/test-description#"})).
|
135
|
+
to produce({
|
132
136
|
'@context' => {
|
133
137
|
"" => "http://www.w3.org/2006/03/test-description#",
|
134
138
|
"dc" => RDF::DC.to_s
|
@@ -154,12 +158,12 @@ describe JSON::LD::Writer do
|
|
154
158
|
owl:onClass <http://data.wikia.com/terms#Element>;
|
155
159
|
owl:onProperty <http://data.wikia.com/terms#characterIn> .
|
156
160
|
)
|
157
|
-
serialize(input, :rename_bnodes => false, :prefixes => {
|
161
|
+
expect(serialize(input, :rename_bnodes => false, :prefixes => {
|
158
162
|
:owl => "http://www.w3.org/2002/07/owl#",
|
159
163
|
:rdfs => "http://www.w3.org/2000/01/rdf-schema#",
|
160
164
|
:xsd => "http://www.w3.org/2001/XMLSchema#"
|
161
|
-
}).
|
162
|
-
|
165
|
+
})).
|
166
|
+
to produce({
|
163
167
|
'@context' => {
|
164
168
|
"owl" => "http://www.w3.org/2002/07/owl#",
|
165
169
|
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-ld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: equivalent-xml
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|