rdf-n3 0.3.1.1 → 0.3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/History.md +4 -0
- data/README.md +83 -87
- data/Rakefile +1 -1
- data/UNLICENSE +24 -0
- data/VERSION +1 -1
- data/example-files/arnau-registered-vocab.rb +21 -0
- data/lib/rdf/n3/format.rb +26 -26
- data/lib/rdf/n3/reader.rb +21 -9
- data/lib/rdf/n3/writer.rb +5 -11
- data/rdf-n3.gemspec +6 -3
- data/script/parse +33 -34
- data/spec/n3reader_spec.rb +1 -1
- data/spec/writer_spec.rb +10 -0
- metadata +6 -3
data/.yardopts
CHANGED
data/History.md
CHANGED
data/README.md
CHANGED
@@ -1,134 +1,130 @@
|
|
1
1
|
RDF::N3 reader/writer
|
2
2
|
=====================
|
3
|
-
Notation-3 and Turtle reader/writer for RDF.rb.
|
3
|
+
Notation-3 and Turtle reader/writer for [RDF.rb][RDF.rb] .
|
4
4
|
|
5
5
|
Description
|
6
6
|
-----------
|
7
|
-
RDF::N3 is an Notation-3 parser for Ruby using the RDF.rb
|
7
|
+
RDF::N3 is an Notation-3 parser for Ruby using the [RDF.rb][RDF.rb] library suite.
|
8
8
|
|
9
9
|
Reader inspired from TimBL predictiveParser and Python librdf implementation.
|
10
10
|
|
11
11
|
Features
|
12
12
|
--------
|
13
|
-
RDF::N3 parses Notation-3, Turtle and N-Triples into statements or triples. It also serializes to Turtle.
|
13
|
+
RDF::N3 parses [Notation-3][N3], [Turtle][Turtle] and [N-Triples][N-Triples] into statements or triples. It also serializes to Turtle.
|
14
14
|
|
15
|
-
|
16
|
-
* Also parses Turtle and N-Triples
|
17
|
-
* Turtle serializer
|
15
|
+
Install with `gem install rdf-n3`
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
Limitations
|
22
|
-
-----------
|
17
|
+
## Limitations
|
23
18
|
* Full support of Unicode input requires Ruby version 1.9 or greater.
|
24
19
|
* Support for Variables in Formulae dependent on underlying repository. Existential variables are quantified to RDF::Node instances, Universals to RDF::Query::Variable, with the URI of the variable target used as the variable name.
|
25
20
|
* No support for N3 Reification. If there were, it would be through a :reify option to the reader.
|
26
21
|
|
27
|
-
Usage
|
28
|
-
-----
|
22
|
+
## Usage
|
29
23
|
Instantiate a reader from a local file:
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
RDF::N3::Reader.open("etc/foaf.n3") do |reader|
|
26
|
+
reader.each_statement do |statement|
|
27
|
+
puts statement.inspect
|
28
|
+
end
|
34
29
|
end
|
35
|
-
end
|
36
30
|
|
37
|
-
Define
|
31
|
+
Define `@base` and `@prefix` definitions, and use for serialization using `:base_uri` an `:prefixes` options
|
38
32
|
|
39
33
|
Write a graph to a file:
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
RDF::N3::Writer.open("etc/test.n3") do |writer|
|
36
|
+
writer << graph
|
37
|
+
end
|
44
38
|
|
45
|
-
Formulae
|
46
|
-
|
47
|
-
N3 Formulae are introduced with the { statmenent-list } syntax. A given formula is assigned an RDF::Node instance, which is also used as the context for RDF::Statement instances provided to RDF::N3::Reader#each_statement. For example, the following N3 generates the associated statements:
|
39
|
+
### Formulae
|
40
|
+
N3 Formulae are introduced with the { statement-list } syntax. A given formula is assigned an RDF::Node instance, which is also used as the context for RDF::Statement instances provided to RDF::N3::Reader#each_statement. For example, the following N3 generates the associated statements:
|
48
41
|
|
49
|
-
|
42
|
+
{ [ x:firstname "Ora" ] dc:wrote [ dc:title "Moby Dick" ] } a n3:falsehood .
|
50
43
|
|
51
44
|
results in
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
f = RDF::Node.new
|
47
|
+
s = RDF::Node.new
|
48
|
+
o = RDF::Node.new
|
49
|
+
RDF::Statement(f, rdf:type n3:falsehood)
|
50
|
+
RDF::Statement(s, x:firstname, "Ora", :context => f)
|
51
|
+
RDF::Statement(s, dc:wrote, o, :context => f)
|
52
|
+
RDF::Statement(o, dc:title, "Moby Dick", :context => f)
|
60
53
|
|
61
|
-
Variables
|
62
|
-
---------
|
54
|
+
### Variables
|
63
55
|
N3 Variables are introduced with @forAll, @forEach, or ?x. Variables reference URIs described in formulae, typically defined in the default vocabulary (e.g., ":x"). Existential variables are replaced with an allocated RDF::Node instance. Universal variables are replaced with a RDF::Query::Variable instance. For example, the following N3 generates the associated statements:
|
64
56
|
|
65
|
-
|
57
|
+
@forAll <#h>. @forSome <#g>. <#g> <#loves> <#h> .
|
66
58
|
|
67
59
|
results in:
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
h = RDF::Query::Variable.new(<#h>)
|
62
|
+
g = RDF::Node.new()
|
63
|
+
RDF::Statement.new(f, <#loves>, h)
|
72
64
|
|
73
|
-
Implementation Notes
|
74
|
-
--------------------
|
65
|
+
## Implementation Notes
|
75
66
|
The parser is driven through a rules table contained in lib/rdf/n3/reader/meta.rb. This includes
|
76
67
|
branch rules to indicate productions to be taken based on a current production. Terminals are denoted
|
77
68
|
through a set of regular expressions used to match each type of terminal.
|
78
69
|
|
79
|
-
The meta.rb file is generated from lib/rdf/n3/reader/n3-selectors.n3
|
70
|
+
The [meta.rb][file:lib/rdf/n3/reader/meta.rb] file is generated from lib/rdf/n3/reader/n3-selectors.n3
|
80
71
|
(taken from http://www.w3.org/2000/10/swap/grammar/n3-selectors.n3) which is the result of parsing
|
81
72
|
http://www.w3.org/2000/10/swap/grammar/n3.n3 (along with bnf-rules.n3) using cwm using the following command sequence:
|
82
73
|
|
83
74
|
cwm n3.n3 bnf-rules.n3 --think --purge --data > n3-selectors.n3
|
84
75
|
|
85
|
-
n3-selectors.n3 is itself used to generate meta.rb using script/build_meta.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
*
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
101
|
-
*
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
76
|
+
[n3-selectors.n3][file:lib/rdf/n3/reader/n3-selectors.rb] is itself used to generate meta.rb using script/build_meta.
|
77
|
+
|
78
|
+
## TODO
|
79
|
+
* Generate Formulae and solutions using BGP and SPARQL CONSTRUCT mechanisms
|
80
|
+
* Create equivalent to `--think` to iterate on solutions.
|
81
|
+
|
82
|
+
## Dependencies
|
83
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.1)
|
84
|
+
|
85
|
+
## Documentation
|
86
|
+
Full documentation available on [RubyForge](http://rdf.rubyforge.org/n3)
|
87
|
+
|
88
|
+
### Principle Classes
|
89
|
+
* {RDF::N3}
|
90
|
+
* {RDF::N3::Format}
|
91
|
+
* {RDF::N3::Reader}
|
92
|
+
* {RDF::N3::Writer}
|
93
|
+
|
94
|
+
### Additional vocabularies
|
95
|
+
* {RDF::LOG}
|
96
|
+
* {RDF::REI}
|
97
|
+
|
98
|
+
### Patches
|
99
|
+
* {Array}
|
100
|
+
* {RDF::Graph}
|
101
|
+
|
102
|
+
## Resources
|
103
|
+
* [RDF.rb][RDF.rb]
|
104
|
+
* [Distiller](http://distiller.kellogg-assoc)
|
105
|
+
* [Documentation](http://rdf.rubyforge.org/n3)
|
106
|
+
* [History](file:file.History.html)
|
107
|
+
* [Notation-3][N3]
|
108
|
+
* [N3 Primer](http://www.w3.org/2000/10/swap/Primer.html)
|
109
|
+
* [N3 Reification](http://www.w3.org/DesignIssues/Reify.html)
|
110
|
+
* [Turtle][Turtle]
|
111
|
+
* [W3C SWAP Test suite](http://www.w3.org/2000/10/swap/test/README.html)
|
112
|
+
* [W3C Turtle Test suite](http://www.w3.org/2001/sw/DataAccess/df1/tests/README.txt)
|
113
|
+
* [N-Triples][N-Triples]
|
114
|
+
|
115
|
+
## License
|
116
|
+
|
117
|
+
This is free and unencumbered public domain software. For more information,
|
118
|
+
see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
127
119
|
|
128
120
|
Feedback
|
129
121
|
--------
|
130
|
-
* gregg@kellogg-assoc.com
|
131
|
-
* rubygems.org/rdf-n3
|
132
|
-
* github.com/gkellogg/rdf-n3
|
133
|
-
*
|
134
|
-
|
122
|
+
* <gregg@kellogg-assoc.com>
|
123
|
+
* <http://rubygems.org/gem/rdf-n3>
|
124
|
+
* <http://github.com/gkellogg/rdf-n3>
|
125
|
+
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
126
|
+
|
127
|
+
[RDF.rb]: http://rdf.rubyforge.org/
|
128
|
+
[N3]: http://www.w3.org/DesignIssues/Notation3.html "Notation-3"
|
129
|
+
[Turtle]: http://www.w3.org/TeamSubmission/turtle/
|
130
|
+
[N-Triples]: http://www.w3.org/2001/sw/RDFCore/ntriples/
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ begin
|
|
19
19
|
gemspec.add_development_dependency('rdf-rdfxml', '>= 0.3.1')
|
20
20
|
gemspec.add_development_dependency('rdf-isomorphic', '>= 0.3.4')
|
21
21
|
gemspec.add_development_dependency('yard')
|
22
|
-
gemspec.extra_rdoc_files = %w(README.md History.md AUTHORS VERSION)
|
22
|
+
gemspec.extra_rdoc_files = %w(README.md History.md AUTHORS VERSION UNLICENSE)
|
23
23
|
end
|
24
24
|
Jeweler::GemcutterTasks.new
|
25
25
|
rescue LoadError
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.1.
|
1
|
+
0.3.1.2
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rdf/rdfxml'
|
4
|
+
require 'rdf/n3'
|
5
|
+
|
6
|
+
data = %q(
|
7
|
+
<?xml version="1.0" encoding="utf-8"?>
|
8
|
+
<rdf:RDF
|
9
|
+
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
10
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
11
|
+
xmlns:vx="http://bcn.cat/data/v8y/xvcard#">
|
12
|
+
|
13
|
+
<owl:Ontology rdf:about="http://bcn.cat/data/v8y/xvcard#">
|
14
|
+
</owl:Ontology>
|
15
|
+
|
16
|
+
</rdf:RDF>)
|
17
|
+
|
18
|
+
reader = RDF::RDFXML::Reader.new(data)
|
19
|
+
graph = RDF::Graph.new << reader
|
20
|
+
|
21
|
+
puts graph.dump(:n3, :prefixes => reader.prefixes)
|
data/lib/rdf/n3/format.rb
CHANGED
@@ -2,24 +2,24 @@ module RDF::N3
|
|
2
2
|
##
|
3
3
|
# RDFa format specification.
|
4
4
|
#
|
5
|
-
# @example Obtaining an
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
5
|
+
# @example Obtaining an Notation3 format class
|
6
|
+
# RDF::Format.for(:n3) #=> RDF::N3::Format
|
7
|
+
# RDF::Format.for("etc/foaf.ttl")
|
8
|
+
# RDF::Format.for("etc/foaf.n3")
|
9
|
+
# RDF::Format.for(:file_name => "etc/foaf.ttl")
|
10
|
+
# RDF::Format.for(:file_name => "etc/foaf.n3")
|
11
|
+
# RDF::Format.for(:file_extension => "ttl")
|
12
|
+
# RDF::Format.for(:file_extension => "n3")
|
13
|
+
# RDF::Format.for(:content_type => "text/turtle")
|
14
|
+
# RDF::Format.for(:content_type => "text/n3")
|
15
15
|
#
|
16
16
|
# @example Obtaining serialization format MIME types
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# RDF::Format.content_types #=> {"text/turtle" => [RDF::N3::Format]}
|
18
|
+
# RDF::Format.content_types #=> {"text/n3")" => [RDF::N3::Format]}
|
19
19
|
#
|
20
20
|
# @example Obtaining serialization format file extension mappings
|
21
|
-
#
|
22
|
-
#
|
21
|
+
# RDF::Format.file_extensions #=> {:ttl => "text/turtle"}
|
22
|
+
# RDF::Format.file_extensions #=> {:n3 => "text/n3"}
|
23
23
|
#
|
24
24
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
25
25
|
class Format < RDF::Format
|
@@ -39,10 +39,10 @@ module RDF::N3
|
|
39
39
|
#
|
40
40
|
# This allows the following:
|
41
41
|
#
|
42
|
-
# @example Obtaining an
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
42
|
+
# @example Obtaining an Notation3 format class
|
43
|
+
# RDF::Format.for(:ttl) #=> RDF::N3::Notation3
|
44
|
+
# RDF::Format.for(:ttl).reader #=> RDF::N3::Reader
|
45
|
+
# RDF::Format.for(:ttl).writer #=> RDF::N3::Writer
|
46
46
|
class Notation3 < RDF::Format
|
47
47
|
reader { RDF::N3::Reader }
|
48
48
|
writer { RDF::N3::Writer }
|
@@ -52,10 +52,10 @@ module RDF::N3
|
|
52
52
|
#
|
53
53
|
# This allows the following:
|
54
54
|
#
|
55
|
-
# @example Obtaining an
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
55
|
+
# @example Obtaining an TTL format class
|
56
|
+
# RDF::Format.for(:ttl) # RDF::N3::TTL
|
57
|
+
# RDF::Format.for(:ttl).reader # RDF::N3::Reader
|
58
|
+
# RDF::Format.for(:ttl).writer # RDF::N3::Writer
|
59
59
|
class TTL < RDF::Format
|
60
60
|
reader { RDF::N3::Reader }
|
61
61
|
writer { RDF::N3::Writer }
|
@@ -65,10 +65,10 @@ module RDF::N3
|
|
65
65
|
#
|
66
66
|
# This allows the following:
|
67
67
|
#
|
68
|
-
# @example Obtaining an
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
68
|
+
# @example Obtaining an Turtle format class
|
69
|
+
# RDF::Format.for(:turtle) # RDF::N3::Turtle
|
70
|
+
# RDF::Format.for(:turtle).reader # RDF::N3::Reader
|
71
|
+
# RDF::Format.for(:turtle).writer # RDF::N3::Writer
|
72
72
|
class Turtle < RDF::Format
|
73
73
|
reader { RDF::N3::Reader }
|
74
74
|
writer { RDF::N3::Writer }
|
data/lib/rdf/n3/reader.rb
CHANGED
@@ -62,9 +62,8 @@ module RDF::N3
|
|
62
62
|
@variables = {} # variable definitions along with defining formula
|
63
63
|
|
64
64
|
if options[:base_uri]
|
65
|
-
@uri
|
66
|
-
|
67
|
-
namespace(nil, uri("#{options[:base_uri]}#"))
|
65
|
+
add_debug("@uri", "#{base_uri.inspect}")
|
66
|
+
namespace(nil, uri("#{base_uri}#"))
|
68
67
|
end
|
69
68
|
add_debug("validate", "#{validate?.inspect}")
|
70
69
|
add_debug("canonicalize", "#{canonicalize?.inspect}")
|
@@ -83,6 +82,19 @@ module RDF::N3
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
85
|
+
##
|
86
|
+
# XXX Remove when added to RDF::Reader
|
87
|
+
# Returns the base URI determined by this reader.
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
|
91
|
+
#
|
92
|
+
# @return [Hash{Symbol => RDF::URI}]
|
93
|
+
# @since 0.3.0
|
94
|
+
def base_uri
|
95
|
+
@options[:base_uri]
|
96
|
+
end
|
97
|
+
|
86
98
|
##
|
87
99
|
# Iterates the given block for each RDF statement in the input.
|
88
100
|
#
|
@@ -169,7 +181,7 @@ module RDF::N3
|
|
169
181
|
when "@base"
|
170
182
|
# Base, set or update document URI
|
171
183
|
uri = decl[:explicituri]
|
172
|
-
|
184
|
+
options[:base_uri] = process_uri(uri)
|
173
185
|
|
174
186
|
# The empty prefix "" is by default , bound to "#" -- the local namespace of the file.
|
175
187
|
# The parser behaves as though there were a
|
@@ -177,8 +189,8 @@ module RDF::N3
|
|
177
189
|
# just before the file.
|
178
190
|
# This means that <#foo> can be written :foo and using @keywords one can reduce that to foo.
|
179
191
|
|
180
|
-
namespace(nil, uri.match(/[\/\#]$/) ?
|
181
|
-
add_debug("declarationFinish[@base]", "@base=#{
|
192
|
+
namespace(nil, uri.match(/[\/\#]$/) ? base_uri : process_uri("#{uri}#"))
|
193
|
+
add_debug("declarationFinish[@base]", "@base=#{base_uri}")
|
182
194
|
when "@keywords"
|
183
195
|
add_debug("declarationFinish[@keywords]", @keywords.inspect)
|
184
196
|
# Keywords are handled in tokenizer and maintained in @keywords array
|
@@ -257,7 +269,7 @@ module RDF::N3
|
|
257
269
|
def literalFinish
|
258
270
|
lit = @prod_data.pop
|
259
271
|
content = RDF::NTriples.unescape(lit[:string])
|
260
|
-
language = lit[:langcode]
|
272
|
+
language = lit[:langcode].downcase if lit[:langcode]
|
261
273
|
datatype = lit[:symbol]
|
262
274
|
|
263
275
|
lit = RDF::Literal.new(content, :language => language, :datatype => datatype, :validate => validate?, :canonicalize => canonicalize?)
|
@@ -554,7 +566,7 @@ module RDF::N3
|
|
554
566
|
end
|
555
567
|
|
556
568
|
def process_uri(uri)
|
557
|
-
uri(
|
569
|
+
uri(base_uri, RDF::NTriples.unescape(uri))
|
558
570
|
end
|
559
571
|
|
560
572
|
def process_qname(tok)
|
@@ -584,7 +596,7 @@ module RDF::N3
|
|
584
596
|
bnode(name)
|
585
597
|
else
|
586
598
|
add_debug('process_qname(default_ns)', name)
|
587
|
-
namespace(nil, uri("#{
|
599
|
+
namespace(nil, uri("#{base_uri}#")) unless prefix(nil)
|
588
600
|
ns(nil, name)
|
589
601
|
end
|
590
602
|
add_debug('process_qname', uri.inspect)
|
data/lib/rdf/n3/writer.rb
CHANGED
@@ -165,7 +165,7 @@ module RDF::N3
|
|
165
165
|
if uri.to_s.index(vocab.to_s) == 0
|
166
166
|
local_name = uri.to_s[(vocab.to_s.length)..-1]
|
167
167
|
add_debug "get_qname(ns): #{prefix}:#{local_name}"
|
168
|
-
return @uri_to_qname[uri] =
|
168
|
+
return @uri_to_qname[uri] = "#{prefix}:#{local_name}"
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -174,7 +174,7 @@ module RDF::N3
|
|
174
174
|
prefix = vocab.__name__.to_s.split('::').last.downcase
|
175
175
|
prefixes[prefix.to_sym] = vocab.to_uri
|
176
176
|
suffix = uri.to_s[vocab.to_uri.to_s.size..-1]
|
177
|
-
return @uri_to_qname[uri] =
|
177
|
+
return @uri_to_qname[uri] = "#{prefix}:#{suffix}"
|
178
178
|
end
|
179
179
|
|
180
180
|
@uri_to_qname[uri] = nil
|
@@ -192,8 +192,8 @@ module RDF::N3
|
|
192
192
|
def sort_properties(properties)
|
193
193
|
properties.keys.each do |k|
|
194
194
|
properties[k] = properties[k].sort do |a, b|
|
195
|
-
a_li = a.
|
196
|
-
b_li = b.
|
195
|
+
a_li = a.to_s.index(RDF._.to_s) == 0 ? a.to_s.match(/\d+$/).to_s.to_i : a.to_s
|
196
|
+
b_li = b.to_s.index(RDF._.to_s) == 0 ? b.to_s.match(/\d+$/).to_s.to_i : b.to_s
|
197
197
|
|
198
198
|
a_li <=> b_li
|
199
199
|
end
|
@@ -242,13 +242,7 @@ module RDF::N3
|
|
242
242
|
# @return [String]
|
243
243
|
def format_uri(uri, options = {})
|
244
244
|
md = relativize(uri)
|
245
|
-
|
246
|
-
"<%s>" % md
|
247
|
-
elsif qname = get_qname(uri)
|
248
|
-
qname.map(&:to_s).join(":")
|
249
|
-
else
|
250
|
-
"<%s>" % uri_for(uri)
|
251
|
-
end
|
245
|
+
md && md != uri.to_s ? "<#{md}>" : (get_qname(uri) || "<#{uri_for(uri)}>")
|
252
246
|
end
|
253
247
|
|
254
248
|
##
|
data/rdf-n3.gemspec
CHANGED
@@ -5,17 +5,18 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rdf-n3}
|
8
|
-
s.version = "0.3.1.
|
8
|
+
s.version = "0.3.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gregg Kellogg"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-30}
|
13
13
|
s.description = %q{RDF::N3 is an Notation-3 (n3-rdf) parser for Ruby using the RDF.rb library suite.}
|
14
14
|
s.email = %q{gregg@kellogg-assoc.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"AUTHORS",
|
17
17
|
"History.md",
|
18
18
|
"README.md",
|
19
|
+
"UNLICENSE",
|
19
20
|
"VERSION"
|
20
21
|
]
|
21
22
|
s.files = [
|
@@ -24,7 +25,9 @@ Gem::Specification.new do |s|
|
|
24
25
|
"History.md",
|
25
26
|
"README.md",
|
26
27
|
"Rakefile",
|
28
|
+
"UNLICENSE",
|
27
29
|
"VERSION",
|
30
|
+
"example-files/arnau-registered-vocab.rb",
|
28
31
|
"example-files/sp2b.n3",
|
29
32
|
"example.rb",
|
30
33
|
"lib/rdf/n3.rb",
|
@@ -414,7 +417,7 @@ Gem::Specification.new do |s|
|
|
414
417
|
]
|
415
418
|
s.homepage = %q{http://github.com/gkellogg/rdf-n3}
|
416
419
|
s.require_paths = ["lib"]
|
417
|
-
s.rubygems_version = %q{1.
|
420
|
+
s.rubygems_version = %q{1.6.2}
|
418
421
|
s.summary = %q{Notation-3 (n3-rdf) and Turtle reader/writer for RDF.rb.}
|
419
422
|
s.test_files = [
|
420
423
|
"spec/cwm_spec.rb",
|
data/script/parse
CHANGED
@@ -6,48 +6,44 @@ require 'rdf/ntriples'
|
|
6
6
|
require 'getoptlong'
|
7
7
|
require 'open-uri'
|
8
8
|
|
9
|
-
def run(input,
|
10
|
-
reader_class = RDF::Reader.for(
|
11
|
-
|
12
|
-
raise "Reader not found for #{$input_format}" unless reader_class
|
13
|
-
raise "Writer not found for #{$output_format}" unless writer_class
|
9
|
+
def run(input, options)
|
10
|
+
reader_class = RDF::Reader.for(options[:input_format].to_sym)
|
11
|
+
raise "Reader not found for #{options[:input_format]}" unless reader_class
|
14
12
|
|
15
13
|
start = Time.new
|
16
14
|
num = 0
|
17
|
-
if
|
15
|
+
if options[:parse_only]
|
18
16
|
include RDF::N3::Meta
|
19
17
|
include RDF::N3::Parser
|
20
|
-
puts "\nparse #{input.read}---\n\n" unless
|
18
|
+
puts "\nparse #{input.read}---\n\n" unless options[:quiet]
|
21
19
|
input.rewind
|
22
|
-
if
|
20
|
+
if options[:quiet]
|
23
21
|
$stdout = StringIO.new
|
24
22
|
end
|
25
23
|
test(input, BRANCHES, REGEXPS)
|
26
|
-
if
|
24
|
+
if options[:quiet]
|
27
25
|
$stdout = STDOUT
|
28
26
|
print "."
|
29
27
|
end
|
30
|
-
elsif
|
31
|
-
reader_class.new(input, :base_uri =>
|
28
|
+
elsif options[:output_format] == :ntriples || options[:quiet]
|
29
|
+
reader_class.new(input, :base_uri => options[:base_uri], :strict => true).each do |statement|
|
32
30
|
num += 1
|
33
|
-
if
|
31
|
+
if options[:quiet]
|
34
32
|
#print "."
|
35
33
|
else
|
36
34
|
puts statement.to_ntriples
|
37
35
|
end
|
38
36
|
end
|
39
|
-
elsif
|
40
|
-
reader_class.new(input, :base_uri =>
|
37
|
+
elsif options[:output_format] == :inspect
|
38
|
+
reader_class.new(input, :base_uri => options[:base_uri], :strict => true).each do |statement|
|
41
39
|
num += 1
|
42
40
|
puts statement.inspect
|
43
41
|
end
|
44
42
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
}
|
43
|
+
r = reader_class.new(input, :base_uri => options[:base_uri], :strict => true)
|
44
|
+
g = RDF::Graph.new << r
|
45
|
+
num = g.count
|
46
|
+
puts g.dump(options[:output_format], :base_uri => r.base_uri, :prefixes => r.prefixes)
|
51
47
|
end
|
52
48
|
puts
|
53
49
|
secs = Time.new - start
|
@@ -58,10 +54,12 @@ rescue
|
|
58
54
|
raise
|
59
55
|
end
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
options = {
|
58
|
+
:verbose => false,
|
59
|
+
:output_format => :ntriples,
|
60
|
+
:input_format => :n3,
|
61
|
+
:base_uri => "http://example.com",
|
62
|
+
}
|
65
63
|
input = nil
|
66
64
|
|
67
65
|
opts = GetoptLong.new(
|
@@ -76,23 +74,24 @@ opts = GetoptLong.new(
|
|
76
74
|
)
|
77
75
|
opts.each do |opt, arg|
|
78
76
|
case opt
|
79
|
-
when '--
|
80
|
-
when '--
|
81
|
-
when '--
|
82
|
-
when '--
|
83
|
-
when '--format' then
|
84
|
-
when '--
|
85
|
-
when '--
|
86
|
-
when '--
|
77
|
+
when '--base-uri' then options[:verbose] = true
|
78
|
+
when '--debug' then ::RDF::N3::debug = true
|
79
|
+
when '--execute' then input = arg
|
80
|
+
when '--format' then options[:output_format] = arg.to_sym
|
81
|
+
when '--input-format' then options[:input_format] = arg.to_sym
|
82
|
+
when '--parse-only' then options[:parse_only] = true
|
83
|
+
when '--quiet' then options[:quiet] = true
|
84
|
+
when '--uri' then options[:base_uri] = arg
|
85
|
+
when '--verbose' then options[:verbose] = true
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
if ARGV.empty?
|
91
90
|
s = input ? input : $stdin.read
|
92
|
-
run(StringIO.new(s),
|
91
|
+
run(StringIO.new(s), options)
|
93
92
|
else
|
94
93
|
ARGV.each do |test_file|
|
95
|
-
run(Kernel.open(test_file),
|
94
|
+
run(Kernel.open(test_file), options)
|
96
95
|
end
|
97
96
|
end
|
98
97
|
puts
|
data/spec/n3reader_spec.rb
CHANGED
@@ -264,7 +264,7 @@ describe "RDF::N3::Reader" do
|
|
264
264
|
it "should allow mixed-case language" do
|
265
265
|
n3doc = %(:x2 :p "xyz"@EN .)
|
266
266
|
statement = parse(n3doc).statements.first
|
267
|
-
statement.object.to_ntriples.should == %("xyz"@
|
267
|
+
statement.object.to_ntriples.should == %("xyz"@en)
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should create typed literals" do
|
data/spec/writer_spec.rb
CHANGED
@@ -34,6 +34,16 @@ describe RDF::N3::Writer do
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
+
# see example-files/arnau-registered-vocab.rb
|
38
|
+
it "should use qname URIs with empty suffix" do
|
39
|
+
input = %(<http://xmlns.com/foaf/0.1/> <http://xmlns.com/foaf/0.1/> <http://xmlns.com/foaf/0.1/> .)
|
40
|
+
serialize(input, nil,
|
41
|
+
[%r(^@prefix foaf: <http://xmlns.com/foaf/0.1/> \.$),
|
42
|
+
%r(^foaf: foaf: foaf: \.$)],
|
43
|
+
:prefixes => { "foaf" => RDF::FOAF}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
37
47
|
it "should order properties" do
|
38
48
|
input = %(
|
39
49
|
@prefix : <http://xmlns.com/foaf/0.1/> .
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rdf-n3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.1.
|
5
|
+
version: 0.3.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gregg Kellogg
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-30 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -111,6 +111,7 @@ extra_rdoc_files:
|
|
111
111
|
- AUTHORS
|
112
112
|
- History.md
|
113
113
|
- README.md
|
114
|
+
- UNLICENSE
|
114
115
|
- VERSION
|
115
116
|
files:
|
116
117
|
- .yardopts
|
@@ -118,7 +119,9 @@ files:
|
|
118
119
|
- History.md
|
119
120
|
- README.md
|
120
121
|
- Rakefile
|
122
|
+
- UNLICENSE
|
121
123
|
- VERSION
|
124
|
+
- example-files/arnau-registered-vocab.rb
|
122
125
|
- example-files/sp2b.n3
|
123
126
|
- example.rb
|
124
127
|
- lib/rdf/n3.rb
|
@@ -529,7 +532,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
529
532
|
requirements: []
|
530
533
|
|
531
534
|
rubyforge_project:
|
532
|
-
rubygems_version: 1.
|
535
|
+
rubygems_version: 1.6.2
|
533
536
|
signing_key:
|
534
537
|
specification_version: 3
|
535
538
|
summary: Notation-3 (n3-rdf) and Turtle reader/writer for RDF.rb.
|