rdf 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ * Fumihiro Kato <fumi@fumi.me>
1
2
  * Gregg Kellogg <gregg@kellogg-assoc.com>
2
3
  * Hellekin O. Wolf <hellekin@cepheide.org>
3
4
  * John Fieber <jrf@ursamaris.org>
data/README CHANGED
@@ -124,6 +124,7 @@ Documentation
124
124
 
125
125
  ### RDF Vocabularies
126
126
 
127
+ * {RDF} - Resource Description Framework (RDF)
127
128
  * {RDF::CC} - Creative Commons (CC)
128
129
  * {RDF::CERT} - W3 Authentication Certificate (CERT)
129
130
  * {RDF::DC} - Dublin Core (DC)
@@ -180,6 +181,11 @@ Resources
180
181
  * <http://raa.ruby-lang.org/project/rdf/>
181
182
  * <http://www.ohloh.net/p/rdf>
182
183
 
184
+ Mailing List
185
+ ------------
186
+
187
+ * <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
188
+
183
189
  Authors
184
190
  -------
185
191
 
@@ -189,6 +195,7 @@ Authors
189
195
  Contributors
190
196
  ------------
191
197
 
198
+ * [Fumihiro Kato](mailto:fumi@fumi.me) - <http://fumi.me/>
192
199
  * [Gregg Kellogg](mailto:gregg@kellogg-assoc.com) - <http://kellogg-assoc.com/>
193
200
  * [Hellekin O. Wolf](mailto:hellekin@cepheide.org) - <http://hellekin.cepheide.org/>
194
201
  * [John Fieber](mailto:jrf@ursamaris.org) - <http://github.com/jfieber>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -27,6 +27,8 @@
27
27
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid1 .
28
28
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid2 .
29
29
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid3 .
30
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid4 .
31
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid5 .
30
32
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#homepage> <http://rdf.rubyforge.org/> .
31
33
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#license> <http://creativecommons.org/licenses/publicdomain/> .
32
34
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#maintainer> <http://ar.to/#self> .
@@ -37,11 +39,17 @@
37
39
  <http://rubygems.org/gems/rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://usefulinc.com/ns/doap#Project> .
38
40
  <http://rubygems.org/gems/rdf> <http://xmlns.com/foaf/0.1/maker> <http://ar.to/#self> .
39
41
  _:genid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
40
- _:genid1 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "c69f3255ff0639543cc5edfd8116eac8df16fab8" .
41
- _:genid1 <http://xmlns.com/foaf/0.1/name> "Hellekin O. Wolf" .
42
+ _:genid1 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "d31fdd6af7a279a89bf09fdc9f7c44d9d08bb930" .
43
+ _:genid1 <http://xmlns.com/foaf/0.1/name> "Fumihiro Kato" .
42
44
  _:genid2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
43
- _:genid2 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "f7653fc1ac0e82ebb32f092389bd5fc728eaae12" .
44
- _:genid2 <http://xmlns.com/foaf/0.1/name> "John Fieber" .
45
+ _:genid2 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "35bc44e6d0070e5ad50ccbe0d24403c96af2b9bd" .
46
+ _:genid2 <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .
45
47
  _:genid3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
46
- _:genid3 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "bedbbf2451e5beb38d59687c0460032aff92cd3c" .
47
- _:genid3 <http://xmlns.com/foaf/0.1/name> "Pius Uzamere" .
48
+ _:genid3 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "c69f3255ff0639543cc5edfd8116eac8df16fab8" .
49
+ _:genid3 <http://xmlns.com/foaf/0.1/name> "Hellekin O. Wolf" .
50
+ _:genid4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
51
+ _:genid4 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "f7653fc1ac0e82ebb32f092389bd5fc728eaae12" .
52
+ _:genid4 <http://xmlns.com/foaf/0.1/name> "John Fieber" .
53
+ _:genid5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
54
+ _:genid5 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "bedbbf2451e5beb38d59687c0460032aff92cd3c" .
55
+ _:genid5 <http://xmlns.com/foaf/0.1/name> "Pius Uzamere" .
@@ -32,12 +32,7 @@ module RDF
32
32
  when Query
33
33
  pattern.execute(self, &block)
34
34
  else
35
- pattern = case pattern
36
- when Query::Pattern, Statement then pattern
37
- when Array then Query::Pattern.new(*pattern)
38
- when Hash then Query::Pattern.new(pattern)
39
- else raise ArgumentError.new("expected RDF::Query, RDF::Query::Pattern, Array, or Hash, but got #{pattern.inspect}")
40
- end
35
+ pattern = Query::Pattern.from(pattern)
41
36
 
42
37
  if block_given?
43
38
  query_pattern(pattern, &block)
@@ -126,14 +126,9 @@ module RDF
126
126
  #
127
127
  # @param [RDF::Statement, Hash, Array, #to_a] statement
128
128
  # @return [RDF::Statement]
129
+ # @deprecated
129
130
  def create_statement(statement)
130
- # TODO: move this to RDF::Statement.construct or the like.
131
- case statement
132
- when Statement then statement
133
- when Hash then Statement.new(statement)
134
- when Array then Statement.new(*statement)
135
- else raise ArgumentError.new # FIXME
136
- end
131
+ Statement.from(statement)
137
132
  end
138
133
 
139
134
  protected :insert_statements
@@ -195,11 +195,17 @@ module RDF
195
195
  end
196
196
 
197
197
  ##
198
- # Inserts the given RDF statement into the graph.
199
- #
200
- # @param [RDF::Statement] statement
201
- # @return [void]
202
- # @see RDF::Mutable#insert
198
+ # @private
199
+ # @see RDF::Queryable#query
200
+ def query_pattern(pattern, &block)
201
+ pattern = pattern.dup
202
+ pattern.context = context
203
+ @data.query(pattern, &block)
204
+ end
205
+
206
+ ##
207
+ # @private
208
+ # @see RDF::Mutable#insert
203
209
  def insert_statement(statement)
204
210
  statement = statement.dup
205
211
  statement.context = context
@@ -207,11 +213,8 @@ module RDF
207
213
  end
208
214
 
209
215
  ##
210
- # Deletes the given RDF statement from the graph.
211
- #
212
- # @param [RDF::Statement] statement
213
- # @return [void]
214
- # @see RDF::Mutable#delete
216
+ # @private
217
+ # @see RDF::Mutable#delete
215
218
  def delete_statement(statement)
216
219
  statement = statement.dup
217
220
  statement.context = context
@@ -219,14 +222,13 @@ module RDF
219
222
  end
220
223
 
221
224
  ##
222
- # Deletes all RDF statements from this graph.
223
- #
224
- # @return [void]
225
- # @see RDF::Mutable#clear
225
+ # @private
226
+ # @see RDF::Mutable#clear
226
227
  def clear_statements
227
228
  @data.delete(:context => context)
228
229
  end
229
230
 
231
+ protected :query_pattern
230
232
  protected :insert_statement
231
233
  protected :delete_statement
232
234
  protected :clear_statements
@@ -113,7 +113,7 @@ module RDF
113
113
  # @option options [URI] :datatype (nil)
114
114
  def initialize(value, options = {})
115
115
  @object = value
116
- @string = options[:lexical] if options.has_key?(:lexical)
116
+ @string = options[:lexical] if options[:lexical]
117
117
  @language = options[:language].to_s.to_sym if options[:language]
118
118
  @datatype = RDF::URI(options[:datatype]) if options[:datatype]
119
119
  end
@@ -14,7 +14,7 @@ module RDF; class Literal
14
14
  # @param [Boolean] value
15
15
  # @option options [String] :lexical (nil)
16
16
  def initialize(value, options = {})
17
- @datatype = options[:datatype] || DATATYPE
17
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
18
18
  @string = options[:lexical] if options.has_key?(:lexical)
19
19
  @string = value if !defined?(@string) && value.is_a?(String)
20
20
  @object = case
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @param [Date] value
13
13
  # @option options [String] :lexical (nil)
14
14
  def initialize(value, options = {})
15
- @datatype = options[:datatype] || DATATYPE
15
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
16
16
  @string = options[:lexical] if options.has_key?(:lexical)
17
17
  @string = value if !defined?(@string) && value.is_a?(String)
18
18
  @object = case
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @param [DateTime] value
13
13
  # @option options [String] :lexical (nil)
14
14
  def initialize(value, options = {})
15
- @datatype = options[:datatype] || DATATYPE
15
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
16
16
  @string = options[:lexical] if options.has_key?(:lexical)
17
17
  @string = value if !defined?(@string) && value.is_a?(String)
18
18
  @object = case
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @param [BigDecimal] value
13
13
  # @option options [String] :lexical (nil)
14
14
  def initialize(value, options = {})
15
- @datatype = options[:datatype] || DATATYPE
15
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
16
16
  @string = options[:lexical] if options.has_key?(:lexical)
17
17
  @string = value if !defined?(@string) && value.is_a?(String)
18
18
  @object = case
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @param [Float, #to_f] value
13
13
  # @option options [String] :lexical (nil)
14
14
  def initialize(value, options = {})
15
- @datatype = options[:datatype] || DATATYPE
15
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
16
16
  @string = options[:lexical] if options.has_key?(:lexical)
17
17
  @string = value if !defined?(@string) && value.is_a?(String)
18
18
  @object = case
@@ -12,7 +12,7 @@ module RDF; class Literal
12
12
  # @param [Integer, #to_i] value
13
13
  # @option options [String] :lexical (nil)
14
14
  def initialize(value, options = {})
15
- @datatype = options[:datatype] || DATATYPE
15
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
16
16
  @string = options[:lexical] if options.has_key?(:lexical)
17
17
  @string = value if !defined?(@string) && value.is_a?(String)
18
18
  @object = case
@@ -16,7 +16,7 @@ module RDF; class Literal
16
16
  # @param [Time] value
17
17
  # @option options [String] :lexical (nil)
18
18
  def initialize(value, options = {})
19
- @datatype = options[:datatype] || DATATYPE
19
+ @datatype = RDF::URI(options[:datatype] || DATATYPE)
20
20
  @string = options[:lexical] if options.has_key?(:lexical)
21
21
  @string = value if !defined?(@string) && value.is_a?(String)
22
22
  @object = case
@@ -21,6 +21,18 @@ module RDF
21
21
  class Statement
22
22
  include RDF::Value
23
23
 
24
+ ##
25
+ # @private
26
+ # @since 0.2.2
27
+ def self.from(statement)
28
+ case statement
29
+ when Statement then statement
30
+ when Hash then self.new(statement)
31
+ when Array then self.new(*statement)
32
+ else raise ArgumentError.new("expected RDF::Statement, Hash, or Array, but got #{statement.inspect}")
33
+ end
34
+ end
35
+
24
36
  # @return [Object]
25
37
  attr_accessor :id
26
38
 
@@ -49,6 +49,8 @@ module RDF
49
49
  #
50
50
  # @param [String] data
51
51
  # @return [RDF::Value]
52
+ # @see RDF::NTriples::Reader.unserialize
53
+ # @since 0.1.5
52
54
  def self.unserialize(data)
53
55
  Reader.unserialize(data)
54
56
  end
@@ -59,9 +61,29 @@ module RDF
59
61
  #
60
62
  # @param [RDF::Value] value
61
63
  # @return [String]
64
+ # @see RDF::NTriples::Writer.serialize
65
+ # @since 0.1.5
62
66
  def self.serialize(value)
63
67
  Writer.serialize(value)
64
68
  end
69
+
70
+ ##
71
+ # @param [String] string
72
+ # @return [String]
73
+ # @see RDF::NTriples::Reader.unescape
74
+ # @since 0.2.2
75
+ def self.unescape(string)
76
+ Reader.unescape(string)
77
+ end
78
+
79
+ ##
80
+ # @param [String] string
81
+ # @return [String]
82
+ # @see RDF::NTriples::Writer.escape
83
+ # @since 0.2.2
84
+ def self.escape(string)
85
+ Writer.escape(string)
86
+ end
65
87
  end
66
88
 
67
89
  ##
@@ -1,7 +1,20 @@
1
- class RDF::Query
1
+ module RDF; class Query
2
2
  ##
3
3
  # An RDF query pattern.
4
4
  class Pattern < RDF::Statement
5
+ ##
6
+ # @private
7
+ # @since 0.2.2
8
+ def self.from(pattern)
9
+ case pattern
10
+ when Pattern then pattern
11
+ when Statement then self.new(pattern.to_hash)
12
+ when Hash then self.new(pattern)
13
+ when Array then self.new(*pattern)
14
+ else raise ArgumentError.new("expected RDF::Query::Pattern, RDF::Statement, Hash, or Array, but got #{pattern.inspect}")
15
+ end
16
+ end
17
+
5
18
  # @return [Hash{Symbol => Object}]
6
19
  attr_reader :options
7
20
 
@@ -11,6 +24,7 @@ class RDF::Query
11
24
  # @option options [Variable, Resource] :subject (nil)
12
25
  # @option options [Variable, URI] :predicate (nil)
13
26
  # @option options [Variable, Value] :object (nil)
27
+ # @option options [Variable, Resource] :context (nil)
14
28
  # @option options [Boolean] :optional (false)
15
29
  #
16
30
  # @overload initialize(subject, predicate, object, options = {})
@@ -18,6 +32,7 @@ class RDF::Query
18
32
  # @param [Variable, URI] predicate
19
33
  # @param [Variable, Value] object
20
34
  # @param [Hash{Symbol => Object}] options
35
+ # @option options [Variable, Resource] :context (nil)
21
36
  # @option options [Boolean] :optional (false)
22
37
  def initialize(subject = nil, predicate = nil, object = nil, options = {})
23
38
  super
@@ -146,5 +161,5 @@ class RDF::Query
146
161
  buffer.string
147
162
  end
148
163
  end
149
- end
150
- end
164
+ end # class Pattern
165
+ end; end # module RDF class Query
@@ -158,6 +158,13 @@ module RDF
158
158
  end
159
159
  end
160
160
 
161
+ ##
162
+ # @return [void]
163
+ # @since 0.2.2
164
+ def close
165
+ @input.close unless @input.closed?
166
+ end
167
+
161
168
  protected
162
169
 
163
170
  ##
@@ -234,6 +234,25 @@ module RDF
234
234
 
235
235
  protected
236
236
 
237
+ ##
238
+ # @private
239
+ # @see RDF::Queryable#query
240
+ def query_pattern(pattern, &block)
241
+ @data.dup.each do |c, ss|
242
+ next if pattern.has_context? && pattern.context != c
243
+ ss.dup.each do |s, ps|
244
+ next if pattern.has_subject? && pattern.subject != s
245
+ ps.dup.each do |p, os|
246
+ next if pattern.has_predicate? && pattern.predicate != p
247
+ os.dup.each do |o|
248
+ next if pattern.has_object? && pattern.object != o
249
+ block.call(RDF::Statement.new(s, p, o, :context => c))
250
+ end
251
+ end
252
+ end
253
+ end
254
+ end
255
+
237
256
  ##
238
257
  # @private
239
258
  # @see RDF::Mutable#insert
@@ -267,6 +286,7 @@ module RDF
267
286
  @data.clear
268
287
  end
269
288
 
289
+ protected :query_pattern
270
290
  protected :insert_statement
271
291
  protected :delete_statement
272
292
  protected :clear_statements
@@ -2,7 +2,7 @@ module RDF
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
@@ -6,6 +6,7 @@ module RDF
6
6
  #
7
7
  # The following vocabularies are pre-defined for your convenience:
8
8
  #
9
+ # * {RDF} - Resource Description Framework (RDF)
9
10
  # * {RDF::CC} - Creative Commons (CC)
10
11
  # * {RDF::CERT} - W3 Authentication Certificate (CERT)
11
12
  # * {RDF::DC} - Dublin Core (DC)
@@ -30,6 +31,7 @@ module RDF
30
31
  #
31
32
  # DC.title #=> RDF::URI("http://purl.org/dc/terms/title")
32
33
  # FOAF.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
34
+ # RDF.type #=> RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
33
35
  # RDFS.seeAlso #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
34
36
  # RSS.title #=> RDF::URI("http://purl.org/rss/1.0/title")
35
37
  # OWL.sameAs #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
@@ -146,6 +146,7 @@ module RDF
146
146
  ##
147
147
  # @param [IO, File] output
148
148
  # @param [Hash{Symbol => Object}] options
149
+ # @option options [Hash] :prefixes ({})
149
150
  # @yield [writer]
150
151
  # @yieldparam [RDF::Writer] writer
151
152
  def initialize(output = $stdout, options = {}, &block)
@@ -162,6 +163,38 @@ module RDF
162
163
  end
163
164
  end
164
165
 
166
+ ##
167
+ # Returns the options for this writer.
168
+ #
169
+ # @return [Hash{Symbol => Object}]
170
+ attr_reader :options
171
+
172
+ ##
173
+ # Returns the URI prefixes currently defined for this writer.
174
+ #
175
+ # @return [Hash{Symbol => RDF::URI}]
176
+ def prefixes
177
+ options[:prefixes] ||= {}
178
+ end
179
+
180
+ ##
181
+ # Defines a named URI prefix for this writer.
182
+ #
183
+ # @overload prefix(name, uri)
184
+ # @param [Symbol, #to_s] name
185
+ # @param [RDF::URI, #to_s] uri
186
+ #
187
+ # @overload prefix(name)
188
+ # @param [Symbol, #to_s] name
189
+ #
190
+ # @return [void]
191
+ def prefix(name, uri = nil)
192
+ name = name.respond_to?(:to_sym) ? name.to_sym : name.to_s.to_sym
193
+ uri.nil? ? prefixes[name] : prefixes[name] = RDF::URI(uri)
194
+ end
195
+
196
+ alias_method :prefix!, :prefix
197
+
165
198
  ##
166
199
  # Flushes the underlying output buffer.
167
200
  #
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
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-06-28 00:00:00 +02:00
18
+ date: 2010-07-06 00:00:00 +02:00
19
19
  default_executable: rdf
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -70,8 +70,8 @@ dependencies:
70
70
  segments:
71
71
  - 0
72
72
  - 2
73
- - 1
74
- version: 0.2.1
73
+ - 2
74
+ version: 0.2.2
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.
@@ -141,7 +141,6 @@ files:
141
141
  - lib/rdf/vocab/geo.rb
142
142
  - lib/rdf/vocab/http.rb
143
143
  - lib/rdf/vocab/owl.rb
144
- - lib/rdf/vocab/rdf.rb
145
144
  - lib/rdf/vocab/rdfs.rb
146
145
  - lib/rdf/vocab/rsa.rb
147
146
  - lib/rdf/vocab/rss.rb
@@ -1,15 +0,0 @@
1
- module RDF
2
- ##
3
- # Resource Description Framework (RDF) vocabulary.
4
- #
5
- # @see http://www.w3.org/RDF/
6
- class RDF < Vocabulary("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
7
- property :first
8
- property :object
9
- property :predicate
10
- property :rest
11
- property :subject
12
- property :type
13
- property :value
14
- end
15
- end