rdf 1.0.10.2 → 1.1.0.p0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +8 -8
  2. data/CREDITS +0 -2
  3. data/README +67 -20
  4. data/VERSION +1 -1
  5. data/etc/doap.nt +75 -75
  6. data/lib/rdf.rb +15 -64
  7. data/lib/rdf/format.rb +11 -20
  8. data/lib/rdf/mixin/countable.rb +4 -11
  9. data/lib/rdf/mixin/enumerable.rb +4 -8
  10. data/lib/rdf/mixin/mutable.rb +1 -4
  11. data/lib/rdf/mixin/queryable.rb +13 -60
  12. data/lib/rdf/model/graph.rb +46 -22
  13. data/lib/rdf/model/list.rb +27 -102
  14. data/lib/rdf/model/literal.rb +48 -100
  15. data/lib/rdf/model/literal/date.rb +1 -1
  16. data/lib/rdf/model/literal/datetime.rb +1 -35
  17. data/lib/rdf/model/literal/decimal.rb +0 -30
  18. data/lib/rdf/model/literal/double.rb +6 -14
  19. data/lib/rdf/model/literal/integer.rb +3 -11
  20. data/lib/rdf/model/literal/numeric.rb +0 -40
  21. data/lib/rdf/model/literal/time.rb +4 -3
  22. data/lib/rdf/model/node.rb +1 -3
  23. data/lib/rdf/model/statement.rb +7 -47
  24. data/lib/rdf/model/term.rb +9 -0
  25. data/lib/rdf/model/uri.rb +28 -68
  26. data/lib/rdf/model/value.rb +1 -31
  27. data/lib/rdf/nquads.rb +4 -7
  28. data/lib/rdf/ntriples.rb +2 -2
  29. data/lib/rdf/ntriples/format.rb +1 -2
  30. data/lib/rdf/ntriples/reader.rb +15 -68
  31. data/lib/rdf/ntriples/writer.rb +13 -53
  32. data/lib/rdf/query.rb +1 -8
  33. data/lib/rdf/query/pattern.rb +25 -7
  34. data/lib/rdf/query/solution.rb +3 -19
  35. data/lib/rdf/query/solutions.rb +4 -22
  36. data/lib/rdf/query/variable.rb +1 -3
  37. data/lib/rdf/reader.rb +8 -22
  38. data/lib/rdf/repository.rb +23 -5
  39. data/lib/rdf/transaction.rb +19 -8
  40. data/lib/rdf/util/aliasing.rb +3 -13
  41. data/lib/rdf/util/cache.rb +2 -3
  42. data/lib/rdf/util/file.rb +5 -15
  43. data/lib/rdf/vocab.rb +19 -20
  44. data/lib/rdf/writer.rb +5 -44
  45. metadata +12 -27
  46. data/lib/rdf/vocab/schema.rb +0 -652
@@ -144,46 +144,6 @@ module RDF; class Literal
144
144
  end
145
145
  end
146
146
 
147
- ##
148
- # Returns the absolute value of `self`.
149
- #
150
- # @return [RDF::Literal]
151
- # @raise [NotImplementedError] unless implemented in subclass
152
- def abs
153
- raise NotImplementedError
154
- end
155
-
156
- ##
157
- # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if arg is not a numeric value.
158
- #
159
- # @return [RDF::Literal]
160
- # @raise [NotImplementedError] unless implemented in subclass
161
- def round
162
- raise NotImplementedError
163
- end
164
-
165
- ##
166
- # Returns the smallest integer greater than or equal to `self`.
167
- #
168
- # @example
169
- # RDF::Literal(1).ceil #=> RDF::Literal(1)
170
- #
171
- # @return [RDF::Literal]
172
- def ceil
173
- self
174
- end
175
-
176
- ##
177
- # Returns the largest integer less than or equal to `self`.
178
- #
179
- # @example
180
- # RDF::Literal(1).floor #=> RDF::Literal(1)
181
- #
182
- # @return [RDF::Literal]
183
- def floor
184
- self
185
- end
186
-
187
147
  ##
188
148
  # Returns the value as an integer.
189
149
  #
@@ -22,7 +22,7 @@ module RDF; class Literal
22
22
  @string ||= value if value.is_a?(String)
23
23
  @object = case
24
24
  when value.is_a?(::Time) then value
25
- when value.respond_to?(:to_time) then value.to_time rescue ::Time.parse(value.to_s)
25
+ when value.respond_to?(:to_time) then value.to_time
26
26
  else ::Time.parse(value.to_s)
27
27
  end rescue nil
28
28
  end
@@ -63,11 +63,12 @@ module RDF; class Literal
63
63
  #
64
64
  # @return [String]
65
65
  def to_s
66
- @string || if RUBY_VERSION >= '1.9' && RUBY_PLATFORM != 'java'
66
+ @string || if RUBY_PLATFORM != 'java'
67
67
  @object.strftime('%H:%M:%S%:z').
68
68
  sub(/\+00:00|UTC|GMT/, 'Z')
69
69
  else
70
- # Ruby 1.8 doesn't do timezone's properly, use utc_offset
70
+ # FIXME: verify
71
+ # JRuby doesn't do timezone's properly, use utc_offset
71
72
  off = @object.utc_offset == 0 ? "Z" : ("%0.2d:00" % (@object.utc_offset/3600))
72
73
  @object.strftime("%H:%M:%S#{off}")
73
74
  end
@@ -132,9 +132,7 @@ module RDF
132
132
  # If other is a Literal, reverse test to consolodate complex type checking logic
133
133
  other == self
134
134
  else
135
- other.respond_to?(:node?) && other.node? &&
136
- self.hash == other.hash &&
137
- other.respond_to?(:id) && @id == other.id
135
+ other.respond_to?(:node?) && other.node? && other.respond_to?(:id) && @id == other.id
138
136
  end
139
137
  end
140
138
  alias_method :===, :==
@@ -9,7 +9,6 @@ module RDF
9
9
  # RDF::Statement.new(s, p, o)
10
10
  #
11
11
  # @example Creating an RDF statement with a context
12
- # uri = RDF::URI("http://example/")
13
12
  # RDF::Statement.new(s, p, o, :context => uri)
14
13
  #
15
14
  # @example Creating an RDF statement from a `Hash`
@@ -59,7 +58,6 @@ module RDF
59
58
  # @option options [RDF::Term] :object (nil)
60
59
  # @option options [RDF::Resource] :context (nil)
61
60
  # Note, in RDF 1.1, a context MUST be an IRI.
62
- # @return [RDF::Statement]
63
61
  #
64
62
  # @overload initialize(subject, predicate, object, options = {})
65
63
  # @param [RDF::Resource] subject
@@ -67,7 +65,6 @@ module RDF
67
65
  # @param [RDF::Term] object
68
66
  # @param [Hash{Symbol => Object}] options
69
67
  # @option options [RDF::Resource] :context (nil)
70
- # @return [RDF::Statement]
71
68
  def initialize(subject = nil, predicate = nil, object = nil, options = {})
72
69
  case subject
73
70
  when Hash
@@ -108,18 +105,6 @@ module RDF
108
105
  true
109
106
  end
110
107
 
111
- ##
112
- # Returns `true` if any element of the statement is not a
113
- # URI, Node or Literal.
114
- #
115
- # @return [Boolean]
116
- def variable?
117
- !(has_subject? && subject.resource? &&
118
- has_predicate? && predicate.resource? &&
119
- has_object? && (object.resource? || object.literal?) &&
120
- (has_context? ? context.resource? : true ))
121
- end
122
-
123
108
  ##
124
109
  # @return [Boolean]
125
110
  def invalid?
@@ -129,10 +114,10 @@ module RDF
129
114
  ##
130
115
  # @return [Boolean]
131
116
  def valid?
132
- has_subject? && subject.resource? && subject.valid? &&
133
- has_predicate? && predicate.uri? && predicate.valid? &&
134
- has_object? && object.term? && object.valid? &&
135
- (has_context? ? context.resource? && context.valid? : true )
117
+ has_subject? && subject.valid? &&
118
+ has_predicate? && predicate.valid? &&
119
+ has_object? && object.valid? &&
120
+ (has_context? ? context.valid? : true )
136
121
  end
137
122
 
138
123
  ##
@@ -184,11 +169,12 @@ module RDF
184
169
  end
185
170
 
186
171
  ##
187
- # Returns `true` if any resource of this statement is a blank node.
172
+ # Returns `true` if the subject or object of this statement is a blank
173
+ # node.
188
174
  #
189
175
  # @return [Boolean]
190
176
  def has_blank_nodes?
191
- to_quad.compact.any?(&:node?)
177
+ (has_object? && object.node?) || (has_subject? && subject.node?)
192
178
  end
193
179
 
194
180
  ##
@@ -258,32 +244,6 @@ module RDF
258
244
  alias_method :to_a, :to_triple
259
245
  alias_method :to_ary, :to_triple
260
246
 
261
- ##
262
- # Canonicalizes each unfrozen term in the statement
263
- #
264
- # @return [RDF::Statement] `self`
265
- # @since 1.0.8
266
- # @raise [ArgumentError] if any element cannot be canonicalized.
267
- def canonicalize!
268
- self.subject.canonicalize! if has_subject? && !self.subject.frozen?
269
- self.predicate.canonicalize! if has_predicate? && !self.predicate.frozen?
270
- self.object.canonicalize! if has_object? && !self.object.frozen?
271
- self.context.canonicalize! if has_context? && !self.context.frozen?
272
- self.validate!
273
- self
274
- end
275
-
276
- ##
277
- # Returns a version of the statement with each position in canonical form
278
- #
279
- # @return [RDF::Statement] `self` or nil if statement cannot be canonicalized
280
- # @since 1.0.8
281
- def canonicalize
282
- self.dup.canonicalize!
283
- rescue ArgumentError
284
- nil
285
- end
286
-
287
247
  ##
288
248
  # Returns the terms of this statement as a `Hash`.
289
249
  #
@@ -56,6 +56,15 @@ module RDF
56
56
  super
57
57
  end
58
58
 
59
+ ##
60
+ # Returns `true` if this term is constant.
61
+ #
62
+ # @return [Boolean] `true` or `false`
63
+ # @see #variable?
64
+ def constant?
65
+ !(variable?)
66
+ end
67
+
59
68
  ##
60
69
  # Returns a base representation of `self`.
61
70
  #
@@ -33,18 +33,15 @@ module RDF
33
33
  CACHE_SIZE = -1 # unlimited by default
34
34
 
35
35
  # IRI components
36
- if RUBY_VERSION >= '1.9'
37
- UCSCHAR = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
38
- [\\u00A0-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFEF]|
39
- [\\u{10000}-\\u{1FFFD}]|[\\u{20000}-\\u{2FFFD}]|[\\u{30000}-\\u{3FFFD}]|
40
- [\\u{40000}-\\u{4FFFD}]|[\\u{50000}-\\u{5FFFD}]|[\\u{60000}-\\u{6FFFD}]|
41
- [\\u{70000}-\\u{7FFFD}]|[\\u{80000}-\\u{8FFFD}]|[\\u{90000}-\\u{9FFFD}]|
42
- [\\u{A0000}-\\u{AFFFD}]|[\\u{B0000}-\\u{BFFFD}]|[\\u{C0000}-\\u{CFFFD}]|
43
- [\\u{D0000}-\\u{DFFFD}]|[\\u{E0000}-\\u{EFFFD}]
44
- EOS
45
- IPRIVATE = Regexp.compile("[\\uE000-\\uF8FF]|[\\u{F0000}-\\u{FFFFD}]|[\\u100000-\\u10FFFD]").freeze
46
- end
47
-
36
+ UCSCHAR = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
37
+ [\\u00A0-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFEF]|
38
+ [\\u{10000}-\\u{1FFFD}]|[\\u{20000}-\\u{2FFFD}]|[\\u{30000}-\\u{3FFFD}]|
39
+ [\\u{40000}-\\u{4FFFD}]|[\\u{50000}-\\u{5FFFD}]|[\\u{60000}-\\u{6FFFD}]|
40
+ [\\u{70000}-\\u{7FFFD}]|[\\u{80000}-\\u{8FFFD}]|[\\u{90000}-\\u{9FFFD}]|
41
+ [\\u{A0000}-\\u{AFFFD}]|[\\u{B0000}-\\u{BFFFD}]|[\\u{C0000}-\\u{CFFFD}]|
42
+ [\\u{D0000}-\\u{DFFFD}]|[\\u{E0000}-\\u{EFFFD}]
43
+ EOS
44
+ IPRIVATE = Regexp.compile("[\\uE000-\\uF8FF]|[\\u{F0000}-\\u{FFFFD}]|[\\u100000-\\u10FFFD]").freeze
48
45
  SCHEME = Regexp.compile("[A-za-z](?:[A-Za-z0-9+-\.])*").freeze
49
46
  PORT = Regexp.compile("[0-9]*").freeze
50
47
  IP_literal = Regexp.compile("\\[[0-9A-Fa-f:\\.]*\\]").freeze # Simplified, no IPvFuture
@@ -54,19 +51,11 @@ module RDF
54
51
  RESERVED = Regexp.compile("(?:#{GEN_DELIMS}|#{SUB_DELIMS})").freeze
55
52
  UNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~").freeze
56
53
 
57
- if RUBY_VERSION >= '1.9'
58
- IUNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~|#{UCSCHAR}").freeze
59
- else
60
- IUNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~").freeze
61
- end
54
+ IUNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~|#{UCSCHAR}").freeze
62
55
 
63
56
  IPCHAR = Regexp.compile("(?:#{IUNRESERVED}|#{PCT_ENCODED}|#{SUB_DELIMS}|:|@)").freeze
64
57
 
65
- if RUBY_VERSION >= '1.9'
66
- IQUERY = Regexp.compile("(?:#{IPCHAR}|#{IPRIVATE}|/|\\?)*").freeze
67
- else
68
- IQUERY = Regexp.compile("(?:#{IPCHAR}|/|\\?)*").freeze
69
- end
58
+ IQUERY = Regexp.compile("(?:#{IPCHAR}|#{IPRIVATE}|/|\\?)*").freeze
70
59
 
71
60
  IFRAGMENT = Regexp.compile("(?:#{IPCHAR}|/|\\?)*").freeze.freeze
72
61
 
@@ -90,14 +79,7 @@ module RDF
90
79
 
91
80
  IHIER_PART = Regexp.compile("(?:(?://#{IAUTHORITY}#{IPATH_ABEMPTY})|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_ROOTLESS})|(?:#{IPATH_EMPTY}))").freeze
92
81
  IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
93
-
94
- # List of schemes known not to be hierarchical
95
- NON_HIER_SCHEMES = %w(
96
- about acct bitcoin callto cid data fax geo gtalk h323 iax icon im jabber
97
- jms magnet mailto maps news pres proxy session sip sips skype sms spotify stun stuns
98
- tag tel turn turns tv urn javascript
99
- ).freeze
100
-
82
+
101
83
  ##
102
84
  # @return [RDF::Util::Cache]
103
85
  # @private
@@ -145,7 +127,6 @@ module RDF
145
127
  #
146
128
  # @overload URI.new(options = {})
147
129
  # @param [Hash{Symbol => Object}] options
148
- # @raise [ArgumentError] on seriously invalid URI
149
130
  def initialize(uri_or_options)
150
131
  case uri_or_options
151
132
  when Hash
@@ -155,8 +136,6 @@ module RDF
155
136
  else
156
137
  @uri = Addressable::URI.parse(uri_or_options.to_s)
157
138
  end
158
- rescue Addressable::URI::InvalidURIError => e
159
- raise ArgumentError, e.message
160
139
  end
161
140
 
162
141
  ##
@@ -181,21 +160,6 @@ module RDF
181
160
  self.start_with?('urn:')
182
161
  end
183
162
 
184
- ##
185
- # Returns `true` if the URI scheme is hierarchical.
186
- #
187
- # @example
188
- # RDF::URI('http://example.org/').hier? #=> true
189
- # RDF::URI('urn:isbn:125235111').hier? #=> false
190
- #
191
- # @return [Boolean] `true` or `false`
192
- # @see http://en.wikipedia.org/wiki/URI_scheme
193
- # @see {NON_HIER_SCHEMES}
194
- # @since 1.0.10
195
- def hier?
196
- !NON_HIER_SCHEMES.include?(scheme)
197
- end
198
-
199
163
  ##
200
164
  # Returns `true` if this URI is a URL.
201
165
  #
@@ -223,16 +187,14 @@ module RDF
223
187
  alias_method :size, :length
224
188
 
225
189
  ##
226
- # Determine if the URI is a valid according to RFC3987
227
- #
228
- # Note, for Ruby versions < 1.9, this always returns true.
190
+ # Determine if the URI is avalid according to RFC3987
229
191
  #
230
192
  # @return [Boolean] `true` or `false`
231
193
  # @since 0.3.9
232
194
  def valid?
233
195
  # As Addressable::URI does not perform adequate validation, validate
234
196
  # relative to RFC3987
235
- to_s.match(RDF::URI::IRI) || false
197
+ to_s.match(RDF::URI::IRI) || to_s.match(RDF::URI::IRELATIVE_REF) || false
236
198
  end
237
199
 
238
200
  ##
@@ -246,6 +208,16 @@ module RDF
246
208
  self
247
209
  end
248
210
 
211
+ ##
212
+ # Returns a copy of this URI converted into its canonical lexical
213
+ # representation.
214
+ #
215
+ # @return [RDF::URI]
216
+ # @since 0.3.0
217
+ def canonicalize
218
+ self.dup.canonicalize!
219
+ end
220
+
249
221
  ##
250
222
  # Converts this URI into its canonical lexical representation.
251
223
  #
@@ -278,15 +250,12 @@ module RDF
278
250
  # @see RDF::URI#+
279
251
  # @param [Array<String, RDF::URI, #to_s>] uris
280
252
  # @return [RDF::URI]
281
- # @raise [ArgumentError] if the resulting URI is invalid
282
253
  def join(*uris)
283
254
  result = @uri.dup
284
255
  uris.each do |uri|
285
256
  result = result.join(uri)
286
257
  end
287
258
  self.class.new(result)
288
- rescue Addressable::URI::InvalidURIError => e
289
- raise ArgumentError, e.message
290
259
  end
291
260
 
292
261
  ##
@@ -312,7 +281,6 @@ module RDF
312
281
  #
313
282
  # @param [Any] fragment A URI fragment to be appended to this URI
314
283
  # @return [RDF::URI]
315
- # @raise [ArgumentError] if the URI is invalid
316
284
  # @see RDF::URI#+
317
285
  # @see RDF::URI#join
318
286
  # @see <http://tools.ietf.org/html/rfc3986#section-5.2>
@@ -372,27 +340,20 @@ module RDF
372
340
  # @see RDF::URI#join
373
341
  # @param [Any] other
374
342
  # @return [RDF::URI]
375
- # @raise [ArgumentError] on seriously invalid URI
376
343
  def +(other)
377
344
  RDF::URI.intern(self.to_s + other.to_s)
378
- rescue Addressable::URI::InvalidURIError => e
379
- raise ArgumentError, e.message
380
345
  end
381
346
 
382
347
  ##
383
- # Returns `true` if this URI's scheme is not hierarchical,
384
- # or its path component is equal to `/`.
385
- # Protocols not using hierarchical components are always considered
386
- # to be at the root.
348
+ # Returns `true` if this URI's path component is equal to `/`.
387
349
  #
388
350
  # @example
389
351
  # RDF::URI('http://example.org/').root? #=> true
390
352
  # RDF::URI('http://example.org/path/').root? #=> false
391
- # RDF::URI('urn:isbn').root? #=> true
392
353
  #
393
354
  # @return [Boolean] `true` or `false`
394
355
  def root?
395
- !self.hier? || self.path == '/' || self.path.empty?
356
+ self.path == '/' || self.path.empty?
396
357
  end
397
358
 
398
359
  ##
@@ -414,7 +375,7 @@ module RDF
414
375
  end
415
376
 
416
377
  ##
417
- # Returns `true` if this URI is hierarchical and it's path component isn't equal to `/`.
378
+ # Returns `true` if this URI's path component isn't equal to `/`.
418
379
  #
419
380
  # @example
420
381
  # RDF::URI('http://example.org/').has_parent? #=> false
@@ -538,7 +499,7 @@ module RDF
538
499
  # @param [RDF::URI] other
539
500
  # @return [Boolean] `true` or `false`
540
501
  def eql?(other)
541
- other.is_a?(URI) && self.hash == other.hash && self == other
502
+ other.is_a?(URI) && self == other
542
503
  end
543
504
 
544
505
  ##
@@ -560,7 +521,6 @@ module RDF
560
521
  # If other is a Literal, reverse test to consolodate complex type checking logic
561
522
  other == self
562
523
  when String then to_s == other
563
- when URI then hash == other.hash && to_s == other.to_s
564
524
  when URI, Addressable::URI then to_s == other.to_s
565
525
  else other.respond_to?(:to_uri) && to_s == other.to_uri.to_s
566
526
  end
@@ -103,7 +103,7 @@ module RDF
103
103
  end
104
104
 
105
105
  ##
106
- # Returns `true` this value is a {RDF::Query::Variable}, or is contains a variable.
106
+ # Returns `true` if `self` is a {RDF::Query::Variable}.
107
107
  #
108
108
  # @return [Boolean]
109
109
  # @since 0.1.7
@@ -111,15 +111,6 @@ module RDF
111
111
  false
112
112
  end
113
113
 
114
- ##
115
- # Returns `true` if this value is constant.
116
- #
117
- # @return [Boolean] `true` or `false`
118
- # @see #variable?
119
- def constant?
120
- !(variable?)
121
- end
122
-
123
114
  ##
124
115
  # Is this an anonymous value?
125
116
  #
@@ -156,27 +147,6 @@ module RDF
156
147
  end
157
148
  alias_method :validate, :validate!
158
149
 
159
- ##
160
- # Returns a copy of this value converted into its canonical
161
- # representation.
162
- #
163
- # @return [RDF::Value]
164
- # @since 1.0.8
165
- def canonicalize
166
- self.dup.canonicalize!
167
- end
168
-
169
- ##
170
- # Converts this value into its canonical representation.
171
- #
172
- # Should be overridden by concrete classes.
173
- #
174
- # @return [RDF::Value] `self`
175
- # @since 1.0.8
176
- def canonicalize!
177
- self
178
- end
179
-
180
150
  ##
181
151
  # Returns an `RDF::Value` representation of `self`.
182
152
  #