rdf 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/VERSION +1 -1
- data/lib/rdf/mixin/enumerable.rb +18 -2
- data/lib/rdf/mixin/queryable.rb +6 -6
- data/lib/rdf/model/graph.rb +1 -1
- data/lib/rdf/model/value.rb +1 -1
- data/lib/rdf/ntriples.rb +1 -0
- data/lib/rdf/ntriples/reader.rb +36 -4
- data/lib/rdf/query/variable.rb +1 -1
- data/lib/rdf/reader.rb +22 -1
- data/lib/rdf/repository.rb +14 -0
- data/lib/rdf/version.rb +1 -1
- data/lib/rdf/writer.rb +7 -6
- metadata +7 -7
data/README
CHANGED
@@ -6,6 +6,7 @@ This is a pure-Ruby library for working with [Resource Description Framework
|
|
6
6
|
|
7
7
|
* <http://github.com/bendiken/rdf>
|
8
8
|
* <http://blog.datagraph.org/2010/03/rdf-for-ruby>
|
9
|
+
* <http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby>
|
9
10
|
* <http://blog.datagraph.org/2010/04/rdf-repository-howto>
|
10
11
|
|
11
12
|
Features
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -107,6 +107,8 @@ module RDF
|
|
107
107
|
#
|
108
108
|
# If no block was given, returns an enumerator.
|
109
109
|
#
|
110
|
+
# The order in which statements are yielded is undefined.
|
111
|
+
#
|
110
112
|
# @overload each_statement
|
111
113
|
# @yield [statement]
|
112
114
|
# @yieldparam [Statement] statement
|
@@ -162,6 +164,8 @@ module RDF
|
|
162
164
|
#
|
163
165
|
# If no block was given, returns an enumerator.
|
164
166
|
#
|
167
|
+
# The order in which triples are yielded is undefined.
|
168
|
+
#
|
165
169
|
# @overload each_triple
|
166
170
|
# @yield [subject, predicate, object]
|
167
171
|
# @yieldparam [Resource] subject
|
@@ -220,6 +224,8 @@ module RDF
|
|
220
224
|
#
|
221
225
|
# If no block was given, returns an enumerator.
|
222
226
|
#
|
227
|
+
# The order in which quads are yielded is undefined.
|
228
|
+
#
|
223
229
|
# @overload each_quad
|
224
230
|
# @yield [subject, predicate, object, context]
|
225
231
|
# @yieldparam [Resource] subject
|
@@ -284,6 +290,8 @@ module RDF
|
|
284
290
|
#
|
285
291
|
# If no block was given, returns an enumerator.
|
286
292
|
#
|
293
|
+
# The order in which values are yielded is undefined.
|
294
|
+
#
|
287
295
|
# @overload each_subject
|
288
296
|
# @yield [subject]
|
289
297
|
# @yieldparam [Resource] subject
|
@@ -350,6 +358,8 @@ module RDF
|
|
350
358
|
#
|
351
359
|
# If no block was given, returns an enumerator.
|
352
360
|
#
|
361
|
+
# The order in which values are yielded is undefined.
|
362
|
+
#
|
353
363
|
# @overload each_predicate
|
354
364
|
# @yield [predicate]
|
355
365
|
# @yieldparam [URI] predicate
|
@@ -416,6 +426,8 @@ module RDF
|
|
416
426
|
#
|
417
427
|
# If no block was given, returns an enumerator.
|
418
428
|
#
|
429
|
+
# The order in which values are yielded is undefined.
|
430
|
+
#
|
419
431
|
# @overload each_object
|
420
432
|
# @yield [object]
|
421
433
|
# @yieldparam [Value] object
|
@@ -482,6 +494,8 @@ module RDF
|
|
482
494
|
#
|
483
495
|
# If no block was given, returns an enumerator.
|
484
496
|
#
|
497
|
+
# The order in which values are yielded is undefined.
|
498
|
+
#
|
485
499
|
# @overload each_context
|
486
500
|
# @yield [context]
|
487
501
|
# @yieldparam [Resource] context
|
@@ -523,6 +537,8 @@ module RDF
|
|
523
537
|
#
|
524
538
|
# If no block was given, returns an enumerator.
|
525
539
|
#
|
540
|
+
# The order in which graphs are yielded is undefined.
|
541
|
+
#
|
526
542
|
# @overload each_graph
|
527
543
|
# @yield [graph]
|
528
544
|
# @yieldparam [RDF::Graph] graph
|
@@ -533,7 +549,7 @@ module RDF
|
|
533
549
|
#
|
534
550
|
# @return [void]
|
535
551
|
# @see #enum_graph
|
536
|
-
# @since 0.1.
|
552
|
+
# @since 0.1.9
|
537
553
|
def each_graph(&block)
|
538
554
|
if block_given?
|
539
555
|
block.call(RDF::Graph.new(nil, :data => self))
|
@@ -550,7 +566,7 @@ module RDF
|
|
550
566
|
#
|
551
567
|
# @return [Enumerator]
|
552
568
|
# @see #each_graph
|
553
|
-
# @since 0.1.
|
569
|
+
# @since 0.1.9
|
554
570
|
def enum_graph
|
555
571
|
Enumerator.new(self, :each_graph)
|
556
572
|
end
|
data/lib/rdf/mixin/queryable.rb
CHANGED
@@ -56,7 +56,7 @@ module RDF
|
|
56
56
|
# @return [RDF::Statement]
|
57
57
|
#
|
58
58
|
# @return [RDF::Statement]
|
59
|
-
# @since 0.1.
|
59
|
+
# @since 0.1.9
|
60
60
|
def first(pattern = nil)
|
61
61
|
if pattern
|
62
62
|
query(pattern) do |statement|
|
@@ -82,7 +82,7 @@ module RDF
|
|
82
82
|
# @return [RDF::Resource]
|
83
83
|
#
|
84
84
|
# @return [RDF::Resource]
|
85
|
-
# @since 0.1.
|
85
|
+
# @since 0.1.9
|
86
86
|
def first_subject(pattern = nil)
|
87
87
|
__send__(*(pattern ? [:query, pattern] : [:each])) do |statement|
|
88
88
|
return statement.subject
|
@@ -104,7 +104,7 @@ module RDF
|
|
104
104
|
# @return [RDF::URI]
|
105
105
|
#
|
106
106
|
# @return [RDF::URI]
|
107
|
-
# @since 0.1.
|
107
|
+
# @since 0.1.9
|
108
108
|
def first_predicate(pattern = nil)
|
109
109
|
__send__(*(pattern ? [:query, pattern] : [:each])) do |statement|
|
110
110
|
return statement.predicate
|
@@ -126,7 +126,7 @@ module RDF
|
|
126
126
|
# @return [RDF::Value]
|
127
127
|
#
|
128
128
|
# @return [RDF::Value]
|
129
|
-
# @since 0.1.
|
129
|
+
# @since 0.1.9
|
130
130
|
def first_object(pattern = nil)
|
131
131
|
__send__(*(pattern ? [:query, pattern] : [:each])) do |statement|
|
132
132
|
return statement.object
|
@@ -149,7 +149,7 @@ module RDF
|
|
149
149
|
# @return [RDF::Literal]
|
150
150
|
#
|
151
151
|
# @return [RDF::Literal]
|
152
|
-
# @since 0.1.
|
152
|
+
# @since 0.1.9
|
153
153
|
def first_literal(pattern = nil)
|
154
154
|
__send__(*(pattern ? [:query, pattern] : [:each])) do |statement|
|
155
155
|
return statement.object if statement.object.is_a?(RDF::Literal)
|
@@ -172,7 +172,7 @@ module RDF
|
|
172
172
|
# @return [Object]
|
173
173
|
#
|
174
174
|
# @return [Object]
|
175
|
-
# @since 0.1.
|
175
|
+
# @since 0.1.9
|
176
176
|
def first_value(pattern = nil)
|
177
177
|
(literal = first_literal(pattern)) ? literal.value : nil
|
178
178
|
end
|
data/lib/rdf/model/graph.rb
CHANGED
data/lib/rdf/model/value.rb
CHANGED
data/lib/rdf/ntriples.rb
CHANGED
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -42,6 +42,15 @@ module RDF::NTriples
|
|
42
42
|
PREDICATE = Regexp.union(URIREF).freeze
|
43
43
|
OBJECT = Regexp.union(URIREF, NODEID, LITERAL).freeze
|
44
44
|
|
45
|
+
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
46
|
+
ESCAPE_CHARS = ["\t", "\n", "\r", "\"", "\\"].freeze
|
47
|
+
ESCAPE_CHAR4 = /\\u([0-9A-Fa-f]{4,4})/.freeze
|
48
|
+
ESCAPE_CHAR8 = /\\U([0-9A-Fa-f]{8,8})/.freeze
|
49
|
+
ESCAPE_CHAR = Regexp.union(ESCAPE_CHAR4, ESCAPE_CHAR8).freeze
|
50
|
+
ESCAPE_SURROGATE = /\\u([0-9A-Fa-f]{4,4})\\u([0-9A-Fa-f]{4,4})/.freeze
|
51
|
+
ESCAPE_SURROGATE1 = (0xD800..0xDBFF).freeze
|
52
|
+
ESCAPE_SURROGATE2 = (0xDC00..0xDFFF).freeze
|
53
|
+
|
45
54
|
##
|
46
55
|
# Reconstructs an RDF value from its serialized N-Triples
|
47
56
|
# representation.
|
@@ -112,12 +121,35 @@ module RDF::NTriples
|
|
112
121
|
# @param [String] string
|
113
122
|
# @return [String]
|
114
123
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
124
|
+
# @see http://blog.grayproductions.net/articles/understanding_m17n
|
115
125
|
def self.unescape(string)
|
116
|
-
|
117
|
-
|
126
|
+
string.force_encoding(Encoding::ASCII_8BIT) if string.respond_to?(:force_encoding)
|
127
|
+
|
128
|
+
# Decode \t|\n|\r|\"|\\ character escapes:
|
129
|
+
ESCAPE_CHARS.each { |escape| string.gsub!(escape.inspect[1...-1], escape) }
|
130
|
+
|
131
|
+
# Decode \uXXXX\uXXXX surrogate pairs:
|
132
|
+
while
|
133
|
+
(string.sub!(ESCAPE_SURROGATE) do
|
134
|
+
if ESCAPE_SURROGATE1.include?($1.hex) && ESCAPE_SURROGATE2.include?($2.hex)
|
135
|
+
s = [$1, $2].pack('H*H*')
|
136
|
+
s = s.respond_to?(:force_encoding) ?
|
137
|
+
s.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8) : # for Ruby 1.9+
|
138
|
+
Iconv.conv('UTF-8', 'UTF-16BE', s) # for Ruby 1.8.x
|
139
|
+
else
|
140
|
+
s = [$1.hex].pack('U*') << '\u' << $2
|
141
|
+
end
|
142
|
+
s.respond_to?(:force_encoding) ? s.force_encoding(Encoding::ASCII_8BIT) : s
|
143
|
+
end)
|
118
144
|
end
|
119
|
-
|
120
|
-
|
145
|
+
|
146
|
+
# Decode \uXXXX and \UXXXXXXXX code points:
|
147
|
+
string.gsub!(ESCAPE_CHAR) do
|
148
|
+
s = [($1 || $2).hex].pack('U*')
|
149
|
+
s.respond_to?(:force_encoding) ? s.force_encoding(Encoding::ASCII_8BIT) : s
|
150
|
+
end
|
151
|
+
|
152
|
+
string.force_encoding(Encoding::UTF_8) if string.respond_to?(:force_encoding)
|
121
153
|
string
|
122
154
|
end
|
123
155
|
|
data/lib/rdf/query/variable.rb
CHANGED
data/lib/rdf/reader.rb
CHANGED
@@ -193,27 +193,48 @@ module RDF
|
|
193
193
|
|
194
194
|
@@subclasses = [] # @private
|
195
195
|
|
196
|
-
|
196
|
+
##
|
197
|
+
# @private
|
198
|
+
def self.inherited(child)
|
197
199
|
@@subclasses << child
|
198
200
|
super
|
199
201
|
end
|
200
202
|
|
203
|
+
##
|
204
|
+
# @return [Integer]
|
201
205
|
def lineno
|
202
206
|
@input.lineno
|
203
207
|
end
|
204
208
|
|
209
|
+
##
|
210
|
+
# @return [String]
|
205
211
|
def readline
|
206
212
|
@line = @input.readline.chomp
|
213
|
+
@line.force_encoding(encoding) if @line.respond_to?(:force_encoding) # for Ruby 1.9+
|
214
|
+
@line
|
207
215
|
end
|
208
216
|
|
217
|
+
##
|
218
|
+
# @return [Encoding]
|
219
|
+
def encoding
|
220
|
+
@encoding ||= ::Encoding::UTF_8
|
221
|
+
end
|
222
|
+
|
223
|
+
##
|
224
|
+
# @return [void]
|
209
225
|
def strip!
|
210
226
|
@line.strip!
|
211
227
|
end
|
212
228
|
|
229
|
+
##
|
230
|
+
# @return [Boolean]
|
213
231
|
def blank?
|
214
232
|
@line.nil? || @line.empty?
|
215
233
|
end
|
216
234
|
|
235
|
+
##
|
236
|
+
# @param [Regexp] pattern
|
237
|
+
# @return [Object]
|
217
238
|
def match(pattern)
|
218
239
|
if @line =~ pattern
|
219
240
|
result, @line = $1, $'.lstrip
|
data/lib/rdf/repository.rb
CHANGED
@@ -128,6 +128,20 @@ module RDF
|
|
128
128
|
##
|
129
129
|
# @see RDF::Repository
|
130
130
|
module Implementation
|
131
|
+
##
|
132
|
+
# Returns `true` if this repository supports `feature`.
|
133
|
+
#
|
134
|
+
# @param [Symbol, #to_sym] feature
|
135
|
+
# @return [Boolean]
|
136
|
+
# @since 0.1.10
|
137
|
+
def supports?(feature)
|
138
|
+
case feature.to_sym
|
139
|
+
when :context then true # statement contexts / named graphs
|
140
|
+
when :inference then false # forward-chaining inference
|
141
|
+
else false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
131
145
|
##
|
132
146
|
# Returns `false` to indicate that this repository is nondurable.
|
133
147
|
#
|
data/lib/rdf/version.rb
CHANGED
data/lib/rdf/writer.rb
CHANGED
@@ -295,12 +295,13 @@ module RDF
|
|
295
295
|
# @param [Resource] uriref
|
296
296
|
# @return [String]
|
297
297
|
def uri_for(uriref)
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
uriref.to_uri
|
302
|
-
|
303
|
-
|
298
|
+
case
|
299
|
+
when uriref.is_a?(RDF::Node)
|
300
|
+
@nodes[uriref]
|
301
|
+
when uriref.respond_to?(:to_uri)
|
302
|
+
uriref.to_uri.to_s
|
303
|
+
else
|
304
|
+
uriref.to_s
|
304
305
|
end
|
305
306
|
end
|
306
307
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 10
|
9
|
+
version: 0.1.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arto Bendiken
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-05-20 00:00:00 +02:00
|
19
19
|
default_executable: rdf
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 1
|
31
|
-
-
|
32
|
-
version: 0.1.
|
31
|
+
- 10
|
32
|
+
version: 0.1.10
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -56,8 +56,8 @@ dependencies:
|
|
56
56
|
segments:
|
57
57
|
- 0
|
58
58
|
- 5
|
59
|
-
-
|
60
|
-
version: 0.5.
|
59
|
+
- 4
|
60
|
+
version: 0.5.4
|
61
61
|
type: :development
|
62
62
|
version_requirements: *id003
|
63
63
|
- !ruby/object:Gem::Dependency
|