rdf 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/VERSION +1 -1
- data/lib/rdf.rb +4 -0
- data/lib/rdf/mixin/writable.rb +20 -0
- data/lib/rdf/model/list.rb +698 -0
- data/lib/rdf/model/literal.rb +13 -1
- data/lib/rdf/model/literal/decimal.rb +91 -0
- data/lib/rdf/model/literal/double.rb +165 -0
- data/lib/rdf/model/literal/integer.rb +131 -0
- data/lib/rdf/model/literal/token.rb +47 -0
- data/lib/rdf/model/statement.rb +0 -1
- data/lib/rdf/query/pattern.rb +0 -1
- data/lib/rdf/query/variable.rb +8 -3
- data/lib/rdf/reader.rb +14 -0
- data/lib/rdf/util/cache.rb +2 -2
- data/lib/rdf/version.rb +1 -1
- data/lib/rdf/writer.rb +19 -9
- metadata +9 -7
@@ -0,0 +1,47 @@
|
|
1
|
+
module RDF; class Literal
|
2
|
+
##
|
3
|
+
# A token literal.
|
4
|
+
#
|
5
|
+
# @see http://www.w3.org/TR/xmlschema-2/#token
|
6
|
+
# @since 0.2.3
|
7
|
+
class Token < Literal
|
8
|
+
DATATYPE = XSD.token
|
9
|
+
GRAMMAR = /\A[^\x0D\x0A\x09]+\z/i.freeze # FIXME
|
10
|
+
|
11
|
+
##
|
12
|
+
# @param [Symbol, #to_s] value
|
13
|
+
# @option options [String] :lexical (nil)
|
14
|
+
def initialize(value, options = {})
|
15
|
+
@datatype = RDF::URI(options[:datatype] || DATATYPE)
|
16
|
+
@string = options[:lexical] if options.has_key?(:lexical)
|
17
|
+
@string = value if !defined?(@string) && value.is_a?(String)
|
18
|
+
@object = value.is_a?(Symbol) ? value : value.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Converts the literal into its canonical lexical representation.
|
23
|
+
#
|
24
|
+
# @return [Literal]
|
25
|
+
# @see http://www.w3.org/TR/xmlschema-2/#boolean
|
26
|
+
def canonicalize
|
27
|
+
@string = @object.to_s if @object
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Returns the value as a symbol.
|
33
|
+
#
|
34
|
+
# @return [Symbol]
|
35
|
+
def to_sym
|
36
|
+
@object.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns the value as a string.
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
def to_s
|
44
|
+
@string || @object.to_s
|
45
|
+
end
|
46
|
+
end # class Token
|
47
|
+
end; end # class RDF::Literal
|
data/lib/rdf/model/statement.rb
CHANGED
data/lib/rdf/query/pattern.rb
CHANGED
@@ -153,7 +153,6 @@ module RDF; class Query
|
|
153
153
|
#
|
154
154
|
# @return [String]
|
155
155
|
def to_s
|
156
|
-
require 'stringio' unless defined?(StringIO)
|
157
156
|
StringIO.open do |buffer| # FIXME in RDF::Statement
|
158
157
|
buffer << (subject.is_a?(Variable) ? subject.to_s : "<#{subject}>") << ' '
|
159
158
|
buffer << (predicate.is_a?(Variable) ? predicate.to_s : "<#{predicate}>") << ' '
|
data/lib/rdf/query/variable.rb
CHANGED
@@ -2,11 +2,15 @@ class RDF::Query
|
|
2
2
|
##
|
3
3
|
# An RDF query variable.
|
4
4
|
#
|
5
|
-
# @example Creating
|
5
|
+
# @example Creating a named unbound variable
|
6
6
|
# var = RDF::Query::Variable.new(:x)
|
7
7
|
# var.unbound? #=> true
|
8
8
|
# var.value #=> nil
|
9
9
|
#
|
10
|
+
# @example Creating an anonymous unbound variable
|
11
|
+
# var = RDF::Query::Variable.new
|
12
|
+
# var.name #=> :g2166151240
|
13
|
+
#
|
10
14
|
# @example Unbound variables match any value
|
11
15
|
# var === 42 #=> true
|
12
16
|
#
|
@@ -52,8 +56,9 @@ class RDF::Query
|
|
52
56
|
##
|
53
57
|
# @param [Symbol] name
|
54
58
|
# @param [Value] value
|
55
|
-
def initialize(name, value = nil)
|
56
|
-
@name
|
59
|
+
def initialize(name = nil, value = nil)
|
60
|
+
@name = (name || "g#{__id__.to_i.abs}").to_sym
|
61
|
+
@value = value
|
57
62
|
end
|
58
63
|
|
59
64
|
##
|
data/lib/rdf/reader.rb
CHANGED
@@ -159,8 +159,22 @@ module RDF
|
|
159
159
|
end
|
160
160
|
|
161
161
|
##
|
162
|
+
# Rewinds the input stream to the beginning of input.
|
163
|
+
#
|
164
|
+
# @return [void]
|
165
|
+
# @since 0.2.3
|
166
|
+
# @see http://ruby-doc.org/core-1.9/classes/IO.html#M001692
|
167
|
+
def rewind
|
168
|
+
@input.rewind
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Closes the input stream. An `IOError` is raised for further read
|
173
|
+
# attempts.
|
174
|
+
#
|
162
175
|
# @return [void]
|
163
176
|
# @since 0.2.2
|
177
|
+
# @see http://ruby-doc.org/core-1.9/classes/IO.html#M001699
|
164
178
|
def close
|
165
179
|
@input.close unless @input.closed?
|
166
180
|
end
|
data/lib/rdf/util/cache.rb
CHANGED
@@ -73,7 +73,7 @@ module RDF; module Util
|
|
73
73
|
# @return [Object]
|
74
74
|
def [](key)
|
75
75
|
if value_id = @cache[key]
|
76
|
-
value = ObjectSpace._id2ref(value_id)
|
76
|
+
value = ObjectSpace._id2ref(value_id) rescue nil
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -110,7 +110,7 @@ module RDF; module Util
|
|
110
110
|
# @return [Object]
|
111
111
|
def [](key)
|
112
112
|
if (ref = @cache[key]) && ref.weakref_alive?
|
113
|
-
value = ref.__getobj__
|
113
|
+
value = ref.__getobj__ rescue nil
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
data/lib/rdf/version.rb
CHANGED
data/lib/rdf/writer.rb
CHANGED
@@ -33,6 +33,7 @@ module RDF
|
|
33
33
|
# @see RDF::Format
|
34
34
|
# @see RDF::Reader
|
35
35
|
class Writer
|
36
|
+
extend RDF::Util::Aliasing::LateBound
|
36
37
|
extend ::Enumerable
|
37
38
|
include RDF::Writable
|
38
39
|
|
@@ -125,8 +126,6 @@ module RDF
|
|
125
126
|
# @yieldparam [Writer] writer
|
126
127
|
# @return [String]
|
127
128
|
def self.buffer(*args, &block)
|
128
|
-
require 'stringio' unless defined?(StringIO)
|
129
|
-
|
130
129
|
StringIO.open do |buffer|
|
131
130
|
self.new(buffer, *args) { |writer| block.call(writer) }
|
132
131
|
buffer.string
|
@@ -270,7 +269,8 @@ module RDF
|
|
270
269
|
# @return [String]
|
271
270
|
def format_value(value, options = {})
|
272
271
|
case value
|
273
|
-
when String then format_literal(value, options)
|
272
|
+
when String then format_literal(RDF::Literal.new(value, options), options)
|
273
|
+
when RDF::List then format_list(value, options)
|
274
274
|
when RDF::Literal then format_literal(value, options)
|
275
275
|
when RDF::URI then format_uri(value, options)
|
276
276
|
when RDF::Node then format_node(value, options)
|
@@ -279,23 +279,23 @@ module RDF
|
|
279
279
|
end
|
280
280
|
|
281
281
|
##
|
282
|
-
# @param [
|
282
|
+
# @param [Node] value
|
283
283
|
# @param [Hash{Symbol => Object}] options
|
284
284
|
# @return [String]
|
285
285
|
# @raise [NotImplementedError] unless implemented in subclass
|
286
286
|
# @abstract
|
287
|
-
def
|
288
|
-
raise NotImplementedError.new("#{self.class}#
|
287
|
+
def format_node(value, options = {})
|
288
|
+
raise NotImplementedError.new("#{self.class}#format_node") # override in subclasses
|
289
289
|
end
|
290
290
|
|
291
291
|
##
|
292
|
-
# @param [
|
292
|
+
# @param [URI] value
|
293
293
|
# @param [Hash{Symbol => Object}] options
|
294
294
|
# @return [String]
|
295
295
|
# @raise [NotImplementedError] unless implemented in subclass
|
296
296
|
# @abstract
|
297
|
-
def
|
298
|
-
raise NotImplementedError.new("#{self.class}#
|
297
|
+
def format_uri(value, options = {})
|
298
|
+
raise NotImplementedError.new("#{self.class}#format_uri") # override in subclasses
|
299
299
|
end
|
300
300
|
|
301
301
|
##
|
@@ -308,6 +308,16 @@ module RDF
|
|
308
308
|
raise NotImplementedError.new("#{self.class}#format_literal") # override in subclasses
|
309
309
|
end
|
310
310
|
|
311
|
+
##
|
312
|
+
# @param [List] value
|
313
|
+
# @param [Hash{Symbol => Object}] options
|
314
|
+
# @return [String]
|
315
|
+
# @abstract
|
316
|
+
# @since 0.2.3
|
317
|
+
def format_list(value, options = {})
|
318
|
+
format_value(value.subject, options)
|
319
|
+
end
|
320
|
+
|
311
321
|
protected
|
312
322
|
|
313
323
|
##
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
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-08-26 00:00:00 +02:00
|
19
19
|
default_executable: rdf
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -27,9 +27,9 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
30
|
-
- 1
|
31
30
|
- 2
|
32
|
-
|
31
|
+
- 0
|
32
|
+
version: 2.2.0
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -70,8 +70,8 @@ dependencies:
|
|
70
70
|
segments:
|
71
71
|
- 0
|
72
72
|
- 2
|
73
|
-
-
|
74
|
-
version: 0.2.
|
73
|
+
- 3
|
74
|
+
version: 0.2.3
|
75
75
|
type: :development
|
76
76
|
version_requirements: *id004
|
77
77
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/rdf/mixin/readable.rb
|
103
103
|
- lib/rdf/mixin/writable.rb
|
104
104
|
- lib/rdf/model/graph.rb
|
105
|
+
- lib/rdf/model/list.rb
|
105
106
|
- lib/rdf/model/literal/boolean.rb
|
106
107
|
- lib/rdf/model/literal/date.rb
|
107
108
|
- lib/rdf/model/literal/datetime.rb
|
@@ -109,6 +110,7 @@ files:
|
|
109
110
|
- lib/rdf/model/literal/double.rb
|
110
111
|
- lib/rdf/model/literal/integer.rb
|
111
112
|
- lib/rdf/model/literal/time.rb
|
113
|
+
- lib/rdf/model/literal/token.rb
|
112
114
|
- lib/rdf/model/literal/xml.rb
|
113
115
|
- lib/rdf/model/literal.rb
|
114
116
|
- lib/rdf/model/node.rb
|