rdf 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -7,6 +7,18 @@ This is a pure-Ruby library for working with [Resource Description Framework
7
7
  * <http://github.com/bendiken/rdf>
8
8
  * <http://blog.datagraph.org/2010/03/rdf-for-ruby>
9
9
 
10
+ Features
11
+ --------
12
+
13
+ * 100% pure Ruby with minimal dependencies and no bloat whatsoever.
14
+ * 100% free and unencumbered [public domain](http://unlicense.org/) software.
15
+ * Provides a clean, well-designed RDF object model and related APIs.
16
+ * Supports parsing and serializing N-Triples out of the box, with more
17
+ serialization format support available through add-on plugins.
18
+ * Plays nice with others: entirely contained in the `RDF` module, and does
19
+ not modify any of Ruby's core classes or standard library.
20
+ * Compatible with Ruby 1.8.x, Ruby 1.9.x, and JRuby (tested with JRuby 1.4).
21
+
10
22
  Examples
11
23
  --------
12
24
 
@@ -26,6 +38,7 @@ Examples
26
38
 
27
39
  DC.title #=> RDF::URI("http://purl.org/dc/terms/title")
28
40
  FOAF.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
41
+ RDF.type #=> RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
29
42
  RDFS.seeAlso #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
30
43
  RSS.title #=> RDF::URI("http://purl.org/rss/1.0/title")
31
44
  OWL.sameAs #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
@@ -49,17 +62,17 @@ Examples
49
62
  Documentation
50
63
  -------------
51
64
 
52
- * <http://rdf.rubyforge.org/>
65
+ <http://rdf.rubyforge.org/>
53
66
 
54
67
  ### RDF Object Model
55
68
 
56
- * {RDF::Graph}
57
- * {RDF::Literal}
58
- * {RDF::Node}
59
- * {RDF::Resource}
60
- * {RDF::Statement}
61
- * {RDF::URI}
62
69
  * {RDF::Value}
70
+ * {RDF::Literal}
71
+ * {RDF::Resource}
72
+ * {RDF::Node}
73
+ * {RDF::URI}
74
+ * {RDF::Graph}
75
+ * {RDF::Statement}
63
76
 
64
77
  ### RDF Serialization
65
78
 
@@ -70,13 +83,20 @@ Documentation
70
83
  ### RDF Serialization Formats
71
84
 
72
85
  * {RDF::NTriples}
73
- * [RDF::JSON](http://rdf.rubyforge.org/json/) (plugin)
74
- * [RDF::Trix](http://rdf.rubyforge.org/trix/) (plugin)
86
+ * [`RDF::JSON`](http://rdf.rubyforge.org/json/) (plugin)
87
+ * [`RDF::Trix`](http://rdf.rubyforge.org/trix/) (plugin)
88
+ * [`RDF::Raptor::RDFXML`](http://rdf.rubyforge.org/raptor/) (plugin)
89
+ * [`RDF::Raptor::Turtle`](http://rdf.rubyforge.org/raptor/) (plugin)
75
90
 
76
91
  ### RDF Storage
77
92
 
78
93
  * {RDF::Repository}
79
- * [RDF::Sesame](http://rdf.rubyforge.org/sesame/) (plugin)
94
+ * {RDF::Enumerable}
95
+ * {RDF::Durable}
96
+ * {RDF::Mutable}
97
+ * {RDF::Queryable}
98
+ * [`RDF::DataObjects`](http://rdf.rubyforge.org/do/) (plugin)
99
+ * [`RDF::Sesame`](http://rdf.rubyforge.org/sesame/) (plugin)
80
100
 
81
101
  ### RDF Querying
82
102
 
@@ -140,11 +160,14 @@ Resources
140
160
  See Also
141
161
  --------
142
162
 
143
- * [DataMapper RDF.rb Adapter](http://dm-rdf.rubyforge.org/)
163
+ * [RDF::BERT](http://rdf.rubyforge.org/bert/)
164
+ * [RDF::Isomorphic](http://rdf.rubyforge.org/isomorphic/)
165
+ * [RDF::Spec](http://rdf.rubyforge.org/spec/)
144
166
  * [RDFS.rb](http://rdfs.rubyforge.org/)
145
167
  * [RDFize](http://rdfize.rubyforge.org/)
146
168
  * [RDFbus](http://rdfbus.rubyforge.org/)
147
169
  * [RDFcache](http://rdfcache.rubyforge.org/)
170
+ * [RDFgrid](http://rdfgrid.rubyforge.org/)
148
171
  * [Trinity](http://trinity.datagraph.org/)
149
172
 
150
173
  Authors
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -36,7 +36,7 @@ module RDF
36
36
  ##
37
37
  # @param [#to_s] id
38
38
  def initialize(id = nil)
39
- @id = (id || object_id).to_s
39
+ @id = (id || "g#{object_id}").to_s
40
40
  end
41
41
 
42
42
  ##
data/lib/rdf/ntriples.rb CHANGED
@@ -41,5 +41,25 @@ module RDF
41
41
  require 'rdf/ntriples/format'
42
42
  autoload :Reader, 'rdf/ntriples/reader'
43
43
  autoload :Writer, 'rdf/ntriples/writer'
44
+
45
+ ##
46
+ # Reconstructs an RDF value from its serialized N-Triples
47
+ # representation.
48
+ #
49
+ # @param [String] data
50
+ # @return [RDF::Value]
51
+ def self.unserialize(data)
52
+ Reader.unserialize(data)
53
+ end
54
+
55
+ ##
56
+ # Returns the serialized N-Triples representation of the given RDF
57
+ # value.
58
+ #
59
+ # @param [RDF::Value] value
60
+ # @return [String]
61
+ def self.serialize(value)
62
+ Writer.serialize(value)
63
+ end
44
64
  end
45
65
  end
@@ -35,7 +35,10 @@ module RDF::NTriples
35
35
  # @param [String] data
36
36
  # @return [RDF::Value]
37
37
  def self.unserialize(data)
38
- self.new(data).read_value
38
+ case data
39
+ when nil then nil
40
+ else self.new(data).read_value
41
+ end
39
42
  end
40
43
 
41
44
  ##
@@ -36,6 +36,7 @@ module RDF::NTriples
36
36
  def self.serialize(value)
37
37
  writer = self.new
38
38
  case value
39
+ when nil then nil
39
40
  when RDF::Statement
40
41
  writer.format_statement(value) + "\n"
41
42
  else
data/lib/rdf/reader.rb CHANGED
@@ -104,12 +104,12 @@ module RDF
104
104
  # @yieldparam [Reader]
105
105
  # @raise [FormatError] if no reader available for the specified format
106
106
  def self.open(filename, options = {}, &block)
107
- Kernel.open(filename, 'rb') do |file|
108
- if reader = self.for(options[:format] || filename)
107
+ if reader = self.for(options[:format] || filename)
108
+ Kernel.open(filename, 'rb') do |file|
109
109
  reader.new(file, options, &block)
110
- else
111
- raise FormatError.new("unknown RDF format: #{options[:format] || filename}")
112
110
  end
111
+ else
112
+ raise FormatError.new("unknown RDF format: #{options[:format] || filename}")
113
113
  end
114
114
  end
115
115
 
data/lib/rdf/spec.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'rdf'
2
+
3
+ module RDF
4
+ ##
5
+ # **`RDF::Spec`** provides RSpec extensions for RDF.rb.
6
+ #
7
+ # @example Requiring the `RDF::Spec` module
8
+ # require 'rdf/spec'
9
+ #
10
+ # @example Including the matchers in `spec/spec_helper.rb`
11
+ # require 'rdf/spec'
12
+ #
13
+ # Spec::Runner.configure do |config|
14
+ # config.include(RDF::Spec::Matchers)
15
+ # end
16
+ #
17
+ # @example Using the shared examples for `RDF::Enumerable`
18
+ # require 'rdf/spec/enumerable'
19
+ #
20
+ # describe RDF::Enumerable do
21
+ # before :each do
22
+ # @statements = RDF::NTriples::Reader.new(File.open("etc/doap.nt")).to_a
23
+ # @enumerable = @statements.dup.extend(RDF::Enumerable)
24
+ # end
25
+ #
26
+ # it_should_behave_like RDF_Enumerable
27
+ # end
28
+ #
29
+ # @example Using the shared examples for `RDF::Repository`
30
+ # require 'rdf/spec/repository'
31
+ #
32
+ # describe RDF::Repository do
33
+ # before :each do
34
+ # @repository = RDF::Repository.new
35
+ # end
36
+ #
37
+ # it_should_behave_like RDF_Repository
38
+ # end
39
+ #
40
+ # @see http://rdf.rubyforge.org/
41
+ # @see http://rspec.info/
42
+ #
43
+ # @author [Arto Bendiken](http://ar.to/)
44
+ # @author [Ben Lavender](http://bhuga.net/)
45
+ module Spec
46
+ autoload :Matchers, 'rdf/spec/matchers'
47
+ autoload :VERSION, 'rdf/spec/version'
48
+ end # module Spec
49
+ end # module RDF
data/lib/rdf/version.rb CHANGED
@@ -2,7 +2,7 @@ module RDF
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/rdf/writer.rb CHANGED
@@ -84,7 +84,7 @@ module RDF
84
84
  def self.format(klass = nil)
85
85
  if klass.nil?
86
86
  Format.each do |format|
87
- if format.reader == self
87
+ if format.writer == self
88
88
  return format
89
89
  end
90
90
  end
@@ -129,6 +129,11 @@ module RDF
129
129
  end
130
130
  end
131
131
 
132
+ ##
133
+ # @param [IO, File] output
134
+ # @param [Hash{Symbol => Object}] options
135
+ # @yield [writer]
136
+ # @yieldparam [RDF::Writer] writer
132
137
  def initialize(output = $stdout, options = {}, &block)
133
138
  @output, @options = output, options
134
139
  @nodes, @node_id = {}, 0
@@ -141,14 +146,17 @@ module RDF
141
146
  end
142
147
 
143
148
  ##
149
+ # @return [void]
144
150
  # @abstract
145
151
  def write_prologue() end
146
152
 
147
153
  ##
154
+ # @return [void]
148
155
  # @abstract
149
156
  def write_epilogue() end
150
157
 
151
158
  ##
159
+ # @return [void]
152
160
  # @abstract
153
161
  def write_comment(text) end
154
162
 
@@ -174,10 +182,13 @@ module RDF
174
182
 
175
183
  ##
176
184
  # @param [Graph] graph
185
+ # @return [void]
177
186
  def write_graph(graph)
178
187
  write_triples(*graph.triples)
179
188
  end
180
189
 
190
+ ##
191
+ # @return [void]
181
192
  def write_resource(subject) # FIXME
182
193
  edge_nodes = []
183
194
  subject.each do |predicate, objects|
@@ -191,18 +202,21 @@ module RDF
191
202
 
192
203
  ##
193
204
  # @param [Array<Statement>] statements
205
+ # @return [void]
194
206
  def write_statements(*statements)
195
207
  statements.flatten.each { |stmt| write_statement(stmt) }
196
208
  end
197
209
 
198
210
  ##
199
211
  # @param [Statement] statement
212
+ # @return [void]
200
213
  def write_statement(statement)
201
214
  write_triple(*statement.to_a)
202
215
  end
203
216
 
204
217
  ##
205
218
  # @param [Array<Array(Value)>] triples
219
+ # @return [void]
206
220
  def write_triples(*triples)
207
221
  triples.each { |triple| write_triple(*triple) }
208
222
  end
@@ -211,6 +225,7 @@ module RDF
211
225
  # @param [Resource] subject
212
226
  # @param [URI] predicate
213
227
  # @param [Value] object
228
+ # @return [void]
214
229
  # @raise [NotImplementedError] unless implemented in subclass
215
230
  # @abstract
216
231
  def write_triple(subject, predicate, object)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
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-03-30 00:00:00 +02:00
18
+ date: 2010-04-03 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
- - 0
32
- version: 0.1.0
31
+ - 4
32
+ version: 0.1.4
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -117,6 +117,7 @@ files:
117
117
  - lib/rdf/query.rb
118
118
  - lib/rdf/reader.rb
119
119
  - lib/rdf/repository.rb
120
+ - lib/rdf/spec.rb
120
121
  - lib/rdf/version.rb
121
122
  - lib/rdf/vocab/cc.rb
122
123
  - lib/rdf/vocab/dc.rb