rdf-n3 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.
- data/.yardopts +1 -0
- data/History.txt +9 -0
- data/README.rdoc +4 -2
- data/Rakefile +37 -2
- data/VERSION +1 -1
- data/example.rb +1 -1
- data/lib/rdf/n3.rb +12 -5
- data/lib/rdf/n3/format.rb +0 -1
- data/lib/rdf/n3/patches/array_hacks.rb +46 -124
- data/lib/rdf/n3/patches/graph_properties.rb +34 -0
- data/lib/rdf/n3/patches/literal_hacks.rb +23 -0
- data/lib/rdf/n3/patches/literal_normalization.rb +120 -0
- data/lib/rdf/n3/patches/qname_hacks.rb +57 -0
- data/lib/rdf/n3/patches/rdf_escape.rb +3 -3
- data/lib/rdf/n3/patches/seq.rb +34 -0
- data/lib/rdf/n3/patches/uri_hacks.rb +19 -0
- data/lib/rdf/n3/reader.rb +110 -68
- data/lib/rdf/n3/reader/n3_grammar.rb +3876 -0
- data/lib/rdf/n3/{vocabulary.rb → vocab.rb} +0 -0
- data/lib/rdf/n3/writer.rb +444 -0
- data/rdf-n3.gemspec +38 -15
- data/script/console +8 -0
- data/script/parse +49 -0
- data/spec/cwm_spec.rb +13 -5
- data/spec/format_spec.rb +21 -0
- data/spec/literal_spec.rb +382 -0
- data/spec/matchers.rb +101 -0
- data/spec/n3reader_spec.rb +253 -185
- data/spec/rdf_helper.rb +115 -89
- data/spec/spec_helper.rb +39 -0
- data/spec/swap_spec.rb +24 -10
- data/spec/swap_test/n3parser.yml +193 -0
- data/spec/swap_test/regression.yml +226 -0
- data/spec/turtle_spec.rb +23 -8
- data/spec/writer_spec.rb +250 -0
- metadata +80 -22
- data/spec/swap_helper.rb +0 -136
- data/spec/triple_spec.rb +0 -236
@@ -0,0 +1,226 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/object:RdfHelper::TestCase
|
3
|
+
about: http://www.w3.org/2000/10/swap/test/animal.rdf
|
4
|
+
description: Parse a small RDF file, generate N3
|
5
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/animal.rdf
|
6
|
+
name: t1001
|
7
|
+
rdf_type: CwmProofTest
|
8
|
+
- !ruby/object:RdfHelper::TestCase
|
9
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/xml_prefix.n3
|
10
|
+
description: "Do not redefine the xml: prefix"
|
11
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/xml_prefix.n3
|
12
|
+
name: t1002a
|
13
|
+
rdf_type: CwmTest
|
14
|
+
- !ruby/object:RdfHelper::TestCase
|
15
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/xmlbase3.rdf
|
16
|
+
description: Allow for relative xml:base
|
17
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/xmlbase3.rdf
|
18
|
+
name: t1002b
|
19
|
+
rdf_type: CwmProofTest
|
20
|
+
- !ruby/object:RdfHelper::TestCase
|
21
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/xml_prefix2.n3
|
22
|
+
description: "do not redefine xml: and xmlns: even if told told"
|
23
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/xml_prefix2.n3
|
24
|
+
name: t1002c
|
25
|
+
rdf_type: CwmProofTest
|
26
|
+
- !ruby/object:RdfHelper::TestCase
|
27
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/rdf_prefix.n3
|
28
|
+
description: "Allow for redefinition of rdf:"
|
29
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/rdf_prefix.n3
|
30
|
+
name: t1002d
|
31
|
+
rdf_type: CwmTest
|
32
|
+
- !ruby/object:RdfHelper::TestCase
|
33
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/xmllit.rdf
|
34
|
+
description: rdf:parseType="Literal"
|
35
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/xmllit.rdf
|
36
|
+
name: t1002e
|
37
|
+
rdf_type: CwmTest
|
38
|
+
- !ruby/object:RdfHelper::TestCase
|
39
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/in-xml.xml
|
40
|
+
description: Parse RDF embedded in foreign XML
|
41
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/in-xml.xml
|
42
|
+
name: t1003
|
43
|
+
rdf_type: CwmTest
|
44
|
+
- !ruby/object:RdfHelper::TestCase
|
45
|
+
about: http://www.w3.org/2000/10/swap/test/reluri-1.n3
|
46
|
+
description: test generation of relative URIs
|
47
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/reluri-1.n3
|
48
|
+
name: t1005
|
49
|
+
rdf_type: CwmTest
|
50
|
+
- !ruby/object:RdfHelper::TestCase
|
51
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/no-last-nl.n3
|
52
|
+
description: An N3 file with no final newline character
|
53
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/no-last-nl.n3
|
54
|
+
name: t1005a
|
55
|
+
rdf_type: CwmProofTest
|
56
|
+
- !ruby/object:RdfHelper::TestCase
|
57
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/dot-dash.n3
|
58
|
+
description: combinations of - and _ in identifiers
|
59
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/dot-dash.n3
|
60
|
+
name: t1005b
|
61
|
+
rdf_type: CwmProofTest
|
62
|
+
- !ruby/object:RdfHelper::TestCase
|
63
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/keywords1.n3
|
64
|
+
description: "@keywords in n3"
|
65
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/keywords1.n3
|
66
|
+
name: t1005c
|
67
|
+
rdf_type: CwmProofTest
|
68
|
+
- !ruby/object:RdfHelper::TestCase
|
69
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/keywords2.n3
|
70
|
+
description: using no keywords in n3
|
71
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/keywords2.n3
|
72
|
+
name: t1005d
|
73
|
+
rdf_type: CwmProofTest
|
74
|
+
- !ruby/object:RdfHelper::TestCase
|
75
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/djb1a.n3
|
76
|
+
description: djb noticed a:b was parsed as rdf:type token
|
77
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/djb1a.n3
|
78
|
+
name: t1005e
|
79
|
+
rdf_type: CwmProofTest
|
80
|
+
- !ruby/object:RdfHelper::TestCase
|
81
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/contexts.n3
|
82
|
+
description: Parse and generate simple contexts
|
83
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/contexts.n3
|
84
|
+
name: t1006
|
85
|
+
rdf_type: CwmProofTest
|
86
|
+
- !ruby/object:RdfHelper::TestCase
|
87
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/anon-prop.n3
|
88
|
+
description: Parse and regen anonymous property
|
89
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/anon-prop.n3
|
90
|
+
name: t1007
|
91
|
+
rdf_type: CwmProofTest
|
92
|
+
status: pending
|
93
|
+
- !ruby/object:RdfHelper::TestCase
|
94
|
+
about: http://www.w3.org/2000/10/swap/test/nodeID/ex1.rdf
|
95
|
+
description: Parse RDF/XML nodeID to N3
|
96
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/nodeID/ex1.rdf
|
97
|
+
name: t1007a
|
98
|
+
rdf_type: CwmProofTest
|
99
|
+
- !ruby/object:RdfHelper::TestCase
|
100
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/nodeID/ex1.rdf
|
101
|
+
description: Parse RDF/XML nodeID and regen RDF/XML
|
102
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/nodeID/ex1.rdf
|
103
|
+
name: t1007b
|
104
|
+
rdf_type: CwmTest
|
105
|
+
- !ruby/object:RdfHelper::TestCase
|
106
|
+
about: http://www.w3.org/2000/10/swap/test/nodeID/classes.n3
|
107
|
+
description: use nodeID's with classes
|
108
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/nodeID/classes.n3
|
109
|
+
name: t1007c
|
110
|
+
rdf_type: CwmTest
|
111
|
+
- !ruby/object:RdfHelper::TestCase
|
112
|
+
about: http://www.w3.org/2000/10/swap/test/anonymous_loop.n3
|
113
|
+
description: A loop of anonymous nodes wasn't being printed at all
|
114
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/anonymous_loop.n3
|
115
|
+
name: t1007d
|
116
|
+
rdf_type: CwmProofTest
|
117
|
+
- !ruby/object:RdfHelper::TestCase
|
118
|
+
about: http://www.w3.org/2000/10/swap/test/daml-pref.n3
|
119
|
+
description: Convert some RDF/XML into RDF/N3
|
120
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/daml-pref.n3
|
121
|
+
name: t1008
|
122
|
+
rdf_type: CwmProofTest
|
123
|
+
- !ruby/object:RdfHelper::TestCase
|
124
|
+
about: http://www.w3.org/2000/10/swap/test/syntax/colon-in-uri.rdf
|
125
|
+
description: When rdf/xml localnames are not valid qNames
|
126
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/colon-in-uri.rdf
|
127
|
+
name: t1008a
|
128
|
+
rdf_type: CwmProofTest
|
129
|
+
- !ruby/object:RdfHelper::TestCase
|
130
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/strquot.n3
|
131
|
+
description: N3 string quoting with escaping
|
132
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/strquot.n3
|
133
|
+
name: t1009
|
134
|
+
rdf_type: CwmTest
|
135
|
+
- !ruby/object:RdfHelper::TestCase
|
136
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/strquot.n3
|
137
|
+
description: N3 string quoting with utf-8 literals
|
138
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/strquot.n3
|
139
|
+
name: t1009aa
|
140
|
+
rdf_type: CwmProofTest
|
141
|
+
- !ruby/object:RdfHelper::TestCase
|
142
|
+
about: http://www.w3.org/2000/10/swap/test/i18n/n3string.n3
|
143
|
+
description: log:n3string genertating utf-8 literals was double encoding
|
144
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/i18n/n3string.n3
|
145
|
+
name: t1009ab
|
146
|
+
rdf_type: CwmProofTest
|
147
|
+
status: pending
|
148
|
+
- !ruby/object:RdfHelper::TestCase
|
149
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/non-ascii-pred.rdf
|
150
|
+
description: XML to XML with utf-8 non-ascii characters
|
151
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/non-ascii-pred.rdf
|
152
|
+
name: t1009b
|
153
|
+
rdf_type: CwmProofTest
|
154
|
+
- !ruby/object:RdfHelper::TestCase
|
155
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/path1.n3
|
156
|
+
description: Path syntax, simple
|
157
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/path1.n3
|
158
|
+
name: t1010
|
159
|
+
rdf_type: CwmProofTest
|
160
|
+
- !ruby/object:RdfHelper::TestCase
|
161
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/path2.n3
|
162
|
+
description: Path syntax, more
|
163
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/path2.n3
|
164
|
+
name: t1011
|
165
|
+
rdf_type: CwmProofTest
|
166
|
+
status: pending
|
167
|
+
- !ruby/object:RdfHelper::TestCase
|
168
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/numbers.n3
|
169
|
+
description: Number syntax
|
170
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/numbers.n3
|
171
|
+
name: t10115
|
172
|
+
rdf_type: CwmProofTest
|
173
|
+
- !ruby/object:RdfHelper::TestCase
|
174
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/lstring.n3
|
175
|
+
description: N3 string nested triple quoting
|
176
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/syntax/lstring.n3
|
177
|
+
name: t1014
|
178
|
+
rdf_type: CwmProofTest
|
179
|
+
- !ruby/object:RdfHelper::TestCase
|
180
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/lists.n3
|
181
|
+
description: parsing and generation of N3 list syntax
|
182
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/lists.n3
|
183
|
+
name: t1017
|
184
|
+
rdf_type: CwmProofTest
|
185
|
+
- !ruby/object:RdfHelper::TestCase
|
186
|
+
about: http://www.w3.org/2000/10/swap/test/lists-simple.n3
|
187
|
+
description: conversion of subset of N3 list syntax to RDF
|
188
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/lists-simple.n3
|
189
|
+
name: t1018
|
190
|
+
rdf_type: CwmTest
|
191
|
+
- !ruby/object:RdfHelper::TestCase
|
192
|
+
about: http://www.w3.org/2000/10/swap/test/list/itemType.rdf
|
193
|
+
description: make sure typeNodes in RDF/XML Collections are parsed
|
194
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/list/itemType.rdf
|
195
|
+
name: t1018a1
|
196
|
+
rdf_type: CwmProofTest
|
197
|
+
- !ruby/object:RdfHelper::TestCase
|
198
|
+
about: http://www.w3.org/2000/10/swap/test/norm/fix.rdf
|
199
|
+
description: Avoiding default namespace on attrs
|
200
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/norm/fix.rdf
|
201
|
+
name: t1019
|
202
|
+
rdf_type: CwmProofTest
|
203
|
+
- !ruby/object:RdfHelper::TestCase
|
204
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/norm/fix.rdf
|
205
|
+
description: Avoiding default namespace on attrs
|
206
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/norm/fix.rdf
|
207
|
+
name: t1020
|
208
|
+
rdf_type: CwmTest
|
209
|
+
- !ruby/object:RdfHelper::TestCase
|
210
|
+
about: /Users/gregg/Projects/rdf-n3/spec/swap_test/norm/fix.rdf
|
211
|
+
description: Avoiding default namespace on attrs
|
212
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/norm/fix.rdf
|
213
|
+
name: t1021
|
214
|
+
rdf_type: CwmTest
|
215
|
+
- !ruby/object:RdfHelper::TestCase
|
216
|
+
about: http://www.w3.org/2000/10/swap/test/owl-ex.rdf
|
217
|
+
description: Early DAML (now OWL) example in XML/RDF
|
218
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/owl-ex.rdf
|
219
|
+
name: t1022
|
220
|
+
rdf_type: CwmProofTest
|
221
|
+
- !ruby/object:RdfHelper::TestCase
|
222
|
+
about: http://www.w3.org/2000/10/swap/test/xml-syntax/basic-serialization.n3
|
223
|
+
description: extremely basic RDF serialization test
|
224
|
+
inputDocument: /Users/gregg/Projects/rdf-n3/spec/swap_test/xml-syntax/basic-serialization.n3
|
225
|
+
name: t1063
|
226
|
+
rdf_type: CwmTest
|
data/spec/turtle_spec.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
include RdfContext
|
3
2
|
|
4
|
-
describe
|
3
|
+
describe RDF::N3::Reader do
|
5
4
|
# W3C Turtle Test suite from http://www.w3.org/2000/10/swap/test/regression.n3
|
6
5
|
describe "w3c turtle tests" do
|
7
6
|
require 'rdf_helper'
|
8
7
|
|
9
8
|
def self.positive_tests
|
10
|
-
RdfHelper::TestCase.test_cases(TURTLE_TEST, TURTLE_DIR)
|
9
|
+
RdfHelper::TestCase.test_cases(TURTLE_TEST, TURTLE_DIR)
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.negative_tests
|
14
|
-
RdfHelper::TestCase.test_cases(TURTLE_BAD_TEST, TURTLE_DIR)
|
13
|
+
RdfHelper::TestCase.test_cases(TURTLE_BAD_TEST, TURTLE_DIR)
|
15
14
|
end
|
16
15
|
|
17
16
|
describe "positive parser tests" do
|
@@ -22,6 +21,7 @@ describe "N3 parser" do
|
|
22
21
|
# modified test-21&22 results exponent to be E not e
|
23
22
|
# modified test-28 2.30 => 2.3 representation
|
24
23
|
specify "#{t.name}: " + (t.description || "#{t.inputDocument} against #{t.outputDocument}") do
|
24
|
+
#puts t.inspect
|
25
25
|
# Skip tests for very long files, too long
|
26
26
|
if %w(test-14 test-15 test-16 rdfq-results).include?(t.name)
|
27
27
|
pending("Skip very long input file")
|
@@ -32,8 +32,16 @@ describe "N3 parser" do
|
|
32
32
|
else
|
33
33
|
begin
|
34
34
|
t.run_test do |rdf_string, parser|
|
35
|
-
|
36
|
-
|
35
|
+
t.debug = []
|
36
|
+
g = RDF::Graph.new
|
37
|
+
RDF::Reader.for(t.inputDocument).new(rdf_string,
|
38
|
+
:base_uri => t.about,
|
39
|
+
:strict => true,
|
40
|
+
:debug => t.debug).each do |statement|
|
41
|
+
g << statement
|
42
|
+
end
|
43
|
+
#t.compare = :array if g.bnodes.empty?
|
44
|
+
g
|
37
45
|
end
|
38
46
|
#rescue #Spec::Expectations::ExpectationNotMetError => e
|
39
47
|
# pending() { raise }
|
@@ -50,8 +58,15 @@ describe "N3 parser" do
|
|
50
58
|
begin
|
51
59
|
t.run_test do |rdf_string, parser|
|
52
60
|
lambda do
|
53
|
-
|
54
|
-
|
61
|
+
t.debug = []
|
62
|
+
g = RDF::Graph.new
|
63
|
+
RDF::Reader.for(t.inputDocument).new(rdf_string,
|
64
|
+
:base_uri => t.about,
|
65
|
+
:strict => true,
|
66
|
+
:debug => t.debug).each do |statement|
|
67
|
+
g << statement
|
68
|
+
end
|
69
|
+
end.should raise_error(RDF::ReaderError)
|
55
70
|
end
|
56
71
|
rescue #Spec::Expectations::ExpectationNotMetError => e
|
57
72
|
pending() { raise }
|
data/spec/writer_spec.rb
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RDF::N3::Writer do
|
4
|
+
describe "simple tests" do
|
5
|
+
it "should use full URIs without base" do
|
6
|
+
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
7
|
+
serialize(input, nil, [%r(^<http://a/b> <http://a/c> <http://a/d> \.$)])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should use relative URIs with base" do
|
11
|
+
input = %(<http://a/b> <http://a/c> <http://a/d> .)
|
12
|
+
serialize(input, "http://a/",
|
13
|
+
[ %r(^@base <http://a/> \.$),
|
14
|
+
%r(^<b> <c> <d> \.$)]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use qname URIs with prefix" do
|
19
|
+
input = %(<http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
|
20
|
+
serialize(input, nil,
|
21
|
+
[%r(^@prefix foaf: <http://xmlns.com/foaf/0.1/> \.$),
|
22
|
+
%r(^foaf:b foaf:c foaf:d \.$)]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should use qname URIs with empty prefix" do
|
27
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . <http://xmlns.com/foaf/0.1/b> <http://xmlns.com/foaf/0.1/c> <http://xmlns.com/foaf/0.1/d> .)
|
28
|
+
serialize(input, nil,
|
29
|
+
[%r(^@prefix : <http://xmlns.com/foaf/0.1/> \.$),
|
30
|
+
%r(^:b :c :d \.$)],
|
31
|
+
:default_namespace => RDF::FOAF
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should order properties" do
|
36
|
+
input = %(
|
37
|
+
@prefix : <http://xmlns.com/foaf/0.1/> .
|
38
|
+
@prefix dc: <http://purl.org/dc/elements/1.1/> .
|
39
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
40
|
+
:b :c :d .
|
41
|
+
:b dc:title "title" .
|
42
|
+
:b a :class .
|
43
|
+
:b rdfs:label "label" .
|
44
|
+
)
|
45
|
+
serialize(input, nil,
|
46
|
+
[%r(^\s+a :class;$),
|
47
|
+
%r(^\s+rdfs:label "label"),
|
48
|
+
%r(^:b dc11:title \"title\"),
|
49
|
+
%r(^\s+:c :d)],
|
50
|
+
:default_namespace => RDF::FOAF
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate object list" do
|
55
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :b :c :d, :e .)
|
56
|
+
serialize(input, nil,
|
57
|
+
[%r(^@prefix : <http://xmlns.com/foaf/0.1/> \.$),
|
58
|
+
%r(^:b :c :d,$),
|
59
|
+
%r(^\s+:e \.$)],
|
60
|
+
:default_namespace => RDF::FOAF
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should generate property list" do
|
65
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :b :c :d; :e :f .)
|
66
|
+
serialize(input, nil,
|
67
|
+
[%r(^@prefix : <http://xmlns.com/foaf/0.1/> \.$),
|
68
|
+
%r(^:b :c :d;$),
|
69
|
+
%r(^\s+:e :f \.$)],
|
70
|
+
:default_namespace => RDF::FOAF
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "anons" do
|
76
|
+
it "should generate bare anon" do
|
77
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . [:a :b] .)
|
78
|
+
serialize(input, nil,
|
79
|
+
[%r(^\s*\[ :a :b\] \.$)],
|
80
|
+
:default_namespace => RDF::FOAF
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should generate anon as subject" do
|
85
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . [:a :b] :c :d .)
|
86
|
+
serialize(input, nil,
|
87
|
+
[%r(^\s*\[ :a :b;$),
|
88
|
+
%r(^\s+:c :d\] \.$)],
|
89
|
+
:default_namespace => RDF::FOAF
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should generate anon as object" do
|
94
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :a :b [:c :d] .)
|
95
|
+
serialize(input, nil,
|
96
|
+
[%r(^\s*\:a :b \[ :c :d\] \.$)],
|
97
|
+
:default_namespace => RDF::FOAF
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "lists" do
|
103
|
+
it "should generate bare list" do
|
104
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . (:a :b) .)
|
105
|
+
serialize(input, nil,
|
106
|
+
[%r(^\(:a :b\) \.$)],
|
107
|
+
:default_namespace => RDF::FOAF
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should generate literal list" do
|
112
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :a :b ( "apple" "banana" ) .)
|
113
|
+
serialize(input, nil,
|
114
|
+
[%r(^:a :b \("apple" "banana"\) \.$)],
|
115
|
+
:default_namespace => RDF::FOAF
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should generate empty list" do
|
120
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :a :b () .)
|
121
|
+
serialize(input, nil,
|
122
|
+
[%r(^:a :b \(\) \.$)],
|
123
|
+
:default_namespace => RDF::FOAF
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should generate empty list(2)" do
|
128
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :emptyList = () .)
|
129
|
+
serialize(input, nil,
|
130
|
+
[%r(^:emptyList (<.*sameAs>|owl:sameAs) \(\) \.$)],
|
131
|
+
:default_namespace => RDF::FOAF
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should generate empty list as subject" do
|
136
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . () :a :b .)
|
137
|
+
serialize(input, nil,
|
138
|
+
[%r(^\(\) :a :b \.$)],
|
139
|
+
:default_namespace => RDF::FOAF
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should generate list as subject" do
|
144
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . (:a) :b :c .)
|
145
|
+
serialize(input, nil,
|
146
|
+
[%r(^\(:a\) :b :c \.$)],
|
147
|
+
:default_namespace => RDF::FOAF
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should generate list of empties" do
|
152
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :listOf2Empties = (() ()) .)
|
153
|
+
serialize(input, nil,
|
154
|
+
[%r(^:listOf2Empties (<.*sameAs>|owl:sameAs) \(\(\) \(\)\) \.$)],
|
155
|
+
:default_namespace => RDF::FOAF
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should generate list anon" do
|
160
|
+
input = %(@prefix : <http://xmlns.com/foaf/0.1/> . :twoAnons = ([a :mother] [a :father]) .)
|
161
|
+
serialize(input, nil,
|
162
|
+
[%r(^:twoAnons (<.*sameAs>|owl:sameAs) \(\[\s*a :mother\] \[\s*a :father\]\) \.$)],
|
163
|
+
:default_namespace => RDF::FOAF
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should generate owl:unionOf list" do
|
168
|
+
input = %(
|
169
|
+
@prefix : <http://xmlns.com/foaf/0.1/> .
|
170
|
+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
171
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
172
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
173
|
+
:a rdfs:domain [
|
174
|
+
a owl:Class;
|
175
|
+
owl:unionOf [
|
176
|
+
a owl:Class;
|
177
|
+
rdf:first :b;
|
178
|
+
rdf:rest [
|
179
|
+
a owl:Class;
|
180
|
+
rdf:first :c;
|
181
|
+
rdf:rest rdf:nil
|
182
|
+
]
|
183
|
+
]
|
184
|
+
] .
|
185
|
+
)
|
186
|
+
serialize(input, nil,
|
187
|
+
[%r(:a rdfs:domain \[\s*a owl:Class;\s+owl:unionOf\s+\(:b\s+:c\)\]\s*\.$)m],
|
188
|
+
:default_namespace => RDF::FOAF
|
189
|
+
)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# W3C Turtle Test suite from http://www.w3.org/2000/10/swap/test/regression.n3
|
194
|
+
describe "w3c turtle tests" do
|
195
|
+
require 'rdf_helper'
|
196
|
+
|
197
|
+
def self.positive_tests
|
198
|
+
RdfHelper::TestCase.test_cases(TURTLE_TEST, TURTLE_DIR)
|
199
|
+
end
|
200
|
+
|
201
|
+
positive_tests.each do |t|
|
202
|
+
#puts t.inspect
|
203
|
+
#next unless t.name == "test-04"
|
204
|
+
|
205
|
+
specify "#{t.name}: " + (t.description || "#{t.inputDocument}") do
|
206
|
+
# Skip tests for very long files, too long
|
207
|
+
if %w(test-14 test-15 test-16 rdfq-results).include?(t.name)
|
208
|
+
pending("Skip very long input file")
|
209
|
+
elsif !defined?(::Encoding) && %w(test-18).include?(t.name)
|
210
|
+
pending("Not supported in Ruby 1.8")
|
211
|
+
elsif %w(test-29).include?(t.name)
|
212
|
+
pending("Silly test")
|
213
|
+
else
|
214
|
+
begin
|
215
|
+
t.run_test do |rdf_string|
|
216
|
+
t.compare = :none
|
217
|
+
serialize(rdf_string, t.about.to_s)
|
218
|
+
end
|
219
|
+
#rescue #Spec::Expectations::ExpectationNotMetError => e
|
220
|
+
# pending() { raise }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def parse(input, options = {})
|
228
|
+
graph = RDF::Graph.new
|
229
|
+
RDF::N3::Reader.new(input, options).each do |statement|
|
230
|
+
graph << statement
|
231
|
+
end
|
232
|
+
graph
|
233
|
+
end
|
234
|
+
|
235
|
+
# Serialize ntstr to a string and compare against regexps
|
236
|
+
def serialize(ntstr, base = nil, regexps = [], options = {})
|
237
|
+
g = parse(ntstr, :base_uri => base)
|
238
|
+
@debug = []
|
239
|
+
result = RDF::N3::Writer.buffer(options.merge(:debug => @debug, :base_uri => base)) do |writer|
|
240
|
+
writer << g
|
241
|
+
end
|
242
|
+
puts result if $verbose
|
243
|
+
|
244
|
+
regexps.each do |re|
|
245
|
+
result.should match_re(re, :about => base, :trace => @debug, :inputDocument => ntstr)
|
246
|
+
end
|
247
|
+
|
248
|
+
result
|
249
|
+
end
|
250
|
+
end
|