json-ld 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/History.markdown +3 -0
  2. data/VERSION +1 -1
  3. data/bin/jsonld +134 -0
  4. data/lib/json/ld/api.rb +4 -4
  5. data/lib/json/ld/frame.rb +2 -1
  6. data/lib/json/ld/from_rdf.rb +1 -1
  7. data/spec/api_spec.rb +66 -0
  8. data/spec/compact_spec.rb +420 -0
  9. data/spec/evaluation_context_spec.rb +1039 -0
  10. data/spec/expand_spec.rb +625 -0
  11. data/spec/format_spec.rb +71 -0
  12. data/spec/frame_spec.rb +542 -0
  13. data/spec/from_rdf_spec.rb +316 -0
  14. data/spec/matchers.rb +67 -0
  15. data/spec/reader_spec.rb +79 -0
  16. data/spec/spec_helper.rb +56 -0
  17. data/spec/suite_helper.rb +184 -0
  18. data/spec/suite_spec.rb +104 -0
  19. data/spec/support/extensions.rb +10 -0
  20. data/spec/test-files/test-1-automatic.json +10 -0
  21. data/spec/test-files/test-1-compacted.json +10 -0
  22. data/spec/test-files/test-1-context.json +7 -0
  23. data/spec/test-files/test-1-expanded.json +5 -0
  24. data/spec/test-files/test-1-input.json +10 -0
  25. data/spec/test-files/test-1-normalized.json +8 -0
  26. data/spec/test-files/test-1-rdf.ttl +7 -0
  27. data/spec/test-files/test-2-automatic.json +27 -0
  28. data/spec/test-files/test-2-compacted.json +20 -0
  29. data/spec/test-files/test-2-context.json +7 -0
  30. data/spec/test-files/test-2-expanded.json +16 -0
  31. data/spec/test-files/test-2-input.json +20 -0
  32. data/spec/test-files/test-2-normalized.json +32 -0
  33. data/spec/test-files/test-2-rdf.ttl +14 -0
  34. data/spec/test-files/test-3-compacted.json +11 -0
  35. data/spec/test-files/test-3-context.json +8 -0
  36. data/spec/test-files/test-3-expanded.json +10 -0
  37. data/spec/test-files/test-3-input.json +11 -0
  38. data/spec/test-files/test-3-normalized.json +13 -0
  39. data/spec/test-files/test-3-rdf.ttl +7 -0
  40. data/spec/test-files/test-4-automatic.json +10 -0
  41. data/spec/test-files/test-4-compacted.json +10 -0
  42. data/spec/test-files/test-4-context.json +7 -0
  43. data/spec/test-files/test-4-expanded.json +6 -0
  44. data/spec/test-files/test-4-input.json +10 -0
  45. data/spec/test-files/test-4-rdf.ttl +5 -0
  46. data/spec/test-files/test-5-automatic.json +13 -0
  47. data/spec/test-files/test-5-compacted.json +13 -0
  48. data/spec/test-files/test-5-context.json +7 -0
  49. data/spec/test-files/test-5-expanded.json +9 -0
  50. data/spec/test-files/test-5-input.json +13 -0
  51. data/spec/test-files/test-5-rdf.ttl +6 -0
  52. data/spec/test-files/test-6-automatic.json +10 -0
  53. data/spec/test-files/test-6-compacted.json +10 -0
  54. data/spec/test-files/test-6-context.json +7 -0
  55. data/spec/test-files/test-6-expanded.json +10 -0
  56. data/spec/test-files/test-6-input.json +10 -0
  57. data/spec/test-files/test-6-rdf.ttl +5 -0
  58. data/spec/test-files/test-7-automatic.json +20 -0
  59. data/spec/test-files/test-7-compacted.json +23 -0
  60. data/spec/test-files/test-7-context.json +4 -0
  61. data/spec/test-files/test-7-expanded.json +20 -0
  62. data/spec/test-files/test-7-input.json +23 -0
  63. data/spec/test-files/test-7-rdf.ttl +13 -0
  64. data/spec/test-files/test-8-automatic.json +1 -0
  65. data/spec/test-files/test-8-compacted.json +34 -0
  66. data/spec/test-files/test-8-context.json +11 -0
  67. data/spec/test-files/test-8-expanded.json +24 -0
  68. data/spec/test-files/test-8-frame.json +18 -0
  69. data/spec/test-files/test-8-framed.json +29 -0
  70. data/spec/test-files/test-8-input.json +30 -0
  71. data/spec/test-files/test-8-rdf.ttl +15 -0
  72. data/spec/test-files/test-9-compacted.json +20 -0
  73. data/spec/test-files/test-9-context.json +13 -0
  74. data/spec/test-files/test-9-expanded.json +14 -0
  75. data/spec/test-files/test-9-input.json +12 -0
  76. data/spec/to_rdf_spec.rb +640 -0
  77. data/spec/writer_spec.rb +161 -0
  78. metadata +150 -22
@@ -0,0 +1,161 @@
1
+ # coding: utf-8
2
+ $:.unshift "."
3
+ require 'spec_helper'
4
+ require 'rdf/spec/writer'
5
+
6
+ describe JSON::LD::Writer do
7
+ before :each do
8
+ @writer = JSON::LD::Writer.new(StringIO.new(""))
9
+ end
10
+
11
+ it_should_behave_like RDF_Writer
12
+
13
+ describe ".for" do
14
+ formats = [
15
+ :jsonld,
16
+ "etc/doap.jsonld",
17
+ {:file_name => 'etc/doap.jsonld'},
18
+ {:file_extension => 'jsonld'},
19
+ {:content_type => 'application/ld+json'},
20
+ {:content_type => 'application/x-ld+json'},
21
+ ].each do |arg|
22
+ it "discovers with #{arg.inspect}" do
23
+ RDF::Reader.for(arg).should == JSON::LD::Reader
24
+ end
25
+ end
26
+ end
27
+
28
+ context "simple tests" do
29
+ it "should use full URIs without base" do
30
+ input = %(<http://a/b> <http://a/c> <http://a/d> .)
31
+ serialize(input).should produce([{
32
+ '@id' => "http://a/b",
33
+ "http://a/c" => [{"@id" => "http://a/d"}]
34
+ }], @debug)
35
+ end
36
+
37
+ it "should use qname URIs with standard prefix" do
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({
41
+ '@context' => {
42
+ "foaf" => "http://xmlns.com/foaf/0.1/",
43
+ },
44
+ '@id' => "foaf:b",
45
+ "foaf:c" => {"@id" => "foaf:d"}
46
+ }, @debug)
47
+ end
48
+
49
+ it "should use qname URIs with parsed prefix" do
50
+ input = %(
51
+ <https://senet.org/gm> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://vocab.org/frbr/core#Work> .
52
+ <https://senet.org/gm> <http://purl.org/dc/terms/title> "Rhythm Paradise"@en .
53
+ <https://senet.org/gm> <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en .
54
+ <https://senet.org/gm> <https://senet.org/ns#urlkey> "rhythm-tengoku" .
55
+ )
56
+ serialize(input, :prefixes => {
57
+ :dc => "http://purl.org/dc/terms/",
58
+ :frbr => "http://vocab.org/frbr/core#",
59
+ :senet => "https://senet.org/ns#",
60
+ }).
61
+ should produce({
62
+ '@context' => {
63
+ "dc" => "http://purl.org/dc/terms/",
64
+ "frbr" => "http://vocab.org/frbr/core#",
65
+ "senet" => "https://senet.org/ns#"
66
+ },
67
+ '@id' => "https://senet.org/gm",
68
+ "@type" => "frbr:Work",
69
+ "dc:title" => {"@value" => "Rhythm Paradise","@language" => "en"},
70
+ "senet:unofficialTitle" => {"@value" => "Rhythm Tengoku","@language" => "en"},
71
+ "senet:urlkey" => "rhythm-tengoku"
72
+ }, @debug)
73
+ end
74
+
75
+ it "should use CURIEs with empty prefix" do
76
+ input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
77
+ begin
78
+ serialize(input, :prefixes => { "" => RDF::FOAF}).
79
+ should produce({
80
+ "@context" => {
81
+ "" => "http://xmlns.com/foaf/0.1/"
82
+ },
83
+ '@id' => ":b",
84
+ ":c" => {"@id" => ":d"}
85
+ }, @debug)
86
+ rescue JSON::LD::ProcessingError, JSON::LD::InvalidContext, TypeError => e
87
+ fail("#{e.class}: #{e.message}\n" +
88
+ "#{@debug.join("\n")}\n" +
89
+ "Backtrace:\n#{e.backtrace.join("\n")}")
90
+ end
91
+ end
92
+
93
+ it "should use terms if no suffix" do
94
+ 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
+ should produce({
97
+ "@context" => {"foaf" => "http://xmlns.com/foaf/0.1/"},
98
+ '@id' => "foaf",
99
+ "foaf" => {"@id" => "foaf"}
100
+ }, @debug)
101
+ end
102
+
103
+ it "should not use CURIE with illegal local part" do
104
+ input = %(
105
+ @prefix db: <http://dbpedia.org/resource/> .
106
+ @prefix dbo: <http://dbpedia.org/ontology/> .
107
+ db:Michael_Jackson dbo:artistOf <http://dbpedia.org/resource/%28I_Can%27t_Make_It%29_Another_Day> .
108
+ )
109
+
110
+ serialize(input, :prefixes => {
111
+ "db" => RDF::URI("http://dbpedia.org/resource/"),
112
+ "dbo" => RDF::URI("http://dbpedia.org/ontology/")}).
113
+ should produce({
114
+ "@context" => {
115
+ "db" => "http://dbpedia.org/resource/",
116
+ "dbo" => "http://dbpedia.org/ontology/"
117
+ },
118
+ '@id' => "db:Michael_Jackson",
119
+ "dbo:artistOf" => {"@id" => "db:%28I_Can%27t_Make_It%29_Another_Day"}
120
+ }, @debug)
121
+ end
122
+
123
+ it "serializes multiple subjects" do
124
+ input = %q(
125
+ @prefix : <http://www.w3.org/2006/03/test-description#> .
126
+ @prefix dc: <http://purl.org/dc/terms/> .
127
+ <http://example.com/test-cases/0001> a :TestCase .
128
+ <http://example.com/test-cases/0002> a :TestCase .
129
+ )
130
+ serialize(input, :prefixes => {"" => "http://www.w3.org/2006/03/test-description#"}).
131
+ should produce({
132
+ '@context' => {
133
+ "" => "http://www.w3.org/2006/03/test-description#",
134
+ "dc" => RDF::DC.to_s
135
+ },
136
+ '@graph' => [
137
+ {'@id' => "http://example.com/test-cases/0001", '@type' => ":TestCase"},
138
+ {'@id' => "http://example.com/test-cases/0002", '@type' => ":TestCase"}
139
+ ]
140
+ }, @debug)
141
+ end
142
+ end
143
+
144
+ def parse(input, options = {})
145
+ RDF::Graph.new << RDF::Turtle::Reader.new(input, options)
146
+ end
147
+
148
+ # Serialize ntstr to a string and compare against regexps
149
+ def serialize(ntstr, options = {})
150
+ g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
151
+ @debug = [] << g.dump(:ttl)
152
+ result = JSON::LD::Writer.buffer(options.merge(:debug => @debug)) do |writer|
153
+ writer << g
154
+ end
155
+ if $verbose
156
+ #puts hash.to_json
157
+ end
158
+
159
+ JSON.parse(result)
160
+ end
161
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -187,22 +187,6 @@ dependencies:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: 0.3.4
190
- - !ruby/object:Gem::Dependency
191
- name: sparql
192
- requirement: !ruby/object:Gem::Requirement
193
- none: false
194
- requirements:
195
- - - ! '>='
196
- - !ruby/object:Gem::Version
197
- version: 0.0.2
198
- type: :development
199
- prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
- requirements:
203
- - - ! '>='
204
- - !ruby/object:Gem::Version
205
- version: 0.0.2
206
190
  - !ruby/object:Gem::Dependency
207
191
  name: backports
208
192
  requirement: !ruby/object:Gem::Requirement
@@ -221,8 +205,9 @@ dependencies:
221
205
  version: '0'
222
206
  description: JSON::LD parses and serializes JSON-LD into RDF and implements expansion,
223
207
  compaction and framing API interfaces.
224
- email: public-rdf-ruby@w3.org
225
- executables: []
208
+ email: public-linked-json@w3.org
209
+ executables:
210
+ - jsonld
226
211
  extensions: []
227
212
  extra_rdoc_files: []
228
213
  files:
@@ -245,6 +230,78 @@ files:
245
230
  - lib/json/ld/version.rb
246
231
  - lib/json/ld/writer.rb
247
232
  - lib/json/ld.rb
233
+ - spec/api_spec.rb
234
+ - spec/compact_spec.rb
235
+ - spec/evaluation_context_spec.rb
236
+ - spec/expand_spec.rb
237
+ - spec/format_spec.rb
238
+ - spec/frame_spec.rb
239
+ - spec/from_rdf_spec.rb
240
+ - spec/matchers.rb
241
+ - spec/reader_spec.rb
242
+ - spec/spec_helper.rb
243
+ - spec/suite_helper.rb
244
+ - spec/suite_spec.rb
245
+ - spec/support/extensions.rb
246
+ - spec/to_rdf_spec.rb
247
+ - spec/writer_spec.rb
248
+ - spec/test-files/test-1-automatic.json
249
+ - spec/test-files/test-1-compacted.json
250
+ - spec/test-files/test-1-context.json
251
+ - spec/test-files/test-1-expanded.json
252
+ - spec/test-files/test-1-input.json
253
+ - spec/test-files/test-1-normalized.json
254
+ - spec/test-files/test-1-rdf.ttl
255
+ - spec/test-files/test-2-automatic.json
256
+ - spec/test-files/test-2-compacted.json
257
+ - spec/test-files/test-2-context.json
258
+ - spec/test-files/test-2-expanded.json
259
+ - spec/test-files/test-2-input.json
260
+ - spec/test-files/test-2-normalized.json
261
+ - spec/test-files/test-2-rdf.ttl
262
+ - spec/test-files/test-3-compacted.json
263
+ - spec/test-files/test-3-context.json
264
+ - spec/test-files/test-3-expanded.json
265
+ - spec/test-files/test-3-input.json
266
+ - spec/test-files/test-3-normalized.json
267
+ - spec/test-files/test-3-rdf.ttl
268
+ - spec/test-files/test-4-automatic.json
269
+ - spec/test-files/test-4-compacted.json
270
+ - spec/test-files/test-4-context.json
271
+ - spec/test-files/test-4-expanded.json
272
+ - spec/test-files/test-4-input.json
273
+ - spec/test-files/test-4-rdf.ttl
274
+ - spec/test-files/test-5-automatic.json
275
+ - spec/test-files/test-5-compacted.json
276
+ - spec/test-files/test-5-context.json
277
+ - spec/test-files/test-5-expanded.json
278
+ - spec/test-files/test-5-input.json
279
+ - spec/test-files/test-5-rdf.ttl
280
+ - spec/test-files/test-6-automatic.json
281
+ - spec/test-files/test-6-compacted.json
282
+ - spec/test-files/test-6-context.json
283
+ - spec/test-files/test-6-expanded.json
284
+ - spec/test-files/test-6-input.json
285
+ - spec/test-files/test-6-rdf.ttl
286
+ - spec/test-files/test-7-automatic.json
287
+ - spec/test-files/test-7-compacted.json
288
+ - spec/test-files/test-7-context.json
289
+ - spec/test-files/test-7-expanded.json
290
+ - spec/test-files/test-7-input.json
291
+ - spec/test-files/test-7-rdf.ttl
292
+ - spec/test-files/test-8-automatic.json
293
+ - spec/test-files/test-8-compacted.json
294
+ - spec/test-files/test-8-context.json
295
+ - spec/test-files/test-8-expanded.json
296
+ - spec/test-files/test-8-frame.json
297
+ - spec/test-files/test-8-framed.json
298
+ - spec/test-files/test-8-input.json
299
+ - spec/test-files/test-8-rdf.ttl
300
+ - spec/test-files/test-9-compacted.json
301
+ - spec/test-files/test-9-context.json
302
+ - spec/test-files/test-9-expanded.json
303
+ - spec/test-files/test-9-input.json
304
+ - bin/jsonld
248
305
  homepage: http://github.com/gkellogg/json-ld
249
306
  licenses:
250
307
  - Public Domain
@@ -266,9 +323,80 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
323
  version: '0'
267
324
  requirements: []
268
325
  rubyforge_project: json-ld
269
- rubygems_version: 1.8.24
326
+ rubygems_version: 1.8.23
270
327
  signing_key:
271
328
  specification_version: 3
272
329
  summary: JSON-LD reader/writer for Ruby.
273
- test_files: []
330
+ test_files:
331
+ - spec/api_spec.rb
332
+ - spec/compact_spec.rb
333
+ - spec/evaluation_context_spec.rb
334
+ - spec/expand_spec.rb
335
+ - spec/format_spec.rb
336
+ - spec/frame_spec.rb
337
+ - spec/from_rdf_spec.rb
338
+ - spec/matchers.rb
339
+ - spec/reader_spec.rb
340
+ - spec/spec_helper.rb
341
+ - spec/suite_helper.rb
342
+ - spec/suite_spec.rb
343
+ - spec/support/extensions.rb
344
+ - spec/to_rdf_spec.rb
345
+ - spec/writer_spec.rb
346
+ - spec/test-files/test-1-automatic.json
347
+ - spec/test-files/test-1-compacted.json
348
+ - spec/test-files/test-1-context.json
349
+ - spec/test-files/test-1-expanded.json
350
+ - spec/test-files/test-1-input.json
351
+ - spec/test-files/test-1-normalized.json
352
+ - spec/test-files/test-1-rdf.ttl
353
+ - spec/test-files/test-2-automatic.json
354
+ - spec/test-files/test-2-compacted.json
355
+ - spec/test-files/test-2-context.json
356
+ - spec/test-files/test-2-expanded.json
357
+ - spec/test-files/test-2-input.json
358
+ - spec/test-files/test-2-normalized.json
359
+ - spec/test-files/test-2-rdf.ttl
360
+ - spec/test-files/test-3-compacted.json
361
+ - spec/test-files/test-3-context.json
362
+ - spec/test-files/test-3-expanded.json
363
+ - spec/test-files/test-3-input.json
364
+ - spec/test-files/test-3-normalized.json
365
+ - spec/test-files/test-3-rdf.ttl
366
+ - spec/test-files/test-4-automatic.json
367
+ - spec/test-files/test-4-compacted.json
368
+ - spec/test-files/test-4-context.json
369
+ - spec/test-files/test-4-expanded.json
370
+ - spec/test-files/test-4-input.json
371
+ - spec/test-files/test-4-rdf.ttl
372
+ - spec/test-files/test-5-automatic.json
373
+ - spec/test-files/test-5-compacted.json
374
+ - spec/test-files/test-5-context.json
375
+ - spec/test-files/test-5-expanded.json
376
+ - spec/test-files/test-5-input.json
377
+ - spec/test-files/test-5-rdf.ttl
378
+ - spec/test-files/test-6-automatic.json
379
+ - spec/test-files/test-6-compacted.json
380
+ - spec/test-files/test-6-context.json
381
+ - spec/test-files/test-6-expanded.json
382
+ - spec/test-files/test-6-input.json
383
+ - spec/test-files/test-6-rdf.ttl
384
+ - spec/test-files/test-7-automatic.json
385
+ - spec/test-files/test-7-compacted.json
386
+ - spec/test-files/test-7-context.json
387
+ - spec/test-files/test-7-expanded.json
388
+ - spec/test-files/test-7-input.json
389
+ - spec/test-files/test-7-rdf.ttl
390
+ - spec/test-files/test-8-automatic.json
391
+ - spec/test-files/test-8-compacted.json
392
+ - spec/test-files/test-8-context.json
393
+ - spec/test-files/test-8-expanded.json
394
+ - spec/test-files/test-8-frame.json
395
+ - spec/test-files/test-8-framed.json
396
+ - spec/test-files/test-8-input.json
397
+ - spec/test-files/test-8-rdf.ttl
398
+ - spec/test-files/test-9-compacted.json
399
+ - spec/test-files/test-9-context.json
400
+ - spec/test-files/test-9-expanded.json
401
+ - spec/test-files/test-9-input.json
274
402
  has_rdoc: false