rdf 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ * Hellekin O. Wolf <hellekin@cepheide.org>
2
+ * John Fieber <jrf@ursamaris.org>
3
+ * Pius Uzamere <pius@alum.mit.edu>
data/README CHANGED
@@ -21,20 +21,34 @@ Features
21
21
  not modify any of Ruby's core classes or standard library.
22
22
  * Based entirely on Ruby's autoloading, meaning that you can generally make
23
23
  use of any one part of the library without needing to load up the rest.
24
- * Compatible with Ruby 1.8.x, Ruby 1.9.x, and JRuby (tested with JRuby 1.4).
24
+ * Compatible with Ruby 1.8.7+, Ruby 1.9.x, and JRuby 1.4/1.5.
25
+ * Compatible with older Ruby versions with the help of the [Backports][] gem.
25
26
 
26
27
  Examples
27
28
  --------
28
29
 
30
+ require 'rubygems'
29
31
  require 'rdf'
30
32
 
31
- ### Creating an RDF statement
33
+ ### Writing RDF data using the N-Triples format
32
34
 
33
- s = RDF::URI("http://rubygems.org/gems/rdf")
34
- p = RDF::DC.creator
35
- o = RDF::URI("http://ar.to/#self")
35
+ require 'rdf/ntriples'
36
36
 
37
- stmt = RDF::Statement(s, p, o)
37
+ RDF::Writer.open("hello.nt") do |writer|
38
+ writer << RDF::Graph.new do |graph|
39
+ graph << [:hello, RDF::DC.title, "Hello, world!"]
40
+ end
41
+ end
42
+
43
+ ### Reading RDF data in the N-Triples format
44
+
45
+ require 'rdf/ntriples'
46
+
47
+ RDF::Reader.open("http://rdf.rubyforge.org/doap.nt") do |reader|
48
+ reader.each_statement do |statement|
49
+ puts statement.inspect
50
+ end
51
+ end
38
52
 
39
53
  ### Using pre-defined RDF vocabularies
40
54
 
@@ -55,14 +69,6 @@ Examples
55
69
  foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
56
70
  foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
57
71
 
58
- ### Reading N-Triples data
59
-
60
- RDF::Reader.open("spec/data/test.nt") do |reader|
61
- reader.each_statement do |statement|
62
- puts statement.inspect
63
- end
64
- end
65
-
66
72
  Documentation
67
73
  -------------
68
74
 
@@ -70,6 +76,8 @@ Documentation
70
76
 
71
77
  ### RDF Object Model
72
78
 
79
+ <http://blog.datagraph.org/2010/03/rdf-for-ruby>
80
+
73
81
  * {RDF::Value}
74
82
  * {RDF::Literal}
75
83
  * {RDF::Resource}
@@ -80,6 +88,8 @@ Documentation
80
88
 
81
89
  ### RDF Serialization
82
90
 
91
+ <http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby>
92
+
83
93
  * {RDF::Format}
84
94
  * {RDF::Reader}
85
95
  * {RDF::Writer}
@@ -94,11 +104,14 @@ Documentation
94
104
 
95
105
  ### RDF Storage
96
106
 
107
+ <http://blog.datagraph.org/2010/04/rdf-repository-howto>
108
+
97
109
  * {RDF::Repository}
110
+ * {RDF::Countable}
98
111
  * {RDF::Enumerable}
99
- * {RDF::Durable}
100
- * {RDF::Mutable}
101
112
  * {RDF::Queryable}
113
+ * {RDF::Mutable}
114
+ * {RDF::Durable}
102
115
  * [`RDF::DataObjects`](http://rdf.rubyforge.org/do/) (plugin)
103
116
  * [`RDF::Sesame`](http://rdf.rubyforge.org/sesame/) (plugin)
104
117
 
@@ -112,13 +125,17 @@ Documentation
112
125
  ### RDF Vocabularies
113
126
 
114
127
  * {RDF::CC} - Creative Commons (CC)
128
+ * {RDF::CERT} - W3 Authentication Certificate (CERT)
115
129
  * {RDF::DC} - Dublin Core (DC)
130
+ * {RDF::DC11} - Dublin Core 1.1 (DC11) _deprecated_
116
131
  * {RDF::DOAP} - Description of a Project (DOAP)
117
132
  * {RDF::EXIF} - Exchangeable Image File Format (EXIF)
118
133
  * {RDF::FOAF} - Friend of a Friend (FOAF)
134
+ * {RDF::GEO} - WGS84 Geo Positioning (GEO)
119
135
  * {RDF::HTTP} - Hypertext Transfer Protocol (HTTP)
120
136
  * {RDF::OWL} - Web Ontology Language (OWL)
121
137
  * {RDF::RDFS} - RDF Schema (RDFS)
138
+ * {RDF::RSA} - W3 RSA Keys (RSA)
122
139
  * {RDF::RSS} - RDF Site Summary (RSS)
123
140
  * {RDF::SIOC} - Semantically-Interlinked Online Communities (SIOC)
124
141
  * {RDF::SKOS} - Simple Knowledge Organization System (SKOS)
@@ -129,15 +146,17 @@ Documentation
129
146
  Dependencies
130
147
  ------------
131
148
 
132
- * [Addressable](http://addressable.rubyforge.org/) (>= 2.1.1)
149
+ * [Ruby](http://ruby-lang.org/) (>= 1.8.7) or (>= 1.8.1 with [Backports][])
150
+ * [Addressable](http://rubygems.org/gems/addressable) (>= 2.1.2)
133
151
 
134
152
  Installation
135
153
  ------------
136
154
 
137
- The recommended installation method is via RubyGems. To install the latest
138
- official release from [RubyGems](http://rubygems.org/), do:
155
+ The recommended installation method is via [RubyGems](http://rubygems.org/).
156
+ To install the latest official release of RDF.rb, do:
139
157
 
140
- % [sudo] gem install rdf
158
+ % [sudo] gem install rdf # Ruby 1.8.7+ or 1.9.x
159
+ % [sudo] gem install backports rdf # Ruby 1.8.1+
141
160
 
142
161
  Download
143
162
  --------
@@ -161,29 +180,44 @@ Resources
161
180
  * <http://raa.ruby-lang.org/project/rdf/>
162
181
  * <http://www.ohloh.net/p/rdf>
163
182
 
164
- See Also
165
- --------
166
-
167
- * [RDF::BERT](http://rdf.rubyforge.org/bert/)
168
- * [RDF::Isomorphic](http://rdf.rubyforge.org/isomorphic/)
169
- * [RDF::Spec](http://rdf.rubyforge.org/spec/)
170
- * [RDFS.rb](http://rdfs.rubyforge.org/)
171
- * [RDFize](http://rdfize.rubyforge.org/)
172
- * [RDFbus](http://rdfbus.rubyforge.org/)
173
- * [RDFcache](http://rdfcache.rubyforge.org/)
174
- * [RDFgrid](http://rdfgrid.rubyforge.org/)
175
- * [Trinity](http://trinity.datagraph.org/)
176
-
177
183
  Authors
178
184
  -------
179
185
 
180
186
  * [Arto Bendiken](mailto:arto.bendiken@gmail.com) - <http://ar.to/>
181
187
  * [Ben Lavender](mailto:blavender@gmail.com) - <http://bhuga.net/>
182
188
 
189
+ Contributors
190
+ ------------
191
+
192
+ * [Hellekin O. Wolf](mailto:hellekin@cepheide.org) - <http://hellekin.cepheide.org/>
193
+ * [John Fieber](mailto:jrf@ursamaris.org) - <http://github.com/jfieber>
194
+ * [Pius Uzamere](mailto:pius@alum.mit.edu) - <http://pius.me/>
195
+
196
+ Contributing
197
+ ------------
198
+
199
+ * Do your best to adhere to the existing coding conventions and idioms.
200
+ * Don't use hard tabs, and don't leave trailing whitespace on any line.
201
+ * Do document every method you add using [YARD][] annotations. Read the
202
+ [tutorial][YARD-GS] or just look at the existing code for examples.
203
+ * Don't touch the `.gemspec` or `VERSION` files. If you need to change them,
204
+ do so on your private branch only.
205
+ * Do feel free to add yourself to the `CONTRIBUTORS` file and the
206
+ corresponding list in the the `README`. Alphabetical order applies.
207
+ * Don't touch the `AUTHORS` file. If your contributions are significant
208
+ enough, be assured we will eventually add you in there.
209
+ * Do note that in order for us to merge any non-trivial changes (as a rule
210
+ of thumb, additions larger than about 15 lines of code), we need an
211
+ explicit [public domain dedication][PDD] on record from you.
212
+
183
213
  License
184
214
  -------
185
215
 
186
216
  RDF.rb is free and unencumbered public domain software. For more
187
217
  information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
188
218
 
189
- [RDF]: http://www.w3.org/RDF/
219
+ [RDF]: http://www.w3.org/RDF/
220
+ [YARD]: http://yardoc.org/
221
+ [YARD-GS]: http://yardoc.org/docs/yard/file:docs/GettingStarted.md
222
+ [PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
223
+ [Backports]: http://rubygems.org/gems/backports
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.2.0
@@ -3,23 +3,30 @@
3
3
  <http://ar.to/#self> <http://xmlns.com/foaf/0.1/homepage> <http://ar.to/> .
4
4
  <http://ar.to/#self> <http://xmlns.com/foaf/0.1/made> <http://rubygems.org/gems/rdf> .
5
5
  <http://ar.to/#self> <http://xmlns.com/foaf/0.1/mbox> <mailto:arto.bendiken@gmail.com> .
6
+ <http://ar.to/#self> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "a033f652c84a4d73b8c26d318c2395699dd2bdfb" .
7
+ <http://ar.to/#self> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "d0737cceb55eb7d740578d2db1bc0727e3ed49ce" .
6
8
  <http://ar.to/#self> <http://xmlns.com/foaf/0.1/name> "Arto Bendiken" .
7
9
  <http://bhuga.net/#ben> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
8
10
  <http://bhuga.net/#ben> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <http://datagraph.org/bhuga/foaf> .
9
11
  <http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/homepage> <http://bhuga.net/> .
10
12
  <http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/mbox> <mailto:blavender@gmail.com> .
13
+ <http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "dbf45f4ffbd27b67aa84f02a6a31c144727d10af" .
11
14
  <http://bhuga.net/#ben> <http://xmlns.com/foaf/0.1/name> "Ben Lavender" .
12
15
  <http://rubygems.org/gems/rdf> <http://purl.org/dc/terms/creator> <http://ar.to/#self> .
13
16
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://ar.to/> .
14
17
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://blog.datagraph.org/> .
15
18
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/bendiken/rdf/issues> .
16
19
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#category> <http://dbpedia.org/resource/Resource_Description_Framework> .
20
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#category> <http://dbpedia.org/resource/Ruby_(programming_language)> .
17
21
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#created> "2007-10-23" .
18
22
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#description> "RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data."@en .
19
23
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#developer> <http://ar.to/#self> .
20
24
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#developer> <http://bhuga.net/#ben> .
21
25
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#documenter> <http://ar.to/#self> .
22
26
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://rubyforge.org/projects/rdf/> .
27
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid1 .
28
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid2 .
29
+ <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#helper> _:genid3 .
23
30
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#homepage> <http://rdf.rubyforge.org/> .
24
31
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#license> <http://creativecommons.org/licenses/publicdomain/> .
25
32
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#maintainer> <http://ar.to/#self> .
@@ -29,3 +36,12 @@
29
36
  <http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#vendor> <http://datagraph.org/> .
30
37
  <http://rubygems.org/gems/rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://usefulinc.com/ns/doap#Project> .
31
38
  <http://rubygems.org/gems/rdf> <http://xmlns.com/foaf/0.1/maker> <http://ar.to/#self> .
39
+ _: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
+ _: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
+ _: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" .
data/lib/rdf.rb CHANGED
@@ -1,5 +1,20 @@
1
- require 'enumerator' # @since Ruby 1.8.1
1
+ require 'enumerator'
2
2
  require 'open-uri'
3
+
4
+ if RUBY_VERSION < '1.8.7'
5
+ # @see http://rubygems.org/gems/backports
6
+ begin
7
+ require 'backports/1.8.7'
8
+ rescue LoadError
9
+ begin
10
+ require 'rubygems'
11
+ require 'backports/1.8.7'
12
+ rescue LoadError
13
+ abort "RDF.rb requires Ruby 1.8.7 or the Backports gem (hint: `gem install backports')."
14
+ end
15
+ end
16
+ end
17
+
3
18
  require 'rdf/version'
4
19
 
5
20
  module RDF
@@ -7,6 +22,7 @@ module RDF
7
22
  Enumerator = defined?(::Enumerator) ? ::Enumerator : ::Enumerable::Enumerator
8
23
 
9
24
  # RDF mixins
25
+ autoload :Countable, 'rdf/mixin/countable'
10
26
  autoload :Durable, 'rdf/mixin/durable'
11
27
  autoload :Enumerable, 'rdf/mixin/enumerable'
12
28
  autoload :Inferable, 'rdf/mixin/inferable'
@@ -43,21 +59,11 @@ module RDF
43
59
 
44
60
  # RDF vocabularies
45
61
  autoload :Vocabulary, 'rdf/vocab'
46
- autoload :CC, 'rdf/vocab/cc'
47
- autoload :DC, 'rdf/vocab/dc'
48
- autoload :DC11, 'rdf/vocab/dc11'
49
- autoload :DOAP, 'rdf/vocab/doap'
50
- autoload :EXIF, 'rdf/vocab/exif'
51
- autoload :FOAF, 'rdf/vocab/foaf'
52
- autoload :HTTP, 'rdf/vocab/http'
53
- autoload :OWL, 'rdf/vocab/owl'
54
- autoload :RDFS, 'rdf/vocab/rdfs'
55
- autoload :RSS, 'rdf/vocab/rss'
56
- autoload :SIOC, 'rdf/vocab/sioc'
57
- autoload :SKOS, 'rdf/vocab/skos'
58
- autoload :WOT, 'rdf/vocab/wot'
59
- autoload :XHTML, 'rdf/vocab/xhtml'
60
- autoload :XSD, 'rdf/vocab/xsd'
62
+ VOCABS = Dir.glob(File.join(File.dirname(__FILE__), 'rdf', 'vocab', '*.rb')).map { |f| File.basename(f)[0...-(File.extname(f).size)].to_sym } rescue []
63
+ VOCABS.each { |v| autoload v.to_s.upcase.to_sym, "rdf/vocab/#{v}" unless v == :rdf }
64
+
65
+ # Utilities
66
+ autoload :Util, 'rdf/util'
61
67
 
62
68
  ##
63
69
  # Alias for `RDF::Resource.new`.
@@ -132,7 +138,7 @@ module RDF
132
138
  # @return [#to_s] property
133
139
  # @return [URI]
134
140
  def self.[](property)
135
- RDF::URI.new([to_uri.to_s, property.to_s].join)
141
+ RDF::URI.intern([to_uri.to_s, property.to_s].join)
136
142
  end
137
143
 
138
144
  ##
@@ -156,7 +162,7 @@ module RDF
156
162
  ##
157
163
  # @return [URI]
158
164
  def self.to_uri
159
- RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
165
+ RDF::URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
160
166
  end
161
167
 
162
168
  class << self
@@ -109,7 +109,7 @@ module RDF
109
109
  else
110
110
  format = format.to_s.downcase
111
111
  @@subclasses.each do |klass|
112
- if klass.name.to_s.split('::').map { |x| x.downcase }.include?(format)
112
+ if klass.name.to_s.split('::').map(&:downcase).include?(format)
113
113
  return klass
114
114
  end
115
115
  end
@@ -225,6 +225,51 @@ module RDF
225
225
  alias_method :writer_class, :writer
226
226
  end
227
227
 
228
+ ##
229
+ # Retrieves or defines MIME content types for this RDF serialization format.
230
+ #
231
+ # @overload content_type(type, options)
232
+ # Retrieves or defines the MIME content type for this RDF serialization format.
233
+ #
234
+ # Optionally also defines alias MIME content types for this RDF serialization format.
235
+ #
236
+ # Optionally also defines a file extension, or a list of file
237
+ # extensions, that should be mapped to the given MIME type and handled
238
+ # by this class.
239
+ #
240
+ # @param [String] type
241
+ # @param [Hash{Symbol => Object}] options
242
+ # @option options [String] :alias (nil)
243
+ # @option options [Array<String>] :aliases (nil)
244
+ # @option options [Symbol] :extension (nil)
245
+ # @option options [Array<Symbol>] :extensions (nil)
246
+ # @return [void]
247
+ #
248
+ # @overload content_type
249
+ # Retrieves the MIME content types for this RDF serialization format.
250
+ #
251
+ # The return is an array where the first element is the cannonical
252
+ # MIME type for the format and following elements are alias MIME types.
253
+ #
254
+ # @return [Array<String>]
255
+ def self.content_type(type = nil, options = {})
256
+ if type.nil?
257
+ [@@content_type[self], @@content_types.map {
258
+ |ct, cl| (cl.include?(self) && ct != @@content_type[self]) ? ct : nil }].flatten.compact
259
+ else
260
+ @@content_type[self] = type
261
+ (@@content_types[type] ||= []) << self
262
+
263
+ if extensions = (options[:extension] || options[:extensions])
264
+ extensions = [extensions].flatten.map(&:to_sym)
265
+ extensions.each { |ext| @@file_extensions[ext] = type }
266
+ end
267
+ if aliases = (options[:alias] || options[:aliases])
268
+ aliases = [aliases].flatten.each { |a| (@@content_types[a] ||= []) << self }
269
+ end
270
+ end
271
+ end
272
+
228
273
  protected
229
274
 
230
275
  ##
@@ -240,27 +285,6 @@ module RDF
240
285
  (@@requires[self] ||= []) << library.to_s
241
286
  end
242
287
 
243
- ##
244
- # Defines MIME content types for this RDF serialization format.
245
- #
246
- # Optionally also defines a file extension, or a list of file
247
- # extensions, that should be mapped to the given MIME type and handled
248
- # by this class.
249
- #
250
- # @param [String] type
251
- # @param [Hash{Symbol => Object}] options
252
- # @option options [Symbol] :extension (nil)
253
- # @option options [Array<Symbol>] :extensions (nil)
254
- # @return [void]
255
- def self.content_type(type, options = {})
256
- (@@content_types[type] ||= []) << self
257
-
258
- if extensions = (options[:extension] || options[:extensions])
259
- extensions = [extensions].flatten.map { |ext| ext.to_sym }
260
- extensions.each { |ext| @@file_extensions[ext] = type }
261
- end
262
- end
263
-
264
288
  ##
265
289
  # Defines the content encoding for this RDF serialization format.
266
290
  #
@@ -277,6 +301,7 @@ module RDF
277
301
  @@subclasses = [] # @private
278
302
  @@requires = {} # @private
279
303
  @@file_extensions = {} # @private
304
+ @@content_type = {} # @private
280
305
  @@content_types = {} # @private
281
306
  @@content_encoding = {} # @private
282
307
  @@readers = {} # @private
@@ -0,0 +1,42 @@
1
+ module RDF
2
+ ##
3
+ # @since 0.2.0
4
+ module Countable
5
+ extend RDF::Util::Aliasing::LateBound
6
+
7
+ ##
8
+ # Returns `true` if `self` contains no RDF statements.
9
+ #
10
+ # @return [Boolean]
11
+ def empty?
12
+ empty = true
13
+ each { empty = false; break }
14
+ empty
15
+ end
16
+
17
+ ##
18
+ # Returns the number of RDF statements in `self`.
19
+ #
20
+ # @return [Integer]
21
+ def count
22
+ count = 0
23
+ each { count += 1 }
24
+ count
25
+ end
26
+
27
+ alias_method :size, :count
28
+ alias_method :length, :count # @deprecated
29
+
30
+ ##
31
+ # @private
32
+ # @param [Symbol, #to_sym] method
33
+ # @return [Enumerator]
34
+ # @see Object#enum_for
35
+ def enum_for(method = :each, *args)
36
+ # Ensure that enumerators support the `#empty?` and `#count` methods:
37
+ super.extend(RDF::Countable)
38
+ end
39
+
40
+ alias_method :to_enum, :enum_for
41
+ end
42
+ end