rdf-n3 0.2.3.2 → 0.3.0

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 (44) hide show
  1. data/.gitignore +1 -0
  2. data/.yardopts +4 -3
  3. data/{History.txt → History.md} +30 -6
  4. data/{README.rdoc → README.md} +56 -19
  5. data/Rakefile +15 -29
  6. data/VERSION +1 -1
  7. data/example-files/sp2b.n3 +50177 -0
  8. data/lib/rdf/n3.rb +2 -2
  9. data/lib/rdf/n3/reader.rb +560 -367
  10. data/lib/rdf/n3/reader/meta.rb +640 -0
  11. data/lib/rdf/n3/reader/n3-selectors.n3 +0 -0
  12. data/lib/rdf/n3/reader/parser.rb +229 -0
  13. data/lib/rdf/n3/vocab.rb +1 -0
  14. data/lib/rdf/n3/writer.rb +324 -265
  15. data/rdf-n3.gemspec +24 -26
  16. data/script/build_meta +242 -0
  17. data/script/parse +62 -13
  18. data/script/tc +4 -4
  19. data/spec/cwm_spec.rb +11 -3
  20. data/spec/n3reader_spec.rb +233 -63
  21. data/spec/rdf_helper.rb +15 -15
  22. data/spec/spec_helper.rb +10 -4
  23. data/spec/swap_spec.rb +11 -35
  24. data/spec/swap_test/n3parser.tests +14 -14
  25. data/spec/swap_test/n3parser.yml +0 -19
  26. data/spec/swap_test/nodeID/classes.ref.rdf +1 -1
  27. data/spec/swap_test/ref/contexts-1.n3 +12 -0
  28. data/spec/swap_test/ref/prefix2.rdf +33 -0
  29. data/spec/swap_test/ref/strquot.n3 +0 -1
  30. data/spec/swap_test/ref/xml-syntax-basic-serialization.rdf +1 -1
  31. data/spec/swap_test/regression.n3 +5 -5
  32. data/spec/swap_test/regression.yml +53 -23
  33. data/spec/turtle/manifest-bad.yml +91 -0
  34. data/spec/turtle/manifest.yml +187 -0
  35. data/spec/turtle_spec.rb +12 -20
  36. data/spec/writer_spec.rb +39 -37
  37. metadata +43 -48
  38. data/lib/rdf/n3/patches/qname_hacks.rb +0 -57
  39. data/lib/rdf/n3/patches/seq.rb +0 -34
  40. data/lib/rdf/n3/reader/n3_grammar.rb +0 -3764
  41. data/lib/rdf/n3/reader/n3_grammar.treetop +0 -227
  42. data/lib/rdf/n3/reader/n3_grammar_18.rb +0 -3764
  43. data/lib/rdf/n3/reader/n3_grammar_18.treetop +0 -227
  44. data/spec/literal_spec.rb +0 -245
@@ -1,227 +0,0 @@
1
- #encoding: utf-8
2
- grammar N3Grammer
3
- # Entry point to grammar
4
- rule document
5
- statements
6
- end
7
-
8
- rule barename
9
- barename_start barename_tail*
10
- end
11
-
12
- rule barename_start
13
- [A-Z_a-z\p{Alpha}]
14
- end
15
-
16
- rule barename_tail
17
- barename_start / [-0-9\\]
18
- end
19
-
20
- rule hexdigit
21
- [0-9a-fA-F]
22
- end
23
-
24
- rule integer
25
- [+-]? [0-9]+
26
- end
27
-
28
- rule barename_csl
29
- space+ barename barename_csl_tail
30
- / ""
31
- end
32
-
33
- rule barename_csl_tail
34
- space* "," space* barename space* barename_csl_tail
35
- / ""
36
- end
37
-
38
- rule boolean
39
- "@"* ("true" / "false")
40
- end
41
-
42
- rule comment
43
- '#' (![\n\r] .)*
44
- end
45
-
46
- rule declaration
47
- "@"? 'keywords' barename_csl {
48
- def declaration; true; end
49
- def keywords; true;end
50
- }
51
- / "@"? 'base' space+ explicituri:explicituri {
52
- def declaration; true; end
53
- def base; true; end
54
- }
55
- / "@"? 'prefix' space+ nprefix:nprefix? ':' space* explicituri:explicituri {
56
- def declaration; true; end
57
- }
58
- end
59
-
60
- rule decimal
61
- integer '.' [0-9]+
62
- end
63
-
64
- rule double
65
- decimal [eE] integer
66
- end
67
-
68
- rule existential
69
- "@"? "forSome" space+ symbol_csl
70
- end
71
-
72
- rule explicituri
73
- "<" uri:URI_Reference ">"
74
- end
75
-
76
- rule expression
77
- pathitem space* '.' expression
78
- / pathitem space* "!" space* expression
79
- / pathitem space* "^" space* expression { def reverse; true; end }
80
- / pathitem
81
- end
82
-
83
- rule language
84
- [a-zA-Z]+ ( "-" [a-zA-Z0-9]+ )*
85
- end
86
-
87
- rule literal
88
- (string_single / string_multi) ("^^" symbol / "@" language )?
89
- end
90
-
91
- rule localname
92
- barename
93
- end
94
-
95
- rule nprefix
96
- barename
97
- end
98
-
99
- rule numericliteral
100
- double { def numericliteral; "double"; end}
101
- / decimal { def numericliteral; "decimal"; end}
102
- / integer { def numericliteral; "integer"; end}
103
- end
104
-
105
- rule object
106
- expression
107
- end
108
-
109
- rule object_list
110
- object space* "," space* object_list
111
- / object
112
- end
113
-
114
- rule pathitem
115
- boolean { def boolean; true; end }
116
- / literal { def literal; true; end }
117
- / numericliteral
118
- #/ quickvariable
119
- / symbol
120
- / "[" space* "]" { def anonnode; true; end }
121
- / "[" space* property_list space* "]" { def anonnode; true; end }
122
- / "{" space* statements space* "}" { def anonnode; true; end }
123
- / "(" space* path_list space* ")" { def anonnode; true; end }
124
- end
125
-
126
- rule path_list
127
- expression space* path_list
128
- / ""
129
- end
130
-
131
- rule prop
132
- expression
133
- end
134
-
135
- rule property_list
136
- verb space* object_list space* ";"+ space* property_list
137
- / verb space* object_list space* ";"*
138
- / verb space* ";"* {def object_missing; true; end}
139
- / ""
140
- end
141
-
142
- rule qname
143
- nprefix ":" localname
144
- / nprefix ':' { def text_value; ""; end }
145
- / ':' localname*
146
- / localname { def barename; true; end }
147
- end
148
-
149
- rule simpleStatement
150
- subject space+ property_list
151
- / subject # For [] and a.b
152
- end
153
-
154
- rule space
155
- [ \t\n\r]+ / comment
156
- end
157
-
158
- rule statement
159
- declaration
160
- / existential
161
- / simpleStatement
162
- / universal
163
- end
164
-
165
- rule statements
166
- (space / statement space* ('.' space*)? )*
167
- end
168
-
169
- # " constant-value-with-escaping "
170
- rule string_single
171
- '""' !["] / '"' string_single_char+ '"'
172
- end
173
-
174
- rule string_single_char
175
- !["\n\r] (
176
- ("\\"
177
- [\\\"bfnrt]
178
- / ( "u" hexdigit hexdigit hexdigit hexdigit )
179
- / ( "U" "00" hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit)
180
- )
181
- / .)
182
- end
183
-
184
- # """ constant value with escaping including single or double occurrences of quotes and/or newlines """
185
- rule string_multi
186
- '"""' string_multi_single_char* '"""'
187
- end
188
-
189
- rule string_multi_single_char
190
- "\\\""
191
- / !('"""') .
192
- end
193
-
194
- rule subject
195
- expression
196
- end
197
-
198
- rule symbol
199
- qname / explicituri
200
- end
201
-
202
- rule symbol_csl
203
- symbol space* "," space* symbol_csl
204
- / symbol
205
- end
206
-
207
- rule verb
208
- "@"? "has" space+ prop # has xxx
209
- / "@"? "is" space+ prop space+ "@"? "of" { # is xxx of
210
- def invert; true; end
211
- }
212
- / "@"? "a" !":" # has rdf:type
213
- / "=>" # has log:implies
214
- / "<=" { def invert; true; end } # is log:implies of
215
- / "=" # has owl:sameAs
216
- / prop # has xxx of -- shorthand
217
- end
218
-
219
- rule universal
220
- "@"? "forAll" space+ symbol_csl
221
- end
222
-
223
- rule URI_Reference
224
- [^{}<>]*
225
- end
226
-
227
- end
@@ -1,245 +0,0 @@
1
- # coding: utf-8
2
- $:.unshift "."
3
- require File.join(File.dirname(__FILE__), 'spec_helper')
4
- require 'nokogiri'
5
-
6
- describe RDF::Literal do
7
- require 'nokogiri' rescue nil
8
-
9
- before :each do
10
- @new = Proc.new { |*args| RDF::Literal.new(*args) }
11
- end
12
-
13
- describe "XML Literal" do
14
- describe "with no namespace" do
15
- subject { @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral) }
16
- it "should return input" do subject.to_s.should == "foo <sup>bar</sup> baz!" end
17
-
18
- it "should be equal if they have the same contents" do
19
- should == @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral)
20
- end
21
- end
22
-
23
- describe "with a namespace" do
24
- subject {
25
- @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
26
- :namespaces => {:dc => RDF::DC.to_s})
27
- }
28
-
29
- it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
30
-
31
- describe "as string prefix" do
32
- subject {
33
- @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
34
- :namespaces => {"dc" => RDF::DC.to_s})
35
- }
36
-
37
- it "should add namespaces" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\">bar</dc:sup> baz!" end
38
- end
39
-
40
- describe "and language" do
41
- subject {
42
- @new.call("foo <dc:sup>bar</dc:sup> baz!", :datatype => RDF.XMLLiteral,
43
- :namespaces => {:dc => RDF::DC.to_s},
44
- :language => :fr)
45
- }
46
-
47
- it "should add namespaces and language" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"fr\">bar</dc:sup> baz!" end
48
- end
49
-
50
- describe "and node set" do
51
- subject {
52
- root = Nokogiri::XML.parse(%(<?xml version="1.0" encoding="UTF-8"?>
53
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
54
- <html xmlns="http://www.w3.org/1999/xhtml"
55
- xmlns:dc="http://purl.org/dc/terms/"
56
- xmlns:ex="http://example.org/rdf/"
57
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
58
- xmlns:svg="http://www.w3.org/2000/svg">
59
- <head profile="http://www.w3.org/1999/xhtml/vocab http://www.w3.org/2005/10/profile">
60
- <title>Test 0100</title>
61
- </head>
62
- <body>
63
- <div about="http://www.example.org">
64
- <h2 property="ex:example" datatype="rdf:XMLLiteral"><svg:svg/></h2>
65
- </div>
66
- </body>
67
- </html>
68
- ), nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML).root
69
- content = root.css("h2").children
70
- @new.call(content, :datatype => RDF.XMLLiteral,
71
- :namespaces => {
72
- :svg => "http://www.w3.org/2000/svg",
73
- :dc => "http://purl.org/dc/terms/",
74
- })
75
- }
76
- it "should add namespace" do subject.to_s.should == "<svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"></svg:svg>" end
77
- end
78
-
79
- describe "and language with an existing language embedded" do
80
- subject {
81
- @new.call("foo <dc:sup>bar</dc:sup><dc:sub xml:lang=\"en\">baz</dc:sub>",
82
- :datatype => RDF.XMLLiteral,
83
- :namespaces => {:dc => RDF::DC.to_s},
84
- :language => :fr)
85
- }
86
-
87
- it "should add namespaces and language" do subject.to_s.should == "foo <dc:sup xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"fr\">bar</dc:sup><dc:sub xmlns:dc=\"http://purl.org/dc/terms/\" xml:lang=\"en\">baz</dc:sub>" end
88
- end
89
- end
90
-
91
- describe "with a default namespace" do
92
- subject {
93
- @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
94
- :namespaces => {:__default__ => RDF::DC.to_s})
95
- }
96
-
97
- it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
98
- end
99
-
100
- describe "with a default namespace (as empty string)" do
101
- subject {
102
- @new.call("foo <sup>bar</sup> baz!", :datatype => RDF.XMLLiteral,
103
- :namespaces => {"" => RDF::DC.to_s})
104
- }
105
-
106
- it "should add namespace" do subject.to_s.should == "foo <sup xmlns=\"http://purl.org/dc/terms/\">bar</sup> baz!" end
107
- end
108
-
109
- context "rdfcore tests" do
110
- context "rdfms-xml-literal-namespaces" do
111
- it "should reproduce test001" do
112
- l = @new.call("
113
- <html:h1>
114
- <b>John</b>
115
- </html:h1>
116
- ",
117
- :datatype => RDF.XMLLiteral,
118
- :namespaces => {
119
- "" => "http://www.w3.org/1999/xhtml",
120
- "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
121
- "html" => "http://NoHTML.example.org",
122
- "my" => "http://my.example.org/",
123
- })
124
-
125
- pending do
126
- l.to_s.should == "\n <html:h1 xmlns:html=\"http://NoHTML.example.org\">\n <b xmlns=\"http://www.w3.org/1999/xhtml\">John</b>\n </html:h1>\n "
127
- end
128
- end
129
-
130
- it "should reproduce test002" do
131
- l = @new.call("
132
- Ramifications of
133
- <apply>
134
- <power/>
135
- <apply>
136
- <plus/>
137
- <ci>a</ci>
138
- <ci>b</ci>
139
- </apply>
140
- <cn>2</cn>
141
- </apply>
142
- to World Peace
143
- ",
144
- :datatype => RDF.XMLLiteral,
145
- :namespaces => {
146
- "" => "http://www.w3.org/TR/REC-mathml",
147
- })
148
-
149
- l.to_s.should == "\n Ramifications of\n <apply xmlns=\"http://www.w3.org/TR/REC-mathml\">\n <power></power>\n <apply>\n\t<plus></plus>\n\t<ci>a</ci>\n\t<ci>b</ci>\n </apply>\n <cn>2</cn>\n </apply>\n to World Peace\n "
150
- end
151
- end
152
-
153
- context "rdfms-xmllang" do
154
- it "should reproduce test001" do
155
- l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => nil)
156
-
157
- l.to_s.should == "chat"
158
- end
159
- it "should reproduce test002" do
160
- l = @new.call("chat", :datatype => RDF.XMLLiteral, :language => :fr)
161
-
162
- l.to_s.should == "chat"
163
- end
164
- end
165
-
166
- context "xml-canon" do
167
- it "should reproduce test001" do
168
- l = @new.call("<br />", :datatype => RDF.XMLLiteral)
169
-
170
- l.to_s.should == "<br></br>"
171
- end
172
- end
173
- end
174
-
175
- context "rdfa tests" do
176
- it "should reproduce test 0011: XMLLiteral" do
177
- l = @new.call("E = mc<sup>2</sup>: The Most Urgent Problem of Our Time",
178
- :datatype => RDF.XMLLiteral,
179
- :namespaces => {"" => "http://www.w3.org/1999/xhtml"})
180
-
181
- l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
182
- end
183
-
184
- it "should reproduce test 0092: Tests XMLLiteral content with explicit @datatype" do
185
- l = @new.call(%(E = mc<sup>2</sup>: The Most Urgent Problem of Our Time<),
186
- :datatype => RDF.XMLLiteral,
187
- :namespaces => {"" => "http://www.w3.org/1999/xhtml"})
188
-
189
- l.to_s.should == "E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time"
190
- end
191
-
192
- it "should reproduce test 0100: XMLLiteral with explicit namespace" do
193
- l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
194
- :datatype => RDF.XMLLiteral,
195
- :namespaces => {
196
- "" => "http://www.w3.org/1999/xhtml",
197
- "svg" => "http://www.w3.org/2000/svg",
198
- })
199
-
200
- pending do
201
- l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
202
- end
203
- end
204
-
205
- it "should reproduce 0101: XMLLiteral with explicit namespace and xml:lang" do
206
- l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
207
- :datatype => RDF.XMLLiteral, :language => :fr,
208
- :namespaces => {
209
- "" => "http://www.w3.org/1999/xhtml",
210
- "svg" => "http://www.w3.org/2000/svg",
211
- })
212
-
213
- pending do
214
- l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"fr\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
215
- end
216
- end
217
-
218
- it "should reproduce test 0102: XMLLiteral with explicit namespace and xml:lang; not overwriting existing langs" do
219
- l = @new.call(%(Du texte ici en <strong>gras</strong> et un rectangle en svg: <svg:svg xml:lang="hu"><svg:rect svg:width="200" svg:height="100"/></svg:svg>),
220
- :datatype => RDF.XMLLiteral, :language => :fr,
221
- :namespaces => {
222
- "" => "http://www.w3.org/1999/xhtml",
223
- "svg" => "http://www.w3.org/2000/svg",
224
- })
225
-
226
- pending do
227
- l.to_s.should == "Du texte ici en <strong xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">gras</strong> et un rectangle en svg: <svg:svg xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"hu\"><svg:rect svg:height=\"100\" svg:width=\"200\"></svg:rect></svg:svg>"
228
- end
229
- end
230
-
231
- it "should reproduce test 0103: XMLLiteral with explicit namespace; not overwriting local namespaces" do
232
- l = @new.call(%(Some text here in <strong>bold</strong> and an svg rectangle: <svg xmlns="http://www.w3.org/2000/svg"><rect width="200" height="100"/></svg>),
233
- :datatype => RDF.XMLLiteral,
234
- :namespaces => {
235
- "" => "http://www.w3.org/1999/xhtml",
236
- "svg" => "http://www.w3.org/2000/svg",
237
- })
238
-
239
- pending do
240
- l.to_s.should == "Some text here in <strong xmlns=\"http://www.w3.org/1999/xhtml\">bold</strong> and an svg rectangle: <svg xmlns=\"http://www.w3.org/2000/svg\"><rect height=\"100\" width=\"200\"></rect></svg>"
241
- end
242
- end
243
- end
244
- end if defined?(::Nokogiri)
245
- end