yaml-ld 0.0.1 → 0.0.2

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/psych/amazing_print.rb +61 -0
  4. data/lib/yaml_ld/api.rb +69 -11
  5. data/lib/yaml_ld/format.rb +25 -0
  6. data/lib/yaml_ld/reader.rb +3 -1
  7. data/lib/yaml_ld/representation.rb +256 -0
  8. data/lib/yaml_ld/version.rb +1 -1
  9. data/lib/yaml_ld.rb +1 -0
  10. data/spec/api_spec.rb +21 -27
  11. data/spec/compact_spec.rb +1 -1
  12. data/spec/expand_spec.rb +1 -1
  13. data/spec/format_spec.rb +56 -0
  14. data/spec/frame_spec.rb +55 -110
  15. data/spec/from_rdf_spec.rb +3 -3
  16. data/spec/matchers.rb +2 -2
  17. data/spec/reader_spec.rb +1 -1
  18. data/spec/representation_spec.rb +170 -0
  19. data/spec/spec_helper.rb +1 -0
  20. data/spec/test-files/test-1-compacted.yamlld +9 -0
  21. data/spec/test-files/test-1-context.yamlld +6 -0
  22. data/spec/test-files/test-1-expanded.yamlld +8 -0
  23. data/spec/test-files/test-1-input.yamlld +1 -0
  24. data/spec/test-files/test-2-compacted.yamlld +17 -0
  25. data/spec/test-files/test-2-context.yamlld +5 -0
  26. data/spec/test-files/test-2-expanded.yamlld +21 -0
  27. data/spec/test-files/test-3-compacted.yamlld +14 -0
  28. data/spec/test-files/test-3-context.yamlld +11 -0
  29. data/spec/test-files/test-3-expanded.yamlld +9 -0
  30. data/spec/test-files/test-4-compacted.yamlld +10 -0
  31. data/spec/test-files/test-4-context.yamlld +5 -0
  32. data/spec/test-files/test-4-expanded.yamlld +9 -0
  33. data/spec/test-files/test-5-compacted.yamlld +11 -0
  34. data/spec/test-files/test-5-context.yamlld +5 -0
  35. data/spec/test-files/test-5-expanded.yamlld +12 -0
  36. data/spec/test-files/test-6-compacted.yamlld +13 -0
  37. data/spec/test-files/test-6-context.yamlld +5 -0
  38. data/spec/test-files/test-6-expanded.yamlld +12 -0
  39. data/spec/test-files/test-7-compacted.yamlld +17 -0
  40. data/spec/test-files/test-7-context.yamlld +4 -0
  41. data/spec/test-files/test-7-expanded.yamlld +23 -0
  42. data/spec/test-files/test-8-compacted.yamlld +25 -0
  43. data/spec/test-files/test-8-context.yamlld +12 -0
  44. data/spec/test-files/test-8-expanded.yamlld +23 -0
  45. data/spec/test-files/test-8-frame.yamlld +15 -0
  46. data/spec/test-files/test-8-framed.yamlld +22 -0
  47. data/spec/test-files/test-9-compacted.yamlld +31 -0
  48. data/spec/test-files/test-9-context.yamlld +20 -0
  49. data/spec/test-files/test-9-expanded.yamlld +17 -0
  50. data/spec/to_rdf_spec.rb +10 -8
  51. metadata +89 -61
  52. data/spec/test-files/test-1-expanded.jsonld +0 -5
  53. data/spec/test-files/test-2-compacted.jsonld +0 -20
  54. data/spec/test-files/test-2-context.jsonld +0 -7
  55. data/spec/test-files/test-2-expanded.jsonld +0 -16
  56. data/spec/test-files/test-3-compacted.jsonld +0 -11
  57. data/spec/test-files/test-3-context.jsonld +0 -8
  58. data/spec/test-files/test-3-expanded.jsonld +0 -10
  59. data/spec/test-files/test-4-compacted.jsonld +0 -10
  60. data/spec/test-files/test-4-context.jsonld +0 -7
  61. data/spec/test-files/test-4-expanded.jsonld +0 -6
  62. data/spec/test-files/test-5-compacted.jsonld +0 -13
  63. data/spec/test-files/test-5-context.jsonld +0 -7
  64. data/spec/test-files/test-5-expanded.jsonld +0 -9
  65. data/spec/test-files/test-6-compacted.jsonld +0 -10
  66. data/spec/test-files/test-6-context.jsonld +0 -7
  67. data/spec/test-files/test-6-expanded.jsonld +0 -10
  68. data/spec/test-files/test-7-compacted.jsonld +0 -23
  69. data/spec/test-files/test-7-context.jsonld +0 -4
  70. data/spec/test-files/test-7-expanded.jsonld +0 -20
  71. data/spec/test-files/test-8-compacted.jsonld +0 -34
  72. data/spec/test-files/test-8-context.jsonld +0 -11
  73. data/spec/test-files/test-8-expanded.jsonld +0 -24
  74. data/spec/test-files/test-8-frame.jsonld +0 -18
  75. data/spec/test-files/test-8-framed.jsonld +0 -25
  76. data/spec/test-files/test-9-compacted.jsonld +0 -20
  77. data/spec/test-files/test-9-context.jsonld +0 -13
  78. data/spec/test-files/test-9-expanded.jsonld +0 -14
@@ -0,0 +1,9 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ avatar: http://xmlns.com/foaf/0.1/avatar
5
+ homepage: http://xmlns.com/foaf/0.1/homepage
6
+ name: http://xmlns.com/foaf/0.1/name
7
+ avatar: http://twitter.com/account/profile_image/manusporny
8
+ homepage: http://manu.sporny.org/
9
+ name: Manu Sporny
@@ -0,0 +1,6 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ name: http://xmlns.com/foaf/0.1/name
5
+ homepage: http://xmlns.com/foaf/0.1/homepage
6
+ avatar: http://xmlns.com/foaf/0.1/avatar
@@ -0,0 +1,8 @@
1
+ %YAML 1.2
2
+ ---
3
+ - http://xmlns.com/foaf/0.1/name:
4
+ - "@value": Manu Sporny
5
+ http://xmlns.com/foaf/0.1/homepage:
6
+ - "@value": http://manu.sporny.org/
7
+ http://xmlns.com/foaf/0.1/avatar:
8
+ - "@value": http://twitter.com/account/profile_image/manusporny
@@ -1,3 +1,4 @@
1
+ %YAML 1.2
1
2
  ---
2
3
  "@context":
3
4
  name: http://xmlns.com/foaf/0.1/name
@@ -0,0 +1,17 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ dc: http://purl.org/dc/elements/1.1/
5
+ ex: http://example.org/vocab#
6
+ "@id": http://example.org/library
7
+ "@type": ex:Library
8
+ ex:contains:
9
+ "@id": http://example.org/library/the-republic
10
+ "@type": ex:Book
11
+ dc:creator: Plato
12
+ dc:title: The Republic
13
+ ex:contains:
14
+ "@id": http://example.org/library/the-republic#introduction
15
+ "@type": ex:Chapter
16
+ dc:description: An introductory chapter on The Republic.
17
+ dc:title: The Introduction
@@ -0,0 +1,5 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ dc: http://purl.org/dc/elements/1.1/
5
+ ex: http://example.org/vocab#
@@ -0,0 +1,21 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://example.org/library
4
+ "@type":
5
+ - http://example.org/vocab#Library
6
+ http://example.org/vocab#contains:
7
+ - "@id": http://example.org/library/the-republic
8
+ "@type":
9
+ - http://example.org/vocab#Book
10
+ http://purl.org/dc/elements/1.1/creator:
11
+ - "@value": Plato
12
+ http://purl.org/dc/elements/1.1/title:
13
+ - "@value": The Republic
14
+ http://example.org/vocab#contains:
15
+ - "@id": http://example.org/library/the-republic#introduction
16
+ "@type":
17
+ - http://example.org/vocab#Chapter
18
+ http://purl.org/dc/elements/1.1/description:
19
+ - "@value": An introductory chapter on The Republic.
20
+ http://purl.org/dc/elements/1.1/title:
21
+ - "@value": The Introduction
@@ -0,0 +1,14 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ xsd: http://www.w3.org/2001/XMLSchema#
5
+ name: http://xmlns.com/foaf/0.1/name
6
+ age:
7
+ "@id": http://xmlns.com/foaf/0.1/age
8
+ "@type": xsd:integer
9
+ homepage:
10
+ "@id": http://xmlns.com/foaf/0.1/homepage
11
+ "@type": "@id"
12
+ name: Manu Sporny
13
+ age: '41'
14
+ homepage: http://manu.sporny.org/
@@ -0,0 +1,11 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ xsd: http://www.w3.org/2001/XMLSchema#
5
+ name: http://xmlns.com/foaf/0.1/name
6
+ age:
7
+ "@id": http://xmlns.com/foaf/0.1/age
8
+ "@type": xsd:integer
9
+ homepage:
10
+ "@id": http://xmlns.com/foaf/0.1/homepage
11
+ "@type": "@id"
@@ -0,0 +1,9 @@
1
+ %YAML 1.2
2
+ ---
3
+ - http://xmlns.com/foaf/0.1/name:
4
+ - "@value": Manu Sporny
5
+ http://xmlns.com/foaf/0.1/age:
6
+ - "@type": http://www.w3.org/2001/XMLSchema#integer
7
+ "@value": '41'
8
+ http://xmlns.com/foaf/0.1/homepage:
9
+ - "@id": http://manu.sporny.org/
@@ -0,0 +1,10 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
6
+ "@id": ":#me"
7
+ "@type": foaf:Person
8
+ foaf:name: Manu Sporny
9
+ foaf:homepage:
10
+ "@id": http://manu.sporny.org/
@@ -0,0 +1,5 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
@@ -0,0 +1,9 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://manu.sporny.org/#me
4
+ "@type":
5
+ - http://xmlns.com/foaf/0.1/Person
6
+ http://xmlns.com/foaf/0.1/name:
7
+ - "@value": Manu Sporny
8
+ http://xmlns.com/foaf/0.1/homepage:
9
+ - "@id": http://manu.sporny.org/
@@ -0,0 +1,11 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
6
+ "@id": ":#me"
7
+ "@type": foaf:Person
8
+ foaf:name: Manu Sporny
9
+ foaf:knows:
10
+ "@type": foaf:Person
11
+ foaf:name: Gregg Kellogg
@@ -0,0 +1,5 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
@@ -0,0 +1,12 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://manu.sporny.org/#me
4
+ "@type":
5
+ - http://xmlns.com/foaf/0.1/Person
6
+ http://xmlns.com/foaf/0.1/name:
7
+ - "@value": Manu Sporny
8
+ http://xmlns.com/foaf/0.1/knows:
9
+ - "@type":
10
+ - http://xmlns.com/foaf/0.1/Person
11
+ http://xmlns.com/foaf/0.1/name:
12
+ - "@value": Gregg Kellogg
@@ -0,0 +1,13 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
6
+ "@id": http://example.org/people#joebob
7
+ "@type": foaf:Person
8
+ foaf:name: Joe Bob
9
+ foaf:nick:
10
+ "@list":
11
+ - joe
12
+ - bob
13
+ - jaybe
@@ -0,0 +1,5 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ '': http://manu.sporny.org/
5
+ foaf: http://xmlns.com/foaf/0.1/
@@ -0,0 +1,12 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://example.org/people#joebob
4
+ "@type":
5
+ - http://xmlns.com/foaf/0.1/Person
6
+ http://xmlns.com/foaf/0.1/name:
7
+ - "@value": Joe Bob
8
+ http://xmlns.com/foaf/0.1/nick:
9
+ - "@list":
10
+ - "@value": joe
11
+ - "@value": bob
12
+ - "@value": jaybe
@@ -0,0 +1,17 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ foaf: http://xmlns.com/foaf/0.1/
5
+ "@graph":
6
+ - "@id": _:bnode1
7
+ "@type": foaf:Person
8
+ foaf:homepage: http://example.com/bob/
9
+ foaf:name: Bob
10
+ - "@id": _:bnode2
11
+ "@type": foaf:Person
12
+ foaf:homepage: http://example.com/eve/
13
+ foaf:name: Eve
14
+ - "@id": _:bnode3
15
+ "@type": foaf:Person
16
+ foaf:homepage: http://example.com/manu/
17
+ foaf:name: Manu
@@ -0,0 +1,4 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ foaf: http://xmlns.com/foaf/0.1/
@@ -0,0 +1,23 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": _:bnode1
4
+ "@type":
5
+ - http://xmlns.com/foaf/0.1/Person
6
+ http://xmlns.com/foaf/0.1/homepage:
7
+ - "@value": http://example.com/bob/
8
+ http://xmlns.com/foaf/0.1/name:
9
+ - "@value": Bob
10
+ - "@id": _:bnode2
11
+ "@type":
12
+ - http://xmlns.com/foaf/0.1/Person
13
+ http://xmlns.com/foaf/0.1/homepage:
14
+ - "@value": http://example.com/eve/
15
+ http://xmlns.com/foaf/0.1/name:
16
+ - "@value": Eve
17
+ - "@id": _:bnode3
18
+ "@type":
19
+ - http://xmlns.com/foaf/0.1/Person
20
+ http://xmlns.com/foaf/0.1/homepage:
21
+ - "@value": http://example.com/manu/
22
+ http://xmlns.com/foaf/0.1/name:
23
+ - "@value": Manu
@@ -0,0 +1,25 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ Book: http://example.org/vocab#Book
5
+ Chapter: http://example.org/vocab#Chapter
6
+ contains:
7
+ "@id": http://example.org/vocab#contains
8
+ "@type": "@id"
9
+ creator: http://purl.org/dc/terms/creator
10
+ description: http://purl.org/dc/terms/description
11
+ Library: http://example.org/vocab#Library
12
+ title: http://purl.org/dc/terms/title
13
+ "@graph":
14
+ - "@id": http://example.com/library
15
+ "@type": Library
16
+ contains: http://example.org/library/the-republic
17
+ - "@id": http://example.org/library/the-republic
18
+ "@type": Book
19
+ creator: Plato
20
+ title: The Republic
21
+ contains: http://example.org/library/the-republic#introduction
22
+ - "@id": http://example.org/library/the-republic#introduction
23
+ "@type": Chapter
24
+ description: An introductory chapter on The Republic.
25
+ title: The Introduction
@@ -0,0 +1,12 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ Book: http://example.org/vocab#Book
5
+ Chapter: http://example.org/vocab#Chapter
6
+ contains:
7
+ "@id": http://example.org/vocab#contains
8
+ "@type": "@id"
9
+ creator: http://purl.org/dc/terms/creator
10
+ description: http://purl.org/dc/terms/description
11
+ Library: http://example.org/vocab#Library
12
+ title: http://purl.org/dc/terms/title
@@ -0,0 +1,23 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://example.com/library
4
+ "@type":
5
+ - http://example.org/vocab#Library
6
+ http://example.org/vocab#contains:
7
+ - "@id": http://example.org/library/the-republic
8
+ - "@id": http://example.org/library/the-republic
9
+ "@type":
10
+ - http://example.org/vocab#Book
11
+ http://purl.org/dc/terms/creator:
12
+ - "@value": Plato
13
+ http://purl.org/dc/terms/title:
14
+ - "@value": The Republic
15
+ http://example.org/vocab#contains:
16
+ - "@id": http://example.org/library/the-republic#introduction
17
+ - "@id": http://example.org/library/the-republic#introduction
18
+ "@type":
19
+ - http://example.org/vocab#Chapter
20
+ http://purl.org/dc/terms/description:
21
+ - "@value": An introductory chapter on The Republic.
22
+ http://purl.org/dc/terms/title:
23
+ - "@value": The Introduction
@@ -0,0 +1,15 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ Book: http://example.org/vocab#Book
5
+ Chapter: http://example.org/vocab#Chapter
6
+ contains: http://example.org/vocab#contains
7
+ creator: http://purl.org/dc/terms/creator
8
+ description: http://purl.org/dc/terms/description
9
+ Library: http://example.org/vocab#Library
10
+ title: http://purl.org/dc/terms/title
11
+ "@type": Library
12
+ contains:
13
+ "@type": Book
14
+ contains:
15
+ "@type": Chapter
@@ -0,0 +1,22 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ Book: http://example.org/vocab#Book
5
+ Chapter: http://example.org/vocab#Chapter
6
+ contains: http://example.org/vocab#contains
7
+ creator: http://purl.org/dc/terms/creator
8
+ description: http://purl.org/dc/terms/description
9
+ Library: http://example.org/vocab#Library
10
+ title: http://purl.org/dc/terms/title
11
+ "@id": http://example.com/library
12
+ "@type": Library
13
+ contains:
14
+ "@id": http://example.org/library/the-republic
15
+ "@type": Book
16
+ contains:
17
+ "@id": http://example.org/library/the-republic#introduction
18
+ "@type": Chapter
19
+ description: An introductory chapter on The Republic.
20
+ title: The Introduction
21
+ creator: Plato
22
+ title: The Republic
@@ -0,0 +1,31 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ id1: http://example.com/id1
5
+ t1: http://example.com/t1
6
+ t2: http://example.com/t2
7
+ term1: http://example.com/term
8
+ term2:
9
+ "@id": http://example.com/term
10
+ "@type": t2
11
+ term3:
12
+ "@id": http://example.com/term
13
+ "@language": en
14
+ term4:
15
+ "@id": http://example.com/term
16
+ "@container": "@list"
17
+ term5:
18
+ "@id": http://example.com/term
19
+ "@language":
20
+ "@language": de
21
+ "@id": http://example.com/id1
22
+ "@type": t1
23
+ term1: v1
24
+ term2: v2
25
+ term3: v3
26
+ term4:
27
+ - 1
28
+ - 2
29
+ term5:
30
+ - v5
31
+ - plain literal
@@ -0,0 +1,20 @@
1
+ %YAML 1.2
2
+ ---
3
+ "@context":
4
+ id1: http://example.com/id1
5
+ t1: http://example.com/t1
6
+ t2: http://example.com/t2
7
+ term1: http://example.com/term
8
+ term2:
9
+ "@id": http://example.com/term
10
+ "@type": t2
11
+ term3:
12
+ "@id": http://example.com/term
13
+ "@language": en
14
+ term4:
15
+ "@id": http://example.com/term
16
+ "@container": "@list"
17
+ term5:
18
+ "@id": http://example.com/term
19
+ "@language":
20
+ "@language": de
@@ -0,0 +1,17 @@
1
+ %YAML 1.2
2
+ ---
3
+ - "@id": http://example.com/id1
4
+ "@type":
5
+ - http://example.com/t1
6
+ http://example.com/term:
7
+ - "@value": v1
8
+ "@language": de
9
+ - "@value": v2
10
+ "@type": http://example.com/t2
11
+ - "@value": v3
12
+ "@language": en
13
+ - "@list":
14
+ - "@value": 1
15
+ - "@value": 2
16
+ - "@value": v5
17
+ - "@value": plain literal
data/spec/to_rdf_spec.rb CHANGED
@@ -131,14 +131,14 @@ describe YAML_LD::API do
131
131
  http://example.com/foo:
132
132
  - bar
133
133
  - baz
134
- }),
134
+ ),
135
135
  %q([ <http://example.com/foo> "bar"^^xsd:string, "baz"^^xsd:string ] .)
136
136
  ],
137
137
  "IRI" => [
138
138
  %q(
139
139
  http://example.com/foo:
140
140
  "@id": http://example.com/bar
141
- }),
141
+ ),
142
142
  %q([ <http://example.com/foo> <http://example.com/bar> ] .)
143
143
  ],
144
144
  "IRIs" => [
@@ -146,13 +146,13 @@ describe YAML_LD::API do
146
146
  http://example.com/foo:
147
147
  - "@id": http://example.com/bar
148
148
  - "@id": http://example.com/baz
149
- }),
149
+ ),
150
150
  %q([ <http://example.com/foo> <http://example.com/bar>, <http://example.com/baz> ] .)
151
151
  ],
152
- }.each do |title, (js, ttl)|
152
+ }.each do |title, (yaml, ttl)|
153
153
  it title do
154
154
  ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
155
- expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
155
+ expect(parse(yaml)).to be_equivalent_graph(ttl, logger: logger, inputDocument: yaml)
156
156
  end
157
157
  end
158
158
  end
@@ -212,10 +212,10 @@ describe YAML_LD::API do
212
212
  <http://greggkellogg.net/foaf#me> <http://purl.org/dc/terms/created> "1957-02-27"^^<http://www.w3.org/2001/XMLSchema#date> .
213
213
  )
214
214
  ],
215
- }.each do |title, (js, ttl)|
215
+ }.each do |title, (yaml, ttl)|
216
216
  it title do
217
217
  ttl = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . #{ttl}"
218
- expect(parse(js)).to be_equivalent_graph(ttl, logger: logger, inputDocument: js)
218
+ expect(parse(yaml)).to be_equivalent_graph(ttl, logger: logger, inputDocument: yaml)
219
219
  end
220
220
  end
221
221
 
@@ -540,7 +540,9 @@ describe YAML_LD::API do
540
540
  def run_to_rdf(params)
541
541
  input, output = params[:input], params[:output]
542
542
  graph = params[:graph] || RDF::Graph.new
543
- input = StringIO.new(input) if input.is_a?(String)
543
+ input = StringIO.new(input).tap do |d|
544
+ d.define_singleton_method(:content_type) {'application/ld+yaml'}
545
+ end if input.is_a?(String)
544
546
  pending params.fetch(:pending, "test implementation") unless input
545
547
  if params[:exception]
546
548
  expect {YAML_LD::API.toRdf(input, **params)}.to raise_error(params[:exception])