yaml-ld 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +1 -0
  3. data/README.md +150 -0
  4. data/UNLICENSE +24 -0
  5. data/VERSION +1 -0
  6. data/lib/yaml_ld/api.rb +295 -0
  7. data/lib/yaml_ld/format.rb +56 -0
  8. data/lib/yaml_ld/reader.rb +40 -0
  9. data/lib/yaml_ld/version.rb +20 -0
  10. data/lib/yaml_ld/writer.rb +42 -0
  11. data/lib/yaml_ld.rb +37 -0
  12. data/spec/api_spec.rb +92 -0
  13. data/spec/compact_spec.rb +358 -0
  14. data/spec/expand_spec.rb +565 -0
  15. data/spec/flatten_spec.rb +225 -0
  16. data/spec/format_spec.rb +54 -0
  17. data/spec/frame_spec.rb +662 -0
  18. data/spec/from_rdf_spec.rb +730 -0
  19. data/spec/matchers.rb +22 -0
  20. data/spec/reader_spec.rb +138 -0
  21. data/spec/spec_helper.rb +265 -0
  22. data/spec/support/extensions.rb +44 -0
  23. data/spec/test-files/test-1-compacted.jsonld +10 -0
  24. data/spec/test-files/test-1-context.jsonld +7 -0
  25. data/spec/test-files/test-1-expanded.jsonld +5 -0
  26. data/spec/test-files/test-1-input.yamlld +8 -0
  27. data/spec/test-files/test-1-rdf.ttl +8 -0
  28. data/spec/test-files/test-2-compacted.jsonld +20 -0
  29. data/spec/test-files/test-2-context.jsonld +7 -0
  30. data/spec/test-files/test-2-expanded.jsonld +16 -0
  31. data/spec/test-files/test-2-input.yamlld +16 -0
  32. data/spec/test-files/test-2-rdf.ttl +14 -0
  33. data/spec/test-files/test-3-compacted.jsonld +11 -0
  34. data/spec/test-files/test-3-context.jsonld +8 -0
  35. data/spec/test-files/test-3-expanded.jsonld +10 -0
  36. data/spec/test-files/test-3-input.yamlld +13 -0
  37. data/spec/test-files/test-3-rdf.ttl +8 -0
  38. data/spec/test-files/test-4-compacted.jsonld +10 -0
  39. data/spec/test-files/test-4-context.jsonld +7 -0
  40. data/spec/test-files/test-4-expanded.jsonld +6 -0
  41. data/spec/test-files/test-4-input.yamlld +9 -0
  42. data/spec/test-files/test-4-rdf.ttl +5 -0
  43. data/spec/test-files/test-5-compacted.jsonld +13 -0
  44. data/spec/test-files/test-5-context.jsonld +7 -0
  45. data/spec/test-files/test-5-expanded.jsonld +9 -0
  46. data/spec/test-files/test-5-input.yamlld +10 -0
  47. data/spec/test-files/test-5-rdf.ttl +7 -0
  48. data/spec/test-files/test-6-compacted.jsonld +10 -0
  49. data/spec/test-files/test-6-context.jsonld +7 -0
  50. data/spec/test-files/test-6-expanded.jsonld +10 -0
  51. data/spec/test-files/test-6-input.yamlld +12 -0
  52. data/spec/test-files/test-6-rdf.ttl +6 -0
  53. data/spec/test-files/test-7-compacted.jsonld +23 -0
  54. data/spec/test-files/test-7-context.jsonld +4 -0
  55. data/spec/test-files/test-7-expanded.jsonld +20 -0
  56. data/spec/test-files/test-7-input.yamlld +16 -0
  57. data/spec/test-files/test-7-rdf.ttl +14 -0
  58. data/spec/test-files/test-8-compacted.jsonld +34 -0
  59. data/spec/test-files/test-8-context.jsonld +11 -0
  60. data/spec/test-files/test-8-expanded.jsonld +24 -0
  61. data/spec/test-files/test-8-frame.jsonld +18 -0
  62. data/spec/test-files/test-8-framed.jsonld +25 -0
  63. data/spec/test-files/test-8-input.yamlld +24 -0
  64. data/spec/test-files/test-8-rdf.ttl +15 -0
  65. data/spec/test-files/test-9-compacted.jsonld +20 -0
  66. data/spec/test-files/test-9-context.jsonld +13 -0
  67. data/spec/test-files/test-9-expanded.jsonld +14 -0
  68. data/spec/test-files/test-9-input.yamlld +16 -0
  69. data/spec/to_rdf_spec.rb +556 -0
  70. data/spec/writer_spec.rb +441 -0
  71. metadata +350 -0
@@ -0,0 +1,225 @@
1
+ # coding: utf-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe JSON::LD::API do
5
+ let(:logger) {RDF::Spec.logger}
6
+
7
+ describe ".flatten" do
8
+ {
9
+ "single object": {
10
+ input: %(
11
+ "@id": http://example.com
12
+ "@type": http://www.w3.org/2000/01/rdf-schema#Resource
13
+ ),
14
+ output: %(
15
+ - "@id": http://example.com
16
+ "@type":
17
+ - http://www.w3.org/2000/01/rdf-schema#Resource
18
+ )
19
+ },
20
+ "embedded object": {
21
+ input: %(
22
+ "@context":
23
+ foaf: http://xmlns.com/foaf/0.1/
24
+ "@id": http://greggkellogg.net/foaf
25
+ "@type": http://xmlns.com/foaf/0.1/PersonalProfileDocument
26
+ foaf:primaryTopic:
27
+ - "@id": http://greggkellogg.net/foaf#me
28
+ "@type": http://xmlns.com/foaf/0.1/Person
29
+ ),
30
+ output: %(
31
+ - "@id": http://greggkellogg.net/foaf
32
+ "@type":
33
+ - http://xmlns.com/foaf/0.1/PersonalProfileDocument
34
+ http://xmlns.com/foaf/0.1/primaryTopic:
35
+ - "@id": http://greggkellogg.net/foaf#me
36
+ - "@id": http://greggkellogg.net/foaf#me
37
+ "@type":
38
+ - http://xmlns.com/foaf/0.1/Person
39
+ )
40
+ },
41
+ "embedded anon": {
42
+ input: %(
43
+ "@context":
44
+ foaf: http://xmlns.com/foaf/0.1/
45
+ "@id": http://greggkellogg.net/foaf
46
+ "@type": foaf:PersonalProfileDocument
47
+ foaf:primaryTopic:
48
+ "@type": foaf:Person
49
+ ),
50
+ output: %(
51
+ - "@id": _:b0
52
+ "@type":
53
+ - http://xmlns.com/foaf/0.1/Person
54
+ - "@id": http://greggkellogg.net/foaf
55
+ "@type":
56
+ - http://xmlns.com/foaf/0.1/PersonalProfileDocument
57
+ http://xmlns.com/foaf/0.1/primaryTopic:
58
+ - "@id": _:b0
59
+ )
60
+ },
61
+ "reverse properties": {
62
+ input: %(
63
+ - "@id": http://example.com/people/markus
64
+ "@reverse":
65
+ http://xmlns.com/foaf/0.1/knows:
66
+ - "@id": http://example.com/people/dave
67
+ - "@id": http://example.com/people/gregg
68
+ http://xmlns.com/foaf/0.1/name:
69
+ "@value": Markus Lanthaler
70
+ ),
71
+ output: %(
72
+ - "@id": http://example.com/people/dave
73
+ http://xmlns.com/foaf/0.1/knows:
74
+ - "@id": http://example.com/people/markus
75
+ - "@id": http://example.com/people/gregg
76
+ http://xmlns.com/foaf/0.1/knows:
77
+ - "@id": http://example.com/people/markus
78
+ - "@id": http://example.com/people/markus
79
+ http://xmlns.com/foaf/0.1/name:
80
+ - "@value": Markus Lanthaler
81
+ )
82
+ },
83
+ "Simple named graph (Wikidata)": {
84
+ input: %q(
85
+ "@context":
86
+ rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
87
+ ex: http://example.org/
88
+ xsd: http://www.w3.org/2001/XMLSchema#
89
+ ex:locatedIn:
90
+ "@type": "@id"
91
+ ex:hasPopulaton:
92
+ "@type": xsd:integer
93
+ ex:hasReference:
94
+ "@type": "@id"
95
+ "@graph":
96
+ - "@id": http://example.org/ParisFact1
97
+ "@type": rdf:Graph
98
+ "@graph":
99
+ "@id": http://example.org/location/Paris#this
100
+ ex:locatedIn: http://example.org/location/France#this
101
+ ex:hasReference:
102
+ - http://www.britannica.com/
103
+ - http://www.wikipedia.org/
104
+ - http://www.brockhaus.de/
105
+ - "@id": http://example.org/ParisFact2
106
+ "@type": rdf:Graph
107
+ "@graph":
108
+ "@id": http://example.org/location/Paris#this
109
+ ex:hasPopulation: 7000000
110
+ ex:hasReference: http://www.wikipedia.org/
111
+ ),
112
+ output: %q(
113
+ - "@id": http://example.org/ParisFact1
114
+ "@type":
115
+ - http://www.w3.org/1999/02/22-rdf-syntax-ns#Graph
116
+ http://example.org/hasReference:
117
+ - "@id": http://www.britannica.com/
118
+ - "@id": http://www.wikipedia.org/
119
+ - "@id": http://www.brockhaus.de/
120
+ "@graph":
121
+ - "@id": http://example.org/location/Paris#this
122
+ http://example.org/locatedIn:
123
+ - "@id": http://example.org/location/France#this
124
+ - "@id": http://example.org/ParisFact2
125
+ "@type":
126
+ - http://www.w3.org/1999/02/22-rdf-syntax-ns#Graph
127
+ http://example.org/hasReference:
128
+ - "@id": http://www.wikipedia.org/
129
+ "@graph":
130
+ - "@id": http://example.org/location/Paris#this
131
+ http://example.org/hasPopulation:
132
+ - "@value": 7000000
133
+ ),
134
+ },
135
+ "Test Manifest (shortened)": {
136
+ input: %q{
137
+ "@id": ''
138
+ http://example/sequence:
139
+ "@list":
140
+ - "@id": "#t0001"
141
+ http://example/name: Keywords cannot be aliased to other keywords
142
+ http://example/input:
143
+ "@id": error-expand-0001-in.jsonld
144
+ },
145
+ output: %q{
146
+ - "@id": ''
147
+ http://example/sequence:
148
+ - "@list":
149
+ - "@id": "#t0001"
150
+ - "@id": "#t0001"
151
+ http://example/input:
152
+ - "@id": error-expand-0001-in.jsonld
153
+ http://example/name:
154
+ - "@value": Keywords cannot be aliased to other keywords
155
+ },
156
+ },
157
+ "@list with embedded object": {
158
+ input: %(
159
+ - http://example.com/foo:
160
+ - "@list":
161
+ - "@id": http://example.com/baz
162
+ http://example.com/bar: buz
163
+ ),
164
+ output: %(
165
+ - "@id": _:b0
166
+ http://example.com/foo:
167
+ - "@list":
168
+ - "@id": http://example.com/baz
169
+ - "@id": http://example.com/baz
170
+ http://example.com/bar:
171
+ - "@value": buz
172
+ )
173
+ },
174
+ "coerced @list containing mixed list values": {
175
+ input: %(
176
+ "@context":
177
+ foo:
178
+ "@id": http://example.com/foo
179
+ "@container": "@list"
180
+ foo:
181
+ - - "@id": http://example/a
182
+ "@type": http://example/Bar
183
+ - "@id": http://example/b
184
+ "@type": http://example/Baz
185
+ ),
186
+ output: %(
187
+ - "@id": _:b0
188
+ http://example.com/foo:
189
+ - "@list":
190
+ - "@list":
191
+ - "@id": http://example/a
192
+ - "@id": http://example/b
193
+ - "@id": http://example/a
194
+ "@type":
195
+ - http://example/Bar
196
+ - "@id": http://example/b
197
+ "@type":
198
+ - http://example/Baz
199
+ )
200
+ },
201
+ }.each do |title, params|
202
+ it(title) {run_flatten(params)}
203
+ end
204
+ end
205
+
206
+ def run_flatten(params)
207
+ input, output, context = params[:input], params[:output], params[:context]
208
+ input = StringIO.new(input) if input.is_a?(String)
209
+ context = ::JSON.parse(context) if context.is_a?(String)
210
+ params[:base] ||= nil
211
+ pending params.fetch(:pending, "test implementation") unless input
212
+ if params[:exception]
213
+ expect {YAML_LD::API.flatten(input, context, logger: logger, **params)}.to raise_error(params[:exception])
214
+ else
215
+ yld = nil
216
+ if params[:write]
217
+ expect{yld = YAML_LD::API.flatten(input, context, logger: logger, **params)}.to write(params[:write]).to(:error)
218
+ else
219
+ expect{yld = YAML_LD::API.flatten(input, context, logger: logger, **params)}.not_to write.to(:error)
220
+ end
221
+
222
+ expect(yld).to produce_yamlld(output, logger)
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'rdf/spec/format'
4
+
5
+ describe YAML_LD::Format do
6
+ it_behaves_like 'an RDF::Format' do
7
+ let(:format_class) {YAML_LD::Format}
8
+ end
9
+
10
+ describe ".for" do
11
+ [
12
+ :yamlld,
13
+ "etc/doap.yamlld",
14
+ {file_name: 'etc/doap.yamlld'},
15
+ {file_extension: 'yamlld'},
16
+ {content_type: 'application/ld+yaml'},
17
+ ].each do |arg|
18
+ it "discovers with #{arg.inspect}" do
19
+ expect(RDF::Format.for(arg)).to eq described_class
20
+ end
21
+ end
22
+
23
+ {
24
+ yamlld: %(---
25
+ "@context": "foo"
26
+ ),
27
+ context: %(---
28
+ "@context": {
29
+ ),
30
+ id: %(---
31
+ "@id": "foo"
32
+ ),
33
+ type: %(---
34
+ "@type": "foo"
35
+ ),
36
+ }.each do |sym, str|
37
+ it "detects #{sym}" do
38
+ expect(described_class.for {str}).to eq described_class
39
+ end
40
+ end
41
+
42
+ it "should discover 'yamlld'" do
43
+ expect(RDF::Format.for(:yamlld).reader).to eq YAML_LD::Reader
44
+ end
45
+ end
46
+
47
+ describe "#to_sym" do
48
+ specify {expect(described_class.to_sym).to eq :yamlld}
49
+ end
50
+
51
+ describe "#to_uri" do
52
+ specify {expect(described_class.to_uri).to eq RDF::URI('http://www.w3.org/ns/formats/YAML-LD')}
53
+ end
54
+ end