rdf 0.3.0.pre → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +40 -19
- data/VERSION +1 -1
- data/lib/rdf/mixin/enumerable.rb +15 -15
- data/lib/rdf/mixin/queryable.rb +47 -28
- data/lib/rdf/model/list.rb +22 -22
- data/lib/rdf/model/literal/boolean.rb +13 -1
- data/lib/rdf/model/literal/decimal.rb +5 -2
- data/lib/rdf/model/literal/double.rb +14 -6
- data/lib/rdf/model/literal/integer.rb +2 -0
- data/lib/rdf/model/literal/numeric.rb +9 -0
- data/lib/rdf/model/literal.rb +37 -19
- data/lib/rdf/model/resource.rb +3 -3
- data/lib/rdf/model/statement.rb +16 -15
- data/lib/rdf/model/term.rb +45 -0
- data/lib/rdf/model/value.rb +2 -18
- data/lib/rdf/nquads.rb +15 -3
- data/lib/rdf/ntriples/reader.rb +4 -4
- data/lib/rdf/ntriples/writer.rb +7 -4
- data/lib/rdf/ntriples.rb +3 -3
- data/lib/rdf/query/pattern.rb +95 -59
- data/lib/rdf/query/solution.rb +9 -9
- data/lib/rdf/query/variable.rb +9 -9
- data/lib/rdf/query.rb +62 -40
- data/lib/rdf/reader.rb +6 -5
- data/lib/rdf/repository.rb +40 -22
- data/lib/rdf/util/aliasing.rb +3 -3
- data/lib/rdf/util/cache.rb +8 -7
- data/lib/rdf/version.rb +1 -1
- data/lib/rdf/writer.rb +15 -13
- data/lib/rdf.rb +5 -1
- metadata +12 -14
data/lib/rdf/repository.rb
CHANGED
@@ -58,6 +58,7 @@ module RDF
|
|
58
58
|
#
|
59
59
|
# @return [URI]
|
60
60
|
attr_reader :uri
|
61
|
+
alias_method :url, :uri
|
61
62
|
|
62
63
|
##
|
63
64
|
# Returns the title of this repository.
|
@@ -149,8 +150,9 @@ module RDF
|
|
149
150
|
#
|
150
151
|
# @param [RDF::Resource] context
|
151
152
|
# @yield [tx]
|
152
|
-
# @yieldparam
|
153
|
-
# @
|
153
|
+
# @yieldparam [RDF::Transaction] tx
|
154
|
+
# @yieldreturn [void] ignored
|
155
|
+
# @return [void] `self`
|
154
156
|
# @see RDF::Transaction
|
155
157
|
# @since 0.3.0
|
156
158
|
def transaction(context = nil, &block)
|
@@ -193,7 +195,7 @@ module RDF
|
|
193
195
|
# the underlying storage.
|
194
196
|
#
|
195
197
|
# @param [RDF::Transaction] tx
|
196
|
-
# @return [void]
|
198
|
+
# @return [void] ignored
|
197
199
|
# @since 0.3.0
|
198
200
|
def rollback_transaction(tx)
|
199
201
|
# nothing to do
|
@@ -207,7 +209,7 @@ module RDF
|
|
207
209
|
# the underlying storage.
|
208
210
|
#
|
209
211
|
# @param [RDF::Transaction] tx
|
210
|
-
# @return [void]
|
212
|
+
# @return [void] ignored
|
211
213
|
# @since 0.3.0
|
212
214
|
def commit_transaction(tx)
|
213
215
|
tx.execute(self)
|
@@ -216,6 +218,8 @@ module RDF
|
|
216
218
|
##
|
217
219
|
# @see RDF::Repository
|
218
220
|
module Implementation
|
221
|
+
DEFAULT_CONTEXT = false
|
222
|
+
|
219
223
|
##
|
220
224
|
# @private
|
221
225
|
def self.extend_object(obj)
|
@@ -268,6 +272,7 @@ module RDF
|
|
268
272
|
# @see RDF::Enumerable#has_statement?
|
269
273
|
def has_statement?(statement)
|
270
274
|
s, p, o, c = statement.to_quad
|
275
|
+
c ||= DEFAULT_CONTEXT
|
271
276
|
@data.has_key?(c) &&
|
272
277
|
@data[c].has_key?(s) &&
|
273
278
|
@data[c][s].has_key?(p) &&
|
@@ -287,30 +292,32 @@ module RDF
|
|
287
292
|
ss.dup.each do |s, ps|
|
288
293
|
ps.dup.each do |p, os|
|
289
294
|
os.dup.each do |o|
|
290
|
-
block.call(RDF::Statement.new(s, p, o, :context => c))
|
295
|
+
block.call(RDF::Statement.new(s, p, o, :context => c.equal?(DEFAULT_CONTEXT) ? nil : c))
|
291
296
|
end
|
292
297
|
end
|
293
298
|
end
|
294
299
|
end
|
295
|
-
else
|
296
|
-
enum_statement
|
297
300
|
end
|
301
|
+
enum_statement
|
298
302
|
end
|
299
|
-
|
300
303
|
alias_method :each, :each_statement
|
301
304
|
|
302
305
|
##
|
303
306
|
# @private
|
304
307
|
# @see RDF::Enumerable#has_context?
|
305
308
|
def has_context?(value)
|
306
|
-
@data.keys.
|
309
|
+
@data.keys.include?(value)
|
307
310
|
end
|
308
311
|
|
309
312
|
##
|
310
313
|
# @private
|
311
314
|
# @see RDF::Enumerable#each_context
|
312
315
|
def each_context(&block)
|
313
|
-
|
316
|
+
if block_given?
|
317
|
+
contexts = @data.keys
|
318
|
+
contexts.delete(DEFAULT_CONTEXT)
|
319
|
+
contexts.each(&block)
|
320
|
+
end
|
314
321
|
enum_context
|
315
322
|
end
|
316
323
|
|
@@ -320,15 +327,24 @@ module RDF
|
|
320
327
|
# @private
|
321
328
|
# @see RDF::Queryable#query
|
322
329
|
def query_pattern(pattern, &block)
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
330
|
+
context = pattern.context
|
331
|
+
subject = pattern.subject
|
332
|
+
predicate = pattern.predicate
|
333
|
+
object = pattern.object
|
334
|
+
|
335
|
+
cs = @data.has_key?(context) ? {context => @data[context]} : @data.dup
|
336
|
+
cs.each do |c, ss|
|
337
|
+
next unless context.nil? || context == c
|
338
|
+
ss = ss.has_key?(subject) ? {subject => ss[subject]} : ss.dup
|
339
|
+
ss.each do |s, ps|
|
340
|
+
next unless subject.nil? || subject == s
|
341
|
+
ps = ps.has_key?(predicate) ? {predicate => ps[predicate]} : ps.dup
|
342
|
+
ps.each do |p, os|
|
343
|
+
next unless predicate.nil? || predicate == p
|
344
|
+
os = os.dup # TODO: is this really needed?
|
345
|
+
os.each do |o|
|
346
|
+
next unless object.nil? || object == o
|
347
|
+
block.call(RDF::Statement.new(s, p, o, :context => c.equal?(DEFAULT_CONTEXT) ? nil : c))
|
332
348
|
end
|
333
349
|
end
|
334
350
|
end
|
@@ -341,6 +357,7 @@ module RDF
|
|
341
357
|
def insert_statement(statement)
|
342
358
|
unless has_statement?(statement)
|
343
359
|
s, p, o, c = statement.to_quad
|
360
|
+
c ||= DEFAULT_CONTEXT
|
344
361
|
@data[c] ||= {}
|
345
362
|
@data[c][s] ||= {}
|
346
363
|
@data[c][s][p] ||= []
|
@@ -354,6 +371,7 @@ module RDF
|
|
354
371
|
def delete_statement(statement)
|
355
372
|
if has_statement?(statement)
|
356
373
|
s, p, o, c = statement.to_quad
|
374
|
+
c ||= DEFAULT_CONTEXT
|
357
375
|
@data[c][s][p].delete(o)
|
358
376
|
@data[c][s].delete(p) if @data[c][s][p].empty?
|
359
377
|
@data[c].delete(s) if @data[c][s].empty?
|
@@ -372,6 +390,6 @@ module RDF
|
|
372
390
|
protected :insert_statement
|
373
391
|
protected :delete_statement
|
374
392
|
protected :clear_statements
|
375
|
-
end #
|
376
|
-
end #
|
377
|
-
end #
|
393
|
+
end # Implementation
|
394
|
+
end # Repository
|
395
|
+
end # RDF
|
data/lib/rdf/util/aliasing.rb
CHANGED
data/lib/rdf/util/cache.rb
CHANGED
@@ -9,8 +9,9 @@ module RDF; module Util
|
|
9
9
|
#
|
10
10
|
# While this cache is something of an internal implementation detail of
|
11
11
|
# RDF.rb, some external libraries do currently make use of it as well,
|
12
|
-
# including [
|
13
|
-
#
|
12
|
+
# including [SPARQL::Algebra](http://sparql.rubyforge.org/algebra/) and
|
13
|
+
# [Spira](http://spira.rubyforge.org/). Do be sure to include any changes
|
14
|
+
# here in the RDF.rb changelog.
|
14
15
|
#
|
15
16
|
# @see RDF::URI.intern
|
16
17
|
# @see http://en.wikipedia.org/wiki/Weak_reference
|
@@ -48,7 +49,7 @@ module RDF; module Util
|
|
48
49
|
##
|
49
50
|
# @return [Boolean]
|
50
51
|
def has_capacity?
|
51
|
-
@capacity
|
52
|
+
@capacity.equal?(-1) || @capacity > @cache.size
|
52
53
|
end
|
53
54
|
|
54
55
|
##
|
@@ -94,7 +95,7 @@ module RDF; module Util
|
|
94
95
|
end
|
95
96
|
value
|
96
97
|
end
|
97
|
-
end #
|
98
|
+
end # ObjectSpaceCache
|
98
99
|
|
99
100
|
##
|
100
101
|
# This implementation uses the `WeakRef` class from Ruby's standard
|
@@ -131,6 +132,6 @@ module RDF; module Util
|
|
131
132
|
end
|
132
133
|
value
|
133
134
|
end
|
134
|
-
end #
|
135
|
-
end #
|
136
|
-
end; end #
|
135
|
+
end # WeakRefCache
|
136
|
+
end # Cache
|
137
|
+
end; end # RDF::Util
|
data/lib/rdf/version.rb
CHANGED
data/lib/rdf/writer.rb
CHANGED
@@ -238,8 +238,8 @@ module RDF
|
|
238
238
|
#
|
239
239
|
# @return [RDF::URI]
|
240
240
|
def prefix(name, uri = nil)
|
241
|
-
name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym
|
242
|
-
uri.nil? ? prefixes[name] : prefixes[name] =
|
241
|
+
name = name.to_s.empty? ? nil : (name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym)
|
242
|
+
uri.nil? ? prefixes[name] : prefixes[name] = uri
|
243
243
|
end
|
244
244
|
alias_method :prefix!, :prefix
|
245
245
|
|
@@ -300,7 +300,7 @@ module RDF
|
|
300
300
|
end
|
301
301
|
|
302
302
|
##
|
303
|
-
# @param [Array<Array(RDF::Resource, RDF::URI, RDF::
|
303
|
+
# @param [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>] triples
|
304
304
|
# @return [void] `self`
|
305
305
|
def write_triples(*triples)
|
306
306
|
triples.each { |triple| write_triple(*triple) }
|
@@ -310,7 +310,7 @@ module RDF
|
|
310
310
|
##
|
311
311
|
# @param [RDF::Resource] subject
|
312
312
|
# @param [RDF::URI] predicate
|
313
|
-
# @param [RDF::
|
313
|
+
# @param [RDF::Term] object
|
314
314
|
# @return [void] `self`
|
315
315
|
# @raise [NotImplementedError] unless implemented in subclass
|
316
316
|
# @abstract
|
@@ -324,18 +324,20 @@ module RDF
|
|
324
324
|
alias_method :insert_statement, :write_statement
|
325
325
|
|
326
326
|
##
|
327
|
-
# @param [RDF::
|
327
|
+
# @param [RDF::Term] term
|
328
328
|
# @return [String]
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
when
|
333
|
-
when RDF::
|
334
|
-
when RDF::
|
335
|
-
when RDF::
|
329
|
+
# @since 0.3.0
|
330
|
+
def format_term(term, options = {})
|
331
|
+
case term
|
332
|
+
when String then format_literal(RDF::Literal(term, options), options)
|
333
|
+
when RDF::List then format_list(term, options)
|
334
|
+
when RDF::Literal then format_literal(term, options)
|
335
|
+
when RDF::URI then format_uri(term, options)
|
336
|
+
when RDF::Node then format_node(term, options)
|
336
337
|
else nil
|
337
338
|
end
|
338
339
|
end
|
340
|
+
alias_method :format_value, :format_term # @deprecated
|
339
341
|
|
340
342
|
##
|
341
343
|
# @param [RDF::Node] value
|
@@ -374,7 +376,7 @@ module RDF
|
|
374
376
|
# @abstract
|
375
377
|
# @since 0.2.3
|
376
378
|
def format_list(value, options = {})
|
377
|
-
|
379
|
+
format_term(value.subject, options)
|
378
380
|
end
|
379
381
|
|
380
382
|
protected
|
data/lib/rdf.rb
CHANGED
@@ -44,6 +44,7 @@ module RDF
|
|
44
44
|
autoload :Statement, 'rdf/model/statement'
|
45
45
|
autoload :URI, 'rdf/model/uri'
|
46
46
|
autoload :Value, 'rdf/model/value'
|
47
|
+
autoload :Term, 'rdf/model/term'
|
47
48
|
|
48
49
|
# RDF collections
|
49
50
|
autoload :List, 'rdf/model/list'
|
@@ -115,7 +116,10 @@ module RDF
|
|
115
116
|
#
|
116
117
|
# @return [RDF::Literal]
|
117
118
|
def self.Literal(*args, &block)
|
118
|
-
|
119
|
+
case literal = args.first
|
120
|
+
when RDF::Literal then literal
|
121
|
+
else Literal.new(*args, &block)
|
122
|
+
end
|
119
123
|
end
|
120
124
|
|
121
125
|
##
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 0.3.0.pre
|
9
|
+
version: 0.3.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Arto Bendiken
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2010-
|
19
|
+
date: 2010-12-27 00:00:00 +01:00
|
21
20
|
default_executable: rdf
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
- - ">="
|
56
55
|
- !ruby/object:Gem::Version
|
57
56
|
segments:
|
57
|
+
- 2
|
58
58
|
- 1
|
59
|
-
- 3
|
60
59
|
- 0
|
61
|
-
version: 1.
|
60
|
+
version: 2.1.0
|
62
61
|
type: :development
|
63
62
|
version_requirements: *id003
|
64
63
|
- !ruby/object:Gem::Dependency
|
@@ -66,14 +65,13 @@ dependencies:
|
|
66
65
|
prerelease: false
|
67
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
68
67
|
requirements:
|
69
|
-
- -
|
68
|
+
- - ~>
|
70
69
|
- !ruby/object:Gem::Version
|
71
70
|
segments:
|
72
71
|
- 0
|
73
72
|
- 3
|
74
73
|
- 0
|
75
|
-
|
76
|
-
version: 0.3.0.pre
|
74
|
+
version: 0.3.0
|
77
75
|
type: :development
|
78
76
|
version_requirements: *id004
|
79
77
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
|
@@ -112,6 +110,7 @@ files:
|
|
112
110
|
- lib/rdf/model/literal/decimal.rb
|
113
111
|
- lib/rdf/model/literal/double.rb
|
114
112
|
- lib/rdf/model/literal/integer.rb
|
113
|
+
- lib/rdf/model/literal/numeric.rb
|
115
114
|
- lib/rdf/model/literal/time.rb
|
116
115
|
- lib/rdf/model/literal/token.rb
|
117
116
|
- lib/rdf/model/literal/xml.rb
|
@@ -119,6 +118,7 @@ files:
|
|
119
118
|
- lib/rdf/model/node.rb
|
120
119
|
- lib/rdf/model/resource.rb
|
121
120
|
- lib/rdf/model/statement.rb
|
121
|
+
- lib/rdf/model/term.rb
|
122
122
|
- lib/rdf/model/uri.rb
|
123
123
|
- lib/rdf/model/value.rb
|
124
124
|
- lib/rdf/nquads.rb
|
@@ -181,13 +181,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: 1.8.1
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
|
-
- - "
|
184
|
+
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
segments:
|
187
|
-
-
|
188
|
-
|
189
|
-
- 1
|
190
|
-
version: 1.3.1
|
187
|
+
- 0
|
188
|
+
version: "0"
|
191
189
|
requirements: []
|
192
190
|
|
193
191
|
rubyforge_project: rdf
|