rdf 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -4,6 +4,8 @@ RDF.rb: RDF API for Ruby
4
4
  This is a pure-Ruby library for working with Resource Description Framework
5
5
  (RDF) data.
6
6
 
7
+ * <http://github.com/bendiken/rdf>
8
+
7
9
  ### About the Resource Description Framework (RDF)
8
10
 
9
11
  * <http://www.w3.org/RDF/>
@@ -144,6 +146,7 @@ See Also
144
146
  * [RDFize](http://rdfize.rubyforge.org/)
145
147
  * [RDFbus](http://rdfbus.rubyforge.org/)
146
148
  * [RDFcache](http://rdfcache.rubyforge.org/)
149
+ * [Trinity](http://trinity.datagraph.org/)
147
150
 
148
151
  Author
149
152
  ------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
data/lib/rdf.rb CHANGED
@@ -4,6 +4,7 @@ module RDF
4
4
  # RDF mixins
5
5
  autoload :Durable, 'rdf/mixin/durable'
6
6
  autoload :Enumerable, 'rdf/mixin/enumerable'
7
+ autoload :Inferable, 'rdf/mixin/inferable'
7
8
  autoload :Mutable, 'rdf/mixin/mutable'
8
9
  autoload :Queryable, 'rdf/mixin/queryable'
9
10
  autoload :Readable, 'rdf/mixin/readable'
@@ -21,7 +22,9 @@ module RDF
21
22
  # RDF serialization
22
23
  autoload :Format, 'rdf/format'
23
24
  autoload :Reader, 'rdf/reader'
25
+ autoload :ReaderError,'rdf/reader'
24
26
  autoload :Writer, 'rdf/writer'
27
+ autoload :WriterError,'rdf/writer'
25
28
 
26
29
  # RDF serialization formats
27
30
  autoload :NTriples, 'rdf/ntriples'
@@ -66,7 +69,7 @@ module RDF
66
69
  # @return [#to_s] property
67
70
  # @return [URI]
68
71
  def self.[](property)
69
- RDF::URI.parse([to_s, property.to_s].join)
72
+ RDF::URI.new([to_uri.to_s, property.to_s].join)
70
73
  end
71
74
 
72
75
  ##
@@ -83,13 +86,18 @@ module RDF
83
86
 
84
87
  ##
85
88
  # @return [URI]
86
- def self.to_uri
87
- RDF::URI.parse(to_s)
89
+ def self.to_rdf
90
+ to_uri
88
91
  end
89
92
 
90
93
  ##
91
- # @return [String]
92
- def self.to_s # FIXME
93
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
94
+ # @return [URI]
95
+ def self.to_uri
96
+ RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
97
+ end
98
+
99
+ class << self
100
+ # For compatibility with `RDF::Vocabulary.__name__`:
101
+ alias_method :__name__, :name
94
102
  end
95
103
  end
@@ -0,0 +1,6 @@
1
+ module RDF
2
+ ##
3
+ module Inferable
4
+ # TODO
5
+ end
6
+ end
@@ -29,7 +29,7 @@ module RDF
29
29
  if block_given?
30
30
  find_all { |statement| pattern === statement }.each(&block)
31
31
  else
32
- find_all { |statement| pattern === statement }
32
+ find_all { |statement| pattern === statement }.extend(RDF::Enumerable, RDF::Queryable)
33
33
  end
34
34
  else
35
35
  raise ArgumentError.new("expected RDF::Query or RDF::Pattern, got #{pattern.inspect}")
@@ -126,6 +126,15 @@ module RDF
126
126
  !!object
127
127
  end
128
128
 
129
+ ##
130
+ # Returns `true` if the subject or object of this statement is a blank
131
+ # node.
132
+ #
133
+ # @return [Boolean]
134
+ def has_blank_nodes?
135
+ (has_object? && object.node?) || (has_subject? && subject.node?)
136
+ end
137
+
129
138
  ##
130
139
  # @param [Statement] other
131
140
  # @return [Boolean]
data/lib/rdf/model/uri.rb CHANGED
@@ -4,9 +4,14 @@ module RDF
4
4
  ##
5
5
  # A Uniform Resource Identifier (URI).
6
6
  #
7
- # @example Creating a URI reference
7
+ # `RDF::URI` supports all the instance methods of `Addressable::URI`.
8
+ #
9
+ # @example Creating a URI reference (1)
8
10
  # uri = RDF::URI.new("http://rdf.rubyforge.org/")
9
11
  #
12
+ # @example Creating a URI reference (2)
13
+ # uri = RDF::URI.new(:scheme => 'http', :host => 'rdf.rubyforge.org', :path => '/')
14
+ #
10
15
  # @example Getting the string representation of a URI
11
16
  # uri.to_s #=> "http://rdf.rubyforge.org/"
12
17
  #
@@ -14,6 +19,11 @@ module RDF
14
19
  # @see http://addressable.rubyforge.org/
15
20
  class URI < Node
16
21
  ##
22
+ # Creates a new `RDF::URI` instance based on the given `uri` string.
23
+ #
24
+ # This is just an alias for {RDF::URI.new} for compatibity with
25
+ # {Addressable::URI].
26
+ #
17
27
  # @param [String] uri
18
28
  # @return [URI]
19
29
  def self.parse(uri)
@@ -21,10 +31,10 @@ module RDF
21
31
  end
22
32
 
23
33
  ##
24
- # @overload uri(uri)
34
+ # @overload URI.new(uri)
25
35
  # @param [URI, String, #to_s] uri
26
36
  #
27
- # @overload uri(options = {})
37
+ # @overload URI.new(options = {})
28
38
  # @param [Hash{Symbol => Object} options
29
39
  def initialize(uri_or_options)
30
40
  case uri_or_options
@@ -54,6 +64,82 @@ module RDF
54
64
  end
55
65
 
56
66
  ##
67
+ # Returns `true` if this URI's path component is equal to `/`.
68
+ #
69
+ # @return [Boolean]
70
+ def root?
71
+ self.path == '/' || self.path.empty?
72
+ end
73
+
74
+ ##
75
+ # Returns a copy of this URI with the path component set to `/`.
76
+ #
77
+ # @return [URI]
78
+ def root
79
+ if root?
80
+ self
81
+ else
82
+ uri = self.dup
83
+ uri.path = '/'
84
+ uri
85
+ end
86
+ end
87
+
88
+ ##
89
+ # Returns `true` if this URI's path component isn't equal to `/`.
90
+ #
91
+ # @return [Boolean]
92
+ def has_parent?
93
+ !root?
94
+ end
95
+
96
+ ##
97
+ # Returns a copy of this URI with the path component ascended to the
98
+ # parent directory, if any.
99
+ #
100
+ # @return [URI]
101
+ def parent
102
+ case
103
+ when root? then nil
104
+ else
105
+ require 'pathname' unless defined?(Pathname)
106
+ if path = Pathname.new(self.path).parent
107
+ uri = self.dup
108
+ uri.path = path.to_s
109
+ uri.path << '/' unless uri.root?
110
+ uri
111
+ end
112
+ end
113
+ end
114
+
115
+ ##
116
+ # Returns a qualified name (QName) for this URI, if possible.
117
+ #
118
+ # @return [Array(Symbol, Symbol)]
119
+ def qname
120
+ Vocabulary.each do |vocab|
121
+ if to_s.index(vocab.to_uri.to_s) == 0
122
+ vocab_name = vocab.__name__.split('::').last.downcase
123
+ local_name = to_s[vocab.to_uri.to_s.size..-1]
124
+ unless vocab_name.empty? || local_name.empty?
125
+ return [vocab_name.to_sym, local_name.to_sym]
126
+ end
127
+ end
128
+ end
129
+ nil # no QName found
130
+ end
131
+
132
+ ##
133
+ # Returns a duplicate copy of `self`.
134
+ #
135
+ # @return [URI]
136
+ def dup
137
+ self.class.new(@uri.dup)
138
+ end
139
+
140
+ ##
141
+ # Checks whether this URI is equal to `other`.
142
+ #
57
143
  # @param [URI] other
58
144
  # @return [Boolean]
59
145
  def eql?(other)
@@ -61,6 +147,8 @@ module RDF
61
147
  end
62
148
 
63
149
  ##
150
+ # Checks whether this URI is equal to `other`.
151
+ #
64
152
  # @param [Object] other
65
153
  # @return [Boolean]
66
154
  def ==(other)
@@ -73,29 +161,51 @@ module RDF
73
161
  end
74
162
 
75
163
  ##
164
+ # Returns `self`.
165
+ #
76
166
  # @return [URI]
77
167
  def to_uri
78
168
  self
79
169
  end
80
170
 
81
171
  ##
172
+ # Returns a string representation of this URI.
173
+ #
82
174
  # @return [String]
83
175
  def to_s
84
176
  @uri.to_s
85
177
  end
86
178
 
87
- protected
179
+ ##
180
+ # Returns a hash code for this URI.
181
+ #
182
+ # @return [Fixnum]
183
+ def hash
184
+ @uri.hash
185
+ end
88
186
 
89
- def respond_to?(symbol) #:nodoc:
90
- @uri.respond_to?(symbol) || super
91
- end
187
+ ##
188
+ # Returns `true` if this URI instance supports the `symbol` method.
189
+ #
190
+ # @param [Symbol, String, #to_s] symbol
191
+ # @return [Boolean]
192
+ def respond_to?(symbol)
193
+ @uri.respond_to?(symbol) || super
194
+ end
92
195
 
93
- def method_missing(symbol, *args, &block) #:nodoc:
94
- if @uri.respond_to?(symbol)
95
- @uri.send(symbol, *args, &block)
96
- else
97
- super
98
- end
196
+ ##
197
+ # @param [Symbol, String, #to_s] symbol
198
+ # @param [Array<Object>] args
199
+ # @yield
200
+ # @private
201
+ def method_missing(symbol, *args, &block)
202
+ if @uri.respond_to?(symbol)
203
+ @uri.send(symbol, *args, &block)
204
+ else
205
+ super
99
206
  end
207
+ end
208
+
209
+ protected :method_missing
100
210
  end
101
211
  end
@@ -29,9 +29,6 @@ module RDF
29
29
  class Value
30
30
  include Comparable
31
31
 
32
- # Prevent the instantiation of this class.
33
- private_class_method :new
34
-
35
32
  ##
36
33
  # Returns `true` if this value is a graph.
37
34
  #
@@ -125,8 +122,11 @@ module RDF
125
122
 
126
123
  private
127
124
 
128
- def self.inherited(child) #:nodoc:
129
- # Enable the instantiation of any subclasses.
125
+ # Prevent the instantiation of this class:
126
+ private_class_method :new
127
+
128
+ def self.inherited(child) # @private
129
+ # Enable the instantiation of any subclasses:
130
130
  child.send(:public_class_method, :new)
131
131
  super
132
132
  end
@@ -59,15 +59,17 @@ module RDF
59
59
  attr_reader :title
60
60
 
61
61
  ##
62
- # Loads an RDF file as a transient in-memory repository.
62
+ # Loads one or more RDF files into a new transient in-memory repository.
63
63
  #
64
- # @param [String] filename
64
+ # @param [String, Array<String>] filenames
65
65
  # @yield [repository]
66
66
  # @yieldparam [Repository]
67
67
  # @return [void]
68
- def self.load(filename, options = {}, &block)
68
+ def self.load(filenames, options = {}, &block)
69
69
  self.new(options) do |repository|
70
- repository.load(filename, options)
70
+ [filenames].flatten.each do |filename|
71
+ repository.load(filename, options)
72
+ end
71
73
 
72
74
  if block_given?
73
75
  case block.arity
data/lib/rdf/version.rb CHANGED
@@ -2,7 +2,7 @@ module RDF
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 8
5
+ TINY = 9
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/rdf/vocab.rb CHANGED
@@ -39,6 +39,28 @@ module RDF
39
39
  # @see http://www.w3.org/TR/curie/
40
40
  # @see http://en.wikipedia.org/wiki/QName
41
41
  class Vocabulary
42
+ extend ::Enumerable
43
+
44
+ ##
45
+ # Enumerates known RDF vocabulary classes.
46
+ #
47
+ # @yield [klass]
48
+ # @yieldparam [Class] klass
49
+ # @return [Enumerator]
50
+ def self.each(&block)
51
+ if self.equal?(Vocabulary)
52
+ # This is needed since all vocabulary classes are defined using
53
+ # Ruby's autoloading facility, meaning that `@@subclasses` will
54
+ # be empty until each subclass has been touched or require'd.
55
+ %w(cc dc doap exif foaf http owl rdfs rss sioc skos wot xhtml xsd).each do |prefix|
56
+ require "rdf/vocab/#{prefix}"
57
+ end
58
+ @@subclasses.each(&block)
59
+ else
60
+ # TODO: should enumerate vocabulary-specific defined properties.
61
+ end
62
+ end
63
+
42
64
  ##
43
65
  # Defines a vocabulary term called `property`.
44
66
  #
@@ -86,6 +108,12 @@ module RDF
86
108
  end
87
109
  end
88
110
 
111
+ class << self
112
+ # Preserve the class name so that it can be obtained even for
113
+ # vocabularies that define a `name` property:
114
+ alias_method :__name__, :name
115
+ end
116
+
89
117
  # Undefine all superfluous instance methods:
90
118
  undef_method *(instance_methods - %w(__id__ __send__ __class__ __eval__ instance_eval inspect class))
91
119
 
@@ -139,11 +167,13 @@ module RDF
139
167
  end
140
168
 
141
169
  def self.inherited(subclass) # @private
170
+ @@subclasses << subclass
142
171
  unless @@uri.nil?
143
172
  subclass.send(:private_class_method, :new)
144
173
  @@uris[subclass] = @@uri
145
174
  @@uri = nil
146
175
  end
176
+ super
147
177
  end
148
178
 
149
179
  def self.method_missing(property, *args, &block)
@@ -164,8 +194,9 @@ module RDF
164
194
 
165
195
  private
166
196
 
167
- @@uris = {} # @private
168
- @@uri = nil # @private
197
+ @@subclasses = [::RDF] # @private
198
+ @@uris = {} # @private
199
+ @@uri = nil # @private
169
200
 
170
201
  end
171
202
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-10 00:00:00 +01:00
13
+ date: 2010-02-01 00:00:00 +01:00
14
14
  default_executable: rdf
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ files:
63
63
  - lib/rdf/format.rb
64
64
  - lib/rdf/mixin/durable.rb
65
65
  - lib/rdf/mixin/enumerable.rb
66
+ - lib/rdf/mixin/inferable.rb
66
67
  - lib/rdf/mixin/mutable.rb
67
68
  - lib/rdf/mixin/queryable.rb
68
69
  - lib/rdf/mixin/readable.rb