rdf-trix 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +0 -0
- data/README +16 -6
- data/VERSION +1 -1
- data/lib/rdf/trix/format.rb +5 -2
- data/lib/rdf/trix/reader/libxml.rb +7 -9
- data/lib/rdf/trix/reader/nokogiri.rb +7 -9
- data/lib/rdf/trix/reader/rexml.rb +7 -9
- data/lib/rdf/trix/reader.rb +39 -21
- data/lib/rdf/trix/version.rb +1 -1
- data/lib/rdf/trix/writer/nokogiri.rb +3 -3
- data/lib/rdf/trix/writer/rexml.rb +3 -3
- data/lib/rdf/trix/writer.rb +10 -9
- data/lib/rdf/trix.rb +3 -3
- metadata +13 -12
data/CREDITS
ADDED
File without changes
|
data/README
CHANGED
@@ -19,7 +19,7 @@ Documentation
|
|
19
19
|
Dependencies
|
20
20
|
------------
|
21
21
|
|
22
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.
|
22
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.0)
|
23
23
|
* [REXML](http://ruby-doc.org/stdlib/libdoc/rexml/rdoc/) (>= 3.1.7),
|
24
24
|
[LibXML-Ruby](http://rubygems.org/gems/libxml-ruby) (>= 1.1.4), or
|
25
25
|
[Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.4.2)
|
@@ -39,21 +39,31 @@ To get a local working copy of the development repository, do:
|
|
39
39
|
|
40
40
|
% git clone git://github.com/bendiken/rdf-trix.git
|
41
41
|
|
42
|
-
Alternatively,
|
43
|
-
|
42
|
+
Alternatively, download the latest development version as a tarball as
|
43
|
+
follows:
|
44
44
|
|
45
45
|
% wget http://github.com/bendiken/rdf-trix/tarball/master
|
46
46
|
|
47
|
+
Mailing List
|
48
|
+
------------
|
49
|
+
|
50
|
+
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
51
|
+
|
47
52
|
Author
|
48
53
|
------
|
49
54
|
|
50
|
-
* [Arto Bendiken](
|
55
|
+
* [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
|
56
|
+
|
57
|
+
Contributors
|
58
|
+
------------
|
59
|
+
|
60
|
+
Refer to the accompanying {file:CREDITS} file.
|
51
61
|
|
52
62
|
License
|
53
63
|
-------
|
54
64
|
|
55
|
-
|
56
|
-
|
65
|
+
This is free and unencumbered public domain software. For more information,
|
66
|
+
see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
57
67
|
|
58
68
|
[RDF.rb]: http://rdf.rubyforge.org/
|
59
69
|
[TriX]: http://www.w3.org/2004/03/trix/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rdf/trix/format.rb
CHANGED
@@ -2,6 +2,9 @@ module RDF::TriX
|
|
2
2
|
##
|
3
3
|
# TriX format specification.
|
4
4
|
#
|
5
|
+
# @example Loading TriX format support
|
6
|
+
# require 'rdf/trix'
|
7
|
+
#
|
5
8
|
# @example Obtaining a TriX format class
|
6
9
|
# RDF::Format.for(:trix) #=> RDF::TriX::Format
|
7
10
|
# RDF::Format.for("etc/doap.xml")
|
@@ -18,5 +21,5 @@ module RDF::TriX
|
|
18
21
|
writer { RDF::TriX::Writer }
|
19
22
|
|
20
23
|
XMLNS = 'http://www.w3.org/2004/03/trix/trix-1/'
|
21
|
-
end #
|
22
|
-
end #
|
24
|
+
end # Format
|
25
|
+
end # RDF::TriX
|
@@ -33,28 +33,26 @@ module RDF::TriX
|
|
33
33
|
# @private
|
34
34
|
# @see RDF::Reader#each_graph
|
35
35
|
def each_graph(&block)
|
36
|
-
|
37
|
-
enum_for(:each_graph)
|
38
|
-
else
|
36
|
+
if block_given?
|
39
37
|
@xml.find('//trix:graph', OPTIONS).each do |graph_element|
|
40
38
|
graph = RDF::Graph.new(read_context(graph_element))
|
41
39
|
read_statements(graph_element) { |statement| graph << statement }
|
42
40
|
block.call(graph)
|
43
41
|
end
|
44
42
|
end
|
43
|
+
enum_graph
|
45
44
|
end
|
46
45
|
|
47
46
|
##
|
48
47
|
# @private
|
49
48
|
# @see RDF::Reader#each_statement
|
50
49
|
def each_statement(&block)
|
51
|
-
|
52
|
-
enum_for(:each_statement)
|
53
|
-
else
|
50
|
+
if block_given?
|
54
51
|
@xml.find('//trix:graph', OPTIONS).each do |graph_element|
|
55
52
|
read_statements(graph_element, &block)
|
56
53
|
end
|
57
54
|
end
|
55
|
+
enum_statement
|
58
56
|
end
|
59
57
|
|
60
58
|
protected
|
@@ -77,6 +75,6 @@ module RDF::TriX
|
|
77
75
|
block.call(RDF::Statement.new(*triple))
|
78
76
|
end
|
79
77
|
end
|
80
|
-
end #
|
81
|
-
end #
|
82
|
-
end #
|
78
|
+
end # LibXML
|
79
|
+
end # Reader
|
80
|
+
end # RDF::TriX
|
@@ -29,28 +29,26 @@ module RDF::TriX
|
|
29
29
|
# @private
|
30
30
|
# @see RDF::Reader#each_graph
|
31
31
|
def each_graph(&block)
|
32
|
-
|
33
|
-
enum_for(:each_graph)
|
34
|
-
else
|
32
|
+
if block_given?
|
35
33
|
@xml.xpath('//trix:graph', OPTIONS).each do |graph_element|
|
36
34
|
graph = RDF::Graph.new(read_context(graph_element))
|
37
35
|
read_statements(graph_element) { |statement| graph << statement }
|
38
36
|
block.call(graph)
|
39
37
|
end
|
40
38
|
end
|
39
|
+
enum_graph
|
41
40
|
end
|
42
41
|
|
43
42
|
##
|
44
43
|
# @private
|
45
44
|
# @see RDF::Reader#each_statement
|
46
45
|
def each_statement(&block)
|
47
|
-
|
48
|
-
enum_for(:each_statement)
|
49
|
-
else
|
46
|
+
if block_given?
|
50
47
|
@xml.xpath('//trix:graph', OPTIONS).each do |graph_element|
|
51
48
|
read_statements(graph_element, &block)
|
52
49
|
end
|
53
50
|
end
|
51
|
+
enum_statement
|
54
52
|
end
|
55
53
|
|
56
54
|
protected
|
@@ -73,6 +71,6 @@ module RDF::TriX
|
|
73
71
|
block.call(RDF::Statement.new(*triple))
|
74
72
|
end
|
75
73
|
end
|
76
|
-
end #
|
77
|
-
end #
|
78
|
-
end #
|
74
|
+
end # Nokogiri
|
75
|
+
end # Reader
|
76
|
+
end # RDF::TriX
|
@@ -29,28 +29,26 @@ module RDF::TriX
|
|
29
29
|
# @private
|
30
30
|
# @see RDF::Reader#each_graph
|
31
31
|
def each_graph(&block)
|
32
|
-
|
33
|
-
enum_for(:each_graph)
|
34
|
-
else
|
32
|
+
if block_given?
|
35
33
|
@xml.elements.each('TriX/graph') do |graph_element|
|
36
34
|
graph = RDF::Graph.new(read_context(graph_element))
|
37
35
|
read_statements(graph_element) { |statement| graph << statement }
|
38
36
|
block.call(graph)
|
39
37
|
end
|
40
38
|
end
|
39
|
+
enum_graph
|
41
40
|
end
|
42
41
|
|
43
42
|
##
|
44
43
|
# @private
|
45
44
|
# @see RDF::Reader#each_statement
|
46
45
|
def each_statement(&block)
|
47
|
-
|
48
|
-
enum_for(:each_statement)
|
49
|
-
else
|
46
|
+
if block_given?
|
50
47
|
@xml.elements.each('TriX/graph') do |graph_element|
|
51
48
|
read_statements(graph_element, &block)
|
52
49
|
end
|
53
50
|
end
|
51
|
+
enum_statement
|
54
52
|
end
|
55
53
|
|
56
54
|
protected
|
@@ -73,6 +71,6 @@ module RDF::TriX
|
|
73
71
|
block.call(RDF::Statement.new(*triple))
|
74
72
|
end
|
75
73
|
end
|
76
|
-
end #
|
77
|
-
end #
|
78
|
-
end #
|
74
|
+
end # REXML
|
75
|
+
end # Reader
|
76
|
+
end # RDF::TriX
|
data/lib/rdf/trix/reader.rb
CHANGED
@@ -12,6 +12,9 @@ module RDF::TriX
|
|
12
12
|
# [LibXML]: http://libxml.rubyforge.org/rdoc/
|
13
13
|
# [Nokogiri]: http://nokogiri.org/
|
14
14
|
#
|
15
|
+
# @example Loading TriX parsing support
|
16
|
+
# require 'rdf/trix'
|
17
|
+
#
|
15
18
|
# @example Obtaining a TriX reader class
|
16
19
|
# RDF::Reader.for(:trix) #=> RDF::TriX::Reader
|
17
20
|
# RDF::Reader.for("etc/doap.xml")
|
@@ -56,11 +59,13 @@ module RDF::TriX
|
|
56
59
|
##
|
57
60
|
# Initializes the TriX reader instance.
|
58
61
|
#
|
59
|
-
# @param [IO, File, String]
|
62
|
+
# @param [IO, File, String] input
|
60
63
|
# @param [Hash{Symbol => Object}] options
|
61
|
-
#
|
62
|
-
# @
|
63
|
-
# @
|
64
|
+
# any additional options (see `RDF::Reader#initialize`)
|
65
|
+
# @option options [Symbol] :library (:nokogiri, :libxml, or :rexml)
|
66
|
+
# @yield [reader] `self`
|
67
|
+
# @yieldparam [RDF::Reader] reader
|
68
|
+
# @yieldreturn [void] ignored
|
64
69
|
def initialize(input = $stdin, options = {}, &block)
|
65
70
|
super do
|
66
71
|
@library = case options[:library]
|
@@ -92,7 +97,12 @@ module RDF::TriX
|
|
92
97
|
self.extend(@implementation)
|
93
98
|
|
94
99
|
initialize_xml(options)
|
95
|
-
|
100
|
+
if block_given?
|
101
|
+
case block.arity
|
102
|
+
when 0 then instance_eval(&block)
|
103
|
+
else block.call(self)
|
104
|
+
end
|
105
|
+
end
|
96
106
|
end
|
97
107
|
end
|
98
108
|
|
@@ -100,32 +110,30 @@ module RDF::TriX
|
|
100
110
|
# @private
|
101
111
|
# @see RDF::Reader#each_triple
|
102
112
|
def each_triple(&block)
|
103
|
-
|
104
|
-
enum_for(:each_triple)
|
105
|
-
else
|
113
|
+
if block_given?
|
106
114
|
each_statement do |statement|
|
107
115
|
block.call(*statement.to_triple)
|
108
116
|
end
|
109
117
|
end
|
118
|
+
enum_triple
|
110
119
|
end
|
111
120
|
|
112
121
|
##
|
113
122
|
# @private
|
114
123
|
# @see RDF::Reader#each_quad
|
115
124
|
def each_quad(&block)
|
116
|
-
|
117
|
-
enum_for(:each_quad)
|
118
|
-
else
|
125
|
+
if block_given?
|
119
126
|
each_statement do |statement|
|
120
127
|
block.call(*statement.to_quad)
|
121
128
|
end
|
122
129
|
end
|
130
|
+
enum_quad
|
123
131
|
end
|
124
132
|
|
125
133
|
##
|
126
134
|
# Returns the RDF value of the given TriX element.
|
127
135
|
#
|
128
|
-
# @param [String]
|
136
|
+
# @param [String] name
|
129
137
|
# @param [Hash{String => Object}] attributes
|
130
138
|
# @param [String] content
|
131
139
|
# @return [RDF::Value]
|
@@ -134,18 +142,28 @@ module RDF::TriX
|
|
134
142
|
when :id
|
135
143
|
RDF::Node.new(content.strip)
|
136
144
|
when :uri
|
137
|
-
RDF::URI.new(content.strip)
|
145
|
+
uri = RDF::URI.new(content.strip) # TODO: interned URIs
|
146
|
+
uri.validate! if validate?
|
147
|
+
uri.canonicalize! if canonicalize?
|
148
|
+
uri
|
138
149
|
when :typedLiteral
|
139
|
-
RDF::Literal.new(content, :datatype => attributes['datatype'])
|
150
|
+
literal = RDF::Literal.new(content, :datatype => attributes['datatype'])
|
151
|
+
literal.validate! if validate?
|
152
|
+
literal.canonicalize! if canonicalize?
|
153
|
+
literal
|
140
154
|
when :plainLiteral
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
155
|
+
literal = case
|
156
|
+
when lang = attributes['xml:lang'] || attributes['lang']
|
157
|
+
RDF::Literal.new(content, :language => lang)
|
158
|
+
else
|
159
|
+
RDF::Literal.new(content)
|
145
160
|
end
|
161
|
+
literal.validate! if validate?
|
162
|
+
literal.canonicalize! if canonicalize?
|
163
|
+
literal
|
146
164
|
else
|
147
|
-
|
165
|
+
raise RDF::ReaderError, "expected element name to be 'id', 'uri', 'typedLiteral', or 'plainLiteral', but got #{name.inspect}"
|
148
166
|
end
|
149
167
|
end
|
150
|
-
end #
|
151
|
-
end #
|
168
|
+
end # Reader
|
169
|
+
end # RDF::TriX
|
data/lib/rdf/trix/version.rb
CHANGED
data/lib/rdf/trix/writer.rb
CHANGED
@@ -12,6 +12,9 @@ module RDF::TriX
|
|
12
12
|
# [LibXML]: http://libxml.rubyforge.org/rdoc/
|
13
13
|
# [Nokogiri]: http://nokogiri.org/
|
14
14
|
#
|
15
|
+
# @example Loading TriX serialization support
|
16
|
+
# require 'rdf/trix'
|
17
|
+
#
|
15
18
|
# @example Obtaining a TriX writer class
|
16
19
|
# RDF::Writer.for(:trix) #=> RDF::TriX::Writer
|
17
20
|
# RDF::Writer.for("etc/test.xml")
|
@@ -58,13 +61,15 @@ module RDF::TriX
|
|
58
61
|
##
|
59
62
|
# Initializes the TriX writer instance.
|
60
63
|
#
|
61
|
-
# @param [IO, File]
|
64
|
+
# @param [IO, File] output
|
62
65
|
# @param [Hash{Symbol => Object}] options
|
66
|
+
# any additional options (see `RDF::Writer#initialize`)
|
63
67
|
# @option options [Symbol] :library (:nokogiri or :rexml)
|
64
68
|
# @option options [String, #to_s] :encoding ('utf-8')
|
65
69
|
# @option options [Integer] :indent (2)
|
66
|
-
# @yield [writer]
|
67
|
-
# @yieldparam
|
70
|
+
# @yield [writer] `self`
|
71
|
+
# @yieldparam [RDF::Writer] writer
|
72
|
+
# @yieldreturn [void] ignored
|
68
73
|
def initialize(output = $stdout, options = {}, &block)
|
69
74
|
@context = nil
|
70
75
|
@nesting = 0
|
@@ -219,7 +224,6 @@ module RDF::TriX
|
|
219
224
|
# @param [Hash{Symbol => Object}] options
|
220
225
|
# @return [Element]
|
221
226
|
def format_literal(value, options = {})
|
222
|
-
value = RDF::Literal.new(value) unless value.is_a?(RDF::Literal) # FIXME: remove after RDF.rb 0.2.1
|
223
227
|
case
|
224
228
|
when value.has_datatype?
|
225
229
|
create_element(:typedLiteral, value.value.to_s, 'datatype' => value.datatype.to_s)
|
@@ -229,8 +233,5 @@ module RDF::TriX
|
|
229
233
|
create_element(:plainLiteral, value.value.to_s)
|
230
234
|
end
|
231
235
|
end
|
232
|
-
|
233
|
-
|
234
|
-
alias_method :insert_statement, :write_statement # FIXME: remove after RDF.rb 0.2.1
|
235
|
-
end # class Writer
|
236
|
-
end # module RDF::TriX
|
236
|
+
end # Writer
|
237
|
+
end # RDF::TriX
|
data/lib/rdf/trix.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rdf'
|
1
|
+
require 'rdf' # @see http://rubygems.org/gems/rdf
|
2
2
|
|
3
3
|
module RDF
|
4
4
|
##
|
@@ -32,5 +32,5 @@ module RDF
|
|
32
32
|
autoload :Reader, 'rdf/trix/reader'
|
33
33
|
autoload :Writer, 'rdf/trix/writer'
|
34
34
|
autoload :VERSION, 'rdf/trix/version'
|
35
|
-
end #
|
36
|
-
end #
|
35
|
+
end # TriX
|
36
|
+
end # RDF
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arto Bendiken
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-27 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,9 +26,9 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
-
-
|
29
|
+
- 3
|
30
30
|
- 0
|
31
|
-
version: 0.
|
31
|
+
version: 0.3.0
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
@@ -82,9 +82,9 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
- 5
|
86
85
|
- 6
|
87
|
-
|
86
|
+
- 0
|
87
|
+
version: 0.6.0
|
88
88
|
type: :development
|
89
89
|
version_requirements: *id005
|
90
90
|
- !ruby/object:Gem::Dependency
|
@@ -95,10 +95,10 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
segments:
|
98
|
+
- 2
|
98
99
|
- 1
|
99
|
-
- 3
|
100
100
|
- 0
|
101
|
-
version: 1.
|
101
|
+
version: 2.1.0
|
102
102
|
type: :development
|
103
103
|
version_requirements: *id006
|
104
104
|
- !ruby/object:Gem::Dependency
|
@@ -110,9 +110,9 @@ dependencies:
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
segments:
|
112
112
|
- 0
|
113
|
-
-
|
113
|
+
- 3
|
114
114
|
- 0
|
115
|
-
version: 0.
|
115
|
+
version: 0.3.0
|
116
116
|
type: :development
|
117
117
|
version_requirements: *id007
|
118
118
|
description: RDF.rb plugin for parsing/serializing TriX data.
|
@@ -125,6 +125,7 @@ extra_rdoc_files: []
|
|
125
125
|
|
126
126
|
files:
|
127
127
|
- AUTHORS
|
128
|
+
- CREDITS
|
128
129
|
- README
|
129
130
|
- UNLICENSE
|
130
131
|
- VERSION
|
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
166
|
- 0
|
166
167
|
version: "0"
|
167
168
|
requirements:
|
168
|
-
- REXML (>= 3.1.7), LibXML-Ruby (>= 1.1.4) or Nokogiri (>= 1.4.2)
|
169
|
+
- REXML (>= 3.1.7), LibXML-Ruby (>= 1.1.4), or Nokogiri (>= 1.4.2)
|
169
170
|
rubyforge_project: rdf
|
170
171
|
rubygems_version: 1.3.6
|
171
172
|
signing_key:
|