rdf 0.3.8 → 0.3.9
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.
- data/README +16 -30
- data/VERSION +1 -1
- data/lib/rdf/model/graph.rb +22 -4
- data/lib/rdf/model/list.rb +1 -1
- data/lib/rdf/model/literal.rb +7 -18
- data/lib/rdf/model/literal/datetime.rb +3 -2
- data/lib/rdf/model/literal/double.rb +1 -1
- data/lib/rdf/model/literal/time.rb +11 -3
- data/lib/rdf/model/statement.rb +3 -1
- data/lib/rdf/model/uri.rb +92 -18
- data/lib/rdf/model/value.rb +28 -0
- data/lib/rdf/ntriples/reader.rb +1 -1
- data/lib/rdf/ntriples/writer.rb +1 -2
- data/lib/rdf/writer.rb +3 -0
- metadata +49 -49
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
RDF.rb: Linked Data for Ruby
|
2
|
-
|
1
|
+
# RDF.rb: Linked Data for Ruby
|
2
|
+
[](http://travis-ci.org/ruby-rdf/rdf)
|
3
3
|
|
4
4
|
This is a pure-Ruby library for working with [Resource Description Framework
|
5
5
|
(RDF)][RDF] data.
|
@@ -10,8 +10,7 @@ This is a pure-Ruby library for working with [Resource Description Framework
|
|
10
10
|
* <http://blog.datagraph.org/2010/04/parsing-rdf-with-ruby>
|
11
11
|
* <http://blog.datagraph.org/2010/04/rdf-repository-howto>
|
12
12
|
|
13
|
-
Features
|
14
|
-
--------
|
13
|
+
## Features
|
15
14
|
|
16
15
|
* 100% pure Ruby with minimal dependencies and no bloat.
|
17
16
|
* 100% free and unencumbered [public domain](http://unlicense.org/) software.
|
@@ -30,15 +29,13 @@ Features
|
|
30
29
|
* Performs auto-detection of input to select appropriate Reader class if one
|
31
30
|
cannot be determined from file characteristics.
|
32
31
|
|
33
|
-
Tutorials
|
34
|
-
---------
|
32
|
+
## Tutorials
|
35
33
|
|
36
34
|
* [Getting data from the Semantic Web using Ruby and RDF.rb](http://semanticweb.org/wiki/Getting_data_from_the_Semantic_Web_%28Ruby%29)
|
37
35
|
* [Using RDF.rb and Spira to process RDF data from the British Ordnance Survey](http://stephenpope.co.uk/?p=85)
|
38
36
|
* [Getting started with RDF and SPARQL using 4store and RDF.rb](http://www.jenitennison.com/blog/node/152)
|
39
37
|
|
40
|
-
Command Line
|
41
|
-
------------
|
38
|
+
## Command Line
|
42
39
|
When installed, RDF.rb includes a `rdf` shell script which acts as a wrapper to perform a number of different
|
43
40
|
operations on RDF files using available readers and writers.
|
44
41
|
|
@@ -48,8 +45,7 @@ operations on RDF files using available readers and writers.
|
|
48
45
|
* `objects`: Returns unique objects from parsed input.
|
49
46
|
* `predicates`: Returns unique objects from parsed input.
|
50
47
|
|
51
|
-
Examples
|
52
|
-
--------
|
48
|
+
## Examples
|
53
49
|
|
54
50
|
require 'rdf'
|
55
51
|
include RDF
|
@@ -155,8 +151,7 @@ A separate [SPARQL][SPARQL doc] gem builds on basic BGP support to provide full
|
|
155
151
|
foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
|
156
152
|
foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
|
157
153
|
|
158
|
-
Documentation
|
159
|
-
-------------
|
154
|
+
## Documentation
|
160
155
|
|
161
156
|
<http://rubydoc.info/github/ruby-rdf/rdf/frames>
|
162
157
|
|
@@ -261,14 +256,12 @@ The meta-gem [LinkedData][LinkedData doc] includes many of these gems.
|
|
261
256
|
* {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
|
262
257
|
* {RDF::XSD} - XML Schema (XSD)
|
263
258
|
|
264
|
-
Dependencies
|
265
|
-
------------
|
259
|
+
## Dependencies
|
266
260
|
|
267
261
|
* [Ruby](http://ruby-lang.org/) (>= 1.8.7) or (>= 1.8.1 with [Backports][])
|
268
262
|
* [Addressable](http://rubygems.org/gems/addressable) (>= 2.2.0)
|
269
263
|
|
270
|
-
Installation
|
271
|
-
------------
|
264
|
+
## Installation
|
272
265
|
|
273
266
|
The recommended installation method is via [RubyGems](http://rubygems.org/).
|
274
267
|
To install the latest official release of RDF.rb, do:
|
@@ -276,8 +269,7 @@ To install the latest official release of RDF.rb, do:
|
|
276
269
|
% [sudo] gem install rdf # Ruby 1.8.7+ or 1.9.x
|
277
270
|
% [sudo] gem install backports rdf # Ruby 1.8.1+
|
278
271
|
|
279
|
-
Download
|
280
|
-
--------
|
272
|
+
## Download
|
281
273
|
|
282
274
|
To get a local working copy of the development repository, do:
|
283
275
|
|
@@ -288,8 +280,7 @@ follows:
|
|
288
280
|
|
289
281
|
% wget http://github.com/ruby-rdf/rdf/tarball/master
|
290
282
|
|
291
|
-
Resources
|
292
|
-
---------
|
283
|
+
## Resources
|
293
284
|
|
294
285
|
* <http://rubydoc.info/github/ruby-rdf/rdf/frames>
|
295
286
|
* <http://github.com/ruby-rdf/rdf>
|
@@ -298,20 +289,17 @@ Resources
|
|
298
289
|
* <http://raa.ruby-lang.org/project/rdf/>
|
299
290
|
* <http://www.ohloh.net/p/rdf>
|
300
291
|
|
301
|
-
Mailing List
|
302
|
-
------------
|
292
|
+
## Mailing List
|
303
293
|
|
304
294
|
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
305
295
|
|
306
|
-
Authors
|
307
|
-
-------
|
296
|
+
## Authors
|
308
297
|
|
309
298
|
* [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
|
310
299
|
* [Ben Lavender](http://github.com/bhuga) - <http://bhuga.net/>
|
311
300
|
* [Gregg Kellogg](http://github.com/gkellogg) - <http://kellogg-assoc.com/>
|
312
301
|
|
313
|
-
Contributors
|
314
|
-
------------
|
302
|
+
## Contributors
|
315
303
|
|
316
304
|
* [Călin Ardelean](http://github.com/clnx) - <http://github.com/clnx>
|
317
305
|
* [Danny Gagne](http://github.com/danny) - <http://www.dannygagne.com/>
|
@@ -323,8 +311,7 @@ Contributors
|
|
323
311
|
* [Keita Urashima](http://github.com/ursm) - <http://ursm.jp/>
|
324
312
|
* [Pius Uzamere](http://github.com/pius) - <http://pius.me/>
|
325
313
|
|
326
|
-
Contributing
|
327
|
-
------------
|
314
|
+
## Contributing
|
328
315
|
|
329
316
|
* Do your best to adhere to the existing coding conventions and idioms.
|
330
317
|
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
@@ -340,8 +327,7 @@ Contributing
|
|
340
327
|
of thumb, additions larger than about 15 lines of code), we need an
|
341
328
|
explicit [public domain dedication][PDD] on record from you.
|
342
329
|
|
343
|
-
License
|
344
|
-
-------
|
330
|
+
## License
|
345
331
|
|
346
332
|
This is free and unencumbered public domain software. For more information,
|
347
333
|
see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.9
|
data/lib/rdf/model/graph.rb
CHANGED
@@ -36,6 +36,7 @@ module RDF
|
|
36
36
|
|
37
37
|
##
|
38
38
|
# @return [RDF::Resource]
|
39
|
+
# @deprecated In the next release, graphs will have no name
|
39
40
|
attr_accessor :context
|
40
41
|
|
41
42
|
##
|
@@ -67,11 +68,22 @@ module RDF
|
|
67
68
|
end
|
68
69
|
|
69
70
|
##
|
70
|
-
# @
|
71
|
-
#
|
71
|
+
# @overload initialize(context, options)
|
72
|
+
# @param [RDF::Resource] context
|
73
|
+
# The context only provides a context for loading relative documents
|
74
|
+
# @param [Hash{Symbol => Object}] options
|
75
|
+
# @deprecated Graph context will be removed in the next release.
|
76
|
+
# This is because context relates to a Named Graph in RDF 1.1
|
77
|
+
# and a default graph has no context/name.
|
78
|
+
# @overload initialize(options)
|
79
|
+
# @param [Hash{Symbol => Object}] options
|
72
80
|
# @yield [graph]
|
73
81
|
# @yieldparam [Graph]
|
74
|
-
|
82
|
+
# @note Currently, context makes this a named garph;
|
83
|
+
# in the next release it will not
|
84
|
+
def initialize(*args, &block)
|
85
|
+
context = args.shift unless args.first.is_a?(Hash)
|
86
|
+
options = args.first || {}
|
75
87
|
@context = case context
|
76
88
|
when nil then nil
|
77
89
|
when RDF::Resource then context
|
@@ -91,6 +103,7 @@ module RDF
|
|
91
103
|
|
92
104
|
##
|
93
105
|
# @return [void]
|
106
|
+
# @note The next release, graphs will not be named
|
94
107
|
def load!(*args)
|
95
108
|
case
|
96
109
|
when args.empty?
|
@@ -111,6 +124,7 @@ module RDF
|
|
111
124
|
# Returns `true` if this is a named graph.
|
112
125
|
#
|
113
126
|
# @return [Boolean]
|
127
|
+
# @note The next release, graphs will not be named, this will return false
|
114
128
|
def named?
|
115
129
|
!unnamed?
|
116
130
|
end
|
@@ -119,6 +133,7 @@ module RDF
|
|
119
133
|
# Returns `true` if this is a unnamed graph.
|
120
134
|
#
|
121
135
|
# @return [Boolean]
|
136
|
+
# @note The next release, graphs will not be named, this will return true
|
122
137
|
def unnamed?
|
123
138
|
context.nil?
|
124
139
|
end
|
@@ -136,6 +151,7 @@ module RDF
|
|
136
151
|
# Returns all unique RDF contexts for this graph.
|
137
152
|
#
|
138
153
|
# @return [Enumerator<RDF::Resource>]
|
154
|
+
# @note The next release, graphs will not be named, this be empty
|
139
155
|
def contexts
|
140
156
|
(named? ? [context] : []).to_enum.extend(RDF::Countable)
|
141
157
|
end
|
@@ -144,6 +160,7 @@ module RDF
|
|
144
160
|
# Returns the URI representation of this graph.
|
145
161
|
#
|
146
162
|
# @return [RDF::URI]
|
163
|
+
# @note The next release, graphs will not be named, this will return nil
|
147
164
|
def to_uri
|
148
165
|
context
|
149
166
|
end
|
@@ -169,6 +186,7 @@ module RDF
|
|
169
186
|
# Returns `true` if this graph has an anonymous context, `false` otherwise.
|
170
187
|
#
|
171
188
|
# @return [Boolean]
|
189
|
+
# @note The next release, graphs will not be named, this will return true
|
172
190
|
def anonymous?
|
173
191
|
context.nil? ? false : context.anonymous?
|
174
192
|
end
|
@@ -190,7 +208,7 @@ module RDF
|
|
190
208
|
# @see RDF::Enumerable#has_statement?
|
191
209
|
def has_statement?(statement)
|
192
210
|
statement = statement.dup
|
193
|
-
statement.context = context
|
211
|
+
statement.context = context # TODO: going away
|
194
212
|
@data.has_statement?(statement)
|
195
213
|
end
|
196
214
|
|
data/lib/rdf/model/list.rb
CHANGED
@@ -236,7 +236,7 @@ module RDF
|
|
236
236
|
end
|
237
237
|
|
238
238
|
graph.insert([new_subject, RDF.type, RDF.List])
|
239
|
-
graph.insert([new_subject, RDF.first, value])
|
239
|
+
graph.insert([new_subject, RDF.first, value.is_a?(RDF::List) ? value.subject : value])
|
240
240
|
graph.insert([new_subject, RDF.rest, RDF.nil])
|
241
241
|
|
242
242
|
self
|
data/lib/rdf/model/literal.rb
CHANGED
@@ -279,13 +279,15 @@ module RDF
|
|
279
279
|
end
|
280
280
|
|
281
281
|
##
|
282
|
-
#
|
283
|
-
#
|
282
|
+
# Validates the value using {#valid?}, raising an error if the value is
|
283
|
+
# invalid.
|
284
284
|
#
|
285
|
-
# @return [
|
285
|
+
# @return [RDF::Literal] `self`
|
286
|
+
# @raise [ArgumentError] if the value is invalid
|
286
287
|
# @since 0.2.1
|
287
|
-
def
|
288
|
-
|
288
|
+
def validate!
|
289
|
+
raise ArgumentError, "#{to_s.inspect} is not a valid <#{datatype.to_s}> literal" if invalid?
|
290
|
+
self
|
289
291
|
end
|
290
292
|
|
291
293
|
##
|
@@ -316,19 +318,6 @@ module RDF
|
|
316
318
|
end
|
317
319
|
end
|
318
320
|
|
319
|
-
##
|
320
|
-
# Validates the value using {#valid?}, raising an error if the value is
|
321
|
-
# invalid.
|
322
|
-
#
|
323
|
-
# @return [RDF::Literal] `self`
|
324
|
-
# @raise [ArgumentError] if the value is invalid
|
325
|
-
# @since 0.2.1
|
326
|
-
def validate!
|
327
|
-
raise ArgumentError, "#{to_s.inspect} is not a valid <#{datatype.to_s}> literal" if invalid?
|
328
|
-
self
|
329
|
-
end
|
330
|
-
alias_method :validate, :validate!
|
331
|
-
|
332
321
|
##
|
333
322
|
# Returns a copy of this literal converted into its canonical lexical
|
334
323
|
# representation.
|
@@ -24,11 +24,12 @@ module RDF; class Literal
|
|
24
24
|
|
25
25
|
##
|
26
26
|
# Converts this literal into its canonical lexical representation.
|
27
|
+
# with date and time normalized to UTC.
|
27
28
|
#
|
28
29
|
# @return [RDF::Literal] `self`
|
29
30
|
# @see http://www.w3.org/TR/xmlschema-2/#dateTime
|
30
31
|
def canonicalize!
|
31
|
-
@string = @object.new_offset(0).strftime('%Y-%m-%dT%H:%M:%
|
32
|
+
@string = @object.new_offset(0).strftime('%Y-%m-%dT%H:%M:%SZ') if self.valid?
|
32
33
|
self
|
33
34
|
end
|
34
35
|
|
@@ -49,7 +50,7 @@ module RDF; class Literal
|
|
49
50
|
#
|
50
51
|
# @return [String]
|
51
52
|
def to_s
|
52
|
-
@string || @object.strftime('%Y-%m-%dT%H:%M:%S
|
53
|
+
@string || @object.strftime('%Y-%m-%dT%H:%M:%S%:z').sub(/\+00:00|UTC|GMT/, 'Z')
|
53
54
|
end
|
54
55
|
|
55
56
|
##
|
@@ -47,7 +47,7 @@ module RDF; class Literal
|
|
47
47
|
when @object.infinite? then @object.to_s[0...-'inity'.length].upcase
|
48
48
|
when @object.zero? then '0.0E0'
|
49
49
|
else
|
50
|
-
i, f, e = ('%.
|
50
|
+
i, f, e = ('%.15E' % @object.to_f).split(/[\.E]/)
|
51
51
|
f.sub!(/0*$/, '') # remove any trailing zeroes
|
52
52
|
f = '0' if f.empty? # ...but there must be a digit to the right of the decimal point
|
53
53
|
e.sub!(/^\+?0+(\d)$/, '\1') # remove the optional leading '+' sign and any extra leading zeroes
|
@@ -41,7 +41,7 @@ module RDF; class Literal
|
|
41
41
|
# @return [RDF::Literal] `self`
|
42
42
|
# @see http://www.w3.org/TR/xmlschema-2/#time
|
43
43
|
def canonicalize!
|
44
|
-
@string = @object.utc.strftime('%H:%M:%
|
44
|
+
@string = @object.utc.strftime('%H:%M:%SZ') if self.valid?
|
45
45
|
self
|
46
46
|
end
|
47
47
|
|
@@ -54,15 +54,23 @@ module RDF; class Literal
|
|
54
54
|
# @return [Boolean]
|
55
55
|
# @since 0.2.1
|
56
56
|
def valid?
|
57
|
-
super && object
|
57
|
+
super && !object.nil?
|
58
58
|
end
|
59
59
|
|
60
60
|
##
|
61
61
|
# Returns the value as a string.
|
62
|
+
# Does not normalize timezone
|
62
63
|
#
|
63
64
|
# @return [String]
|
64
65
|
def to_s
|
65
|
-
@string ||
|
66
|
+
@string || if RUBY_VERSION >= '1.9' && RUBY_PLATFORM != 'java'
|
67
|
+
@object.strftime('%H:%M:%S%:z').
|
68
|
+
sub(/\+00:00|UTC|GMT/, 'Z')
|
69
|
+
else
|
70
|
+
# Ruby 1.8 doesn't do timezone's properly, use utc_offset
|
71
|
+
off = @object.utc_offset == 0 ? "Z" : ("%0.2d:00" % (@object.utc_offset/3600))
|
72
|
+
@object.strftime("%H:%M:%S#{off}")
|
73
|
+
end
|
66
74
|
end
|
67
75
|
|
68
76
|
##
|
data/lib/rdf/model/statement.rb
CHANGED
data/lib/rdf/model/uri.rb
CHANGED
@@ -3,6 +3,7 @@ require 'addressable/uri'
|
|
3
3
|
module RDF
|
4
4
|
##
|
5
5
|
# A Uniform Resource Identifier (URI).
|
6
|
+
# Also compatible with International Resource Identifier (IRI)
|
6
7
|
#
|
7
8
|
# `RDF::URI` supports all the instance methods of `Addressable::URI`.
|
8
9
|
#
|
@@ -19,6 +20,8 @@ module RDF
|
|
19
20
|
# uri.to_s #=> "http://rdf.rubyforge.org/"
|
20
21
|
#
|
21
22
|
# @see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier
|
23
|
+
# @see http://www.ietf.org/rfc/rfc3986.txt
|
24
|
+
# @see http://www.ietf.org/rfc/rfc3987.txt
|
22
25
|
# @see http://addressable.rubyforge.org/
|
23
26
|
class URI
|
24
27
|
include RDF::Resource
|
@@ -27,7 +30,66 @@ module RDF
|
|
27
30
|
# Defines the maximum number of interned URI references that can be held
|
28
31
|
# cached in memory at any one time.
|
29
32
|
CACHE_SIZE = -1 # unlimited by default
|
30
|
-
|
33
|
+
|
34
|
+
# IRI components
|
35
|
+
if RUBY_VERSION >= '1.9'
|
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]")
|
45
|
+
end
|
46
|
+
|
47
|
+
SCHEME = Regexp.compile("[A-za-z](?:[A-Za-z0-9+-\.])*")
|
48
|
+
PORT = Regexp.compile("[0-9]*")
|
49
|
+
IP_literal = Regexp.compile("\\[[0-9A-Fa-f:\\.]*\\]") # Simplified, no IPvFuture
|
50
|
+
PCT_ENCODED = Regexp.compile("%[0-9A-Fa-f]{2}")
|
51
|
+
GEN_DELIMS = Regexp.compile("[:/\\?\\#\\[\\]@]")
|
52
|
+
SUB_DELIMS = Regexp.compile("[!\\$&'\\(\\)\\*\\+,;=]")
|
53
|
+
RESERVED = Regexp.compile("(?:#{GEN_DELIMS}|#{SUB_DELIMS})")
|
54
|
+
UNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~")
|
55
|
+
|
56
|
+
if RUBY_VERSION >= '1.9'
|
57
|
+
IUNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~|#{UCSCHAR}")
|
58
|
+
else
|
59
|
+
IUNRESERVED = Regexp.compile("[A-Za-z0-9]|-|\\.|_|~")
|
60
|
+
end
|
61
|
+
|
62
|
+
IPCHAR = Regexp.compile("(?:#{IUNRESERVED}|#{PCT_ENCODED}|#{SUB_DELIMS}|:|@)")
|
63
|
+
|
64
|
+
if RUBY_VERSION >= '1.9'
|
65
|
+
IQUERY = Regexp.compile("(?:#{IPCHAR}|#{IPRIVATE}|/|\\?)*")
|
66
|
+
else
|
67
|
+
IQUERY = Regexp.compile("(?:#{IPCHAR}|/|\\?)*")
|
68
|
+
end
|
69
|
+
|
70
|
+
IFRAGMENT = Regexp.compile("(?:#{IPCHAR}|/|\\?)*")
|
71
|
+
|
72
|
+
ISEGMENT = Regexp.compile("(?:#{IPCHAR})*")
|
73
|
+
ISEGMENT_NZ = Regexp.compile("(?:#{IPCHAR})+")
|
74
|
+
ISEGMENT_NZ_NC = Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS})|@)+")
|
75
|
+
|
76
|
+
IPATH_ABEMPTY = Regexp.compile("(?:/#{ISEGMENT})*")
|
77
|
+
IPATH_ABSOLUTE = Regexp.compile("/(?:(?:#{ISEGMENT_NZ})(/#{ISEGMENT})*)?")
|
78
|
+
IPATH_NOSCHEME = Regexp.compile("(?:#{ISEGMENT_NZ_NC})(?:/#{ISEGMENT})*")
|
79
|
+
IPATH_ROOTLESS = Regexp.compile("(?:#{ISEGMENT_NZ})(?:/#{ISEGMENT})*")
|
80
|
+
IPATH_EMPTY = Regexp.compile("")
|
81
|
+
|
82
|
+
IREG_NAME = Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS}))*")
|
83
|
+
IHOST = Regexp.compile("(?:#{IP_literal})|(?:#{IREG_NAME})")
|
84
|
+
IUSERINFO = Regexp.compile("(?:(?:#{IUNRESERVED})|(?:#{PCT_ENCODED})|(?:#{SUB_DELIMS})|:)*")
|
85
|
+
IAUTHORITY = Regexp.compile("(?:#{IUSERINFO}@)?#{IHOST}(?:#{PORT})?")
|
86
|
+
|
87
|
+
IRELATIVE_PART = Regexp.compile("(?:(?://#{IAUTHORITY}(?:#{IPATH_ABEMPTY}))|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_NOSCHEME})|(?:#{IPATH_EMPTY}))")
|
88
|
+
IRELATIVE_REF = Regexp.compile("^#{IRELATIVE_PART}(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$")
|
89
|
+
|
90
|
+
IHIER_PART = Regexp.compile("(?:(?://#{IAUTHORITY}#{IPATH_ABEMPTY})|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_ROOTLESS})|(?:#{IPATH_EMPTY}))")
|
91
|
+
IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$")
|
92
|
+
|
31
93
|
##
|
32
94
|
# @return [RDF::Util::Cache]
|
33
95
|
# @private
|
@@ -142,6 +204,19 @@ module RDF
|
|
142
204
|
end
|
143
205
|
alias_method :size, :length
|
144
206
|
|
207
|
+
##
|
208
|
+
# Determine if the URI is avalid according to RFC3987
|
209
|
+
#
|
210
|
+
# Note, for Ruby versions < 1.9, this always returns true.
|
211
|
+
#
|
212
|
+
# @return [Boolean] `true` or `false`
|
213
|
+
# @since 0.3.9
|
214
|
+
def valid?
|
215
|
+
# As Addressable::URI does not perform adequate validation, validate
|
216
|
+
# relative to RFC3987
|
217
|
+
to_s.match(RDF::URI::IRI) || to_s.match(RDF::URI::IRELATIVE_REF) || false
|
218
|
+
end
|
219
|
+
|
145
220
|
##
|
146
221
|
# Validates this URI, raising an error if it is invalid.
|
147
222
|
#
|
@@ -149,10 +224,9 @@ module RDF
|
|
149
224
|
# @raise [ArgumentError] if the URI is invalid
|
150
225
|
# @since 0.3.0
|
151
226
|
def validate!
|
152
|
-
#
|
227
|
+
raise ArgumentError, "#{to_s.inspect} is not a valid IRI" if invalid?
|
153
228
|
self
|
154
229
|
end
|
155
|
-
alias_method :validate, :validate!
|
156
230
|
|
157
231
|
##
|
158
232
|
# Returns a copy of this URI converted into its canonical lexical
|
@@ -170,7 +244,7 @@ module RDF
|
|
170
244
|
# @return [RDF::URI] `self`
|
171
245
|
# @since 0.3.0
|
172
246
|
def canonicalize!
|
173
|
-
|
247
|
+
@uri.normalize!
|
174
248
|
self
|
175
249
|
end
|
176
250
|
|
@@ -250,21 +324,21 @@ module RDF
|
|
250
324
|
RDF::URI.intern(to_s.sub(/:+$/,'') + ':' + fragment.to_s.sub(/^:+/,''))
|
251
325
|
else # !urn?
|
252
326
|
case to_s[-1].chr
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
else # includes '/'. Results from bases ending in '/' are the same as if there were no trailing slash.
|
261
|
-
case fragment.to_s[0].chr
|
262
|
-
when '#' then # Base ending with '/', fragment beginning with '#'. The fragment wins, we use '#'.
|
263
|
-
RDF::URI.intern(to_s.sub(/\/+$/,'') + '#' + fragment.to_s.sub(/^#+/,''))
|
264
|
-
else
|
265
|
-
RDF::URI.intern(to_s.sub(/\/+$/,'') + '/' + fragment.to_s.sub(/^\/+/,''))
|
266
|
-
end
|
327
|
+
when '#'
|
328
|
+
case fragment.to_s[0].chr
|
329
|
+
when '/' then # Base ending with '#', fragment beginning with '/'. The fragment wins, we use '/'.
|
330
|
+
RDF::URI.intern(to_s.sub(/#+$/,'') + '/' + fragment.to_s.sub(/^\/+/,''))
|
331
|
+
else
|
332
|
+
RDF::URI.intern(to_s.sub(/#+$/,'') + '#' + fragment.to_s.sub(/^#+/,''))
|
267
333
|
end
|
334
|
+
else # includes '/'. Results from bases ending in '/' are the same as if there were no trailing slash.
|
335
|
+
case fragment.to_s[0].chr
|
336
|
+
when '#' then # Base ending with '/', fragment beginning with '#'. The fragment wins, we use '#'.
|
337
|
+
RDF::URI.intern(to_s.sub(/\/+$/,'') + '#' + fragment.to_s.sub(/^#+/,''))
|
338
|
+
else
|
339
|
+
RDF::URI.intern(to_s.sub(/\/+$/,'') + '/' + fragment.to_s.sub(/^\/+/,''))
|
340
|
+
end
|
341
|
+
end
|
268
342
|
end
|
269
343
|
end
|
270
344
|
|
data/lib/rdf/model/value.rb
CHANGED
@@ -93,6 +93,34 @@ module RDF
|
|
93
93
|
false
|
94
94
|
end
|
95
95
|
|
96
|
+
##
|
97
|
+
# Returns `true` if the value has a valid representation
|
98
|
+
#
|
99
|
+
# @return [Boolean] `true` or `false`
|
100
|
+
# @since 0.3.9
|
101
|
+
def valid?
|
102
|
+
true
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Returns `true` if value is not valid
|
107
|
+
#
|
108
|
+
# @return [Boolean] `true` or `false`
|
109
|
+
# @since 0.2.1
|
110
|
+
def invalid?
|
111
|
+
!valid?
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# Default validate! implementation, overridden in concrete classes
|
116
|
+
# @return [RDF::Literal] `self`
|
117
|
+
# @raise [ArgumentError] if the value is invalid
|
118
|
+
# @since 0.3.9
|
119
|
+
def validate!
|
120
|
+
raise ArgumentError if invalid?
|
121
|
+
end
|
122
|
+
alias_method :validate, :validate!
|
123
|
+
|
96
124
|
##
|
97
125
|
# Returns an `RDF::Value` representation of `self`.
|
98
126
|
#
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -124,7 +124,7 @@ module RDF::NTriples
|
|
124
124
|
# @see http://blog.grayproductions.net/articles/understanding_m17n
|
125
125
|
# @see http://yehudakatz.com/2010/05/17/encodings-unabridged/
|
126
126
|
def self.unescape(string)
|
127
|
-
string.force_encoding(Encoding::ASCII_8BIT) if string.respond_to?(:force_encoding)
|
127
|
+
string = string.dup.force_encoding(Encoding::ASCII_8BIT) if string.respond_to?(:force_encoding)
|
128
128
|
|
129
129
|
# Decode \t|\n|\r|\"|\\ character escapes:
|
130
130
|
ESCAPE_CHARS.each { |escape| string.gsub!(escape.inspect[1...-1], escape) }
|
data/lib/rdf/ntriples/writer.rb
CHANGED
data/lib/rdf/writer.rb
CHANGED
@@ -136,7 +136,10 @@ module RDF
|
|
136
136
|
# @yieldparam [RDF::Writer] writer
|
137
137
|
# @yieldreturn [void]
|
138
138
|
# @return [String]
|
139
|
+
# @raise [ArgumentError] if no block is provided
|
139
140
|
def self.buffer(*args, &block)
|
141
|
+
raise ArgumentError, "block expected" unless block_given?
|
142
|
+
|
140
143
|
StringIO.open do |buffer|
|
141
144
|
self.new(buffer, *args) { |writer| block.call(writer) }
|
142
145
|
buffer.string
|
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.3.
|
4
|
+
version: 0.3.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,72 +11,72 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
18
|
-
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
18
|
requirements:
|
21
19
|
- - ! '>='
|
22
20
|
- !ruby/object:Gem::Version
|
23
21
|
version: 2.2.6
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
27
22
|
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
28
24
|
requirements:
|
29
25
|
- - ! '>='
|
30
26
|
- !ruby/object:Gem::Version
|
31
27
|
version: 2.2.6
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: yard
|
34
|
-
requirement: !ruby/object:Gem::Requirement
|
35
28
|
none: false
|
29
|
+
name: addressable
|
30
|
+
prerelease: false
|
31
|
+
type: :runtime
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
34
|
requirements:
|
37
35
|
- - ! '>='
|
38
36
|
- !ruby/object:Gem::Version
|
39
37
|
version: 0.7.5
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
38
|
none: false
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
44
40
|
requirements:
|
45
41
|
- - ! '>='
|
46
42
|
- !ruby/object:Gem::Version
|
47
43
|
version: 0.7.5
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rdf-spec
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
44
|
none: false
|
45
|
+
name: yard
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
50
|
requirements:
|
53
51
|
- - ~>
|
54
52
|
- !ruby/object:Gem::Version
|
55
53
|
version: 0.3.8
|
56
|
-
type: :development
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: !ruby/object:Gem::Requirement
|
59
54
|
none: false
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
60
56
|
requirements:
|
61
57
|
- - ~>
|
62
58
|
- !ruby/object:Gem::Version
|
63
59
|
version: 0.3.8
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: rspec
|
66
|
-
requirement: !ruby/object:Gem::Requirement
|
67
60
|
none: false
|
61
|
+
name: rdf-spec
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
66
|
requirements:
|
69
67
|
- - ! '>='
|
70
68
|
- !ruby/object:Gem::Version
|
71
69
|
version: 2.8.0
|
72
|
-
type: :development
|
73
|
-
prerelease: false
|
74
|
-
version_requirements: !ruby/object:Gem::Requirement
|
75
70
|
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
76
72
|
requirements:
|
77
73
|
- - ! '>='
|
78
74
|
- !ruby/object:Gem::Version
|
79
75
|
version: 2.8.0
|
76
|
+
none: false
|
77
|
+
name: rspec
|
78
|
+
prerelease: false
|
79
|
+
type: :development
|
80
80
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework
|
81
81
|
(RDF) data.
|
82
82
|
email: [email protected]
|
@@ -93,8 +93,19 @@ files:
|
|
93
93
|
- bin/rdf
|
94
94
|
- etc/doap.nt
|
95
95
|
- lib/df.rb
|
96
|
+
- lib/rdf.rb
|
96
97
|
- lib/rdf/cli.rb
|
97
98
|
- lib/rdf/format.rb
|
99
|
+
- lib/rdf/nquads.rb
|
100
|
+
- lib/rdf/ntriples.rb
|
101
|
+
- lib/rdf/query.rb
|
102
|
+
- lib/rdf/reader.rb
|
103
|
+
- lib/rdf/repository.rb
|
104
|
+
- lib/rdf/transaction.rb
|
105
|
+
- lib/rdf/util.rb
|
106
|
+
- lib/rdf/version.rb
|
107
|
+
- lib/rdf/vocab.rb
|
108
|
+
- lib/rdf/writer.rb
|
98
109
|
- lib/rdf/mixin/countable.rb
|
99
110
|
- lib/rdf/mixin/durable.rb
|
100
111
|
- lib/rdf/mixin/enumerable.rb
|
@@ -107,16 +118,6 @@ files:
|
|
107
118
|
- lib/rdf/mixin/writable.rb
|
108
119
|
- lib/rdf/model/graph.rb
|
109
120
|
- lib/rdf/model/list.rb
|
110
|
-
- lib/rdf/model/literal/boolean.rb
|
111
|
-
- lib/rdf/model/literal/date.rb
|
112
|
-
- lib/rdf/model/literal/datetime.rb
|
113
|
-
- lib/rdf/model/literal/decimal.rb
|
114
|
-
- lib/rdf/model/literal/double.rb
|
115
|
-
- lib/rdf/model/literal/integer.rb
|
116
|
-
- lib/rdf/model/literal/numeric.rb
|
117
|
-
- lib/rdf/model/literal/time.rb
|
118
|
-
- lib/rdf/model/literal/token.rb
|
119
|
-
- lib/rdf/model/literal/xml.rb
|
120
121
|
- lib/rdf/model/literal.rb
|
121
122
|
- lib/rdf/model/node.rb
|
122
123
|
- lib/rdf/model/resource.rb
|
@@ -124,25 +125,17 @@ files:
|
|
124
125
|
- lib/rdf/model/term.rb
|
125
126
|
- lib/rdf/model/uri.rb
|
126
127
|
- lib/rdf/model/value.rb
|
127
|
-
- lib/rdf/nquads.rb
|
128
128
|
- lib/rdf/ntriples/format.rb
|
129
129
|
- lib/rdf/ntriples/reader.rb
|
130
130
|
- lib/rdf/ntriples/writer.rb
|
131
|
-
- lib/rdf/ntriples.rb
|
132
131
|
- lib/rdf/query/pattern.rb
|
133
132
|
- lib/rdf/query/solution.rb
|
134
133
|
- lib/rdf/query/solutions.rb
|
135
134
|
- lib/rdf/query/variable.rb
|
136
|
-
- lib/rdf/query.rb
|
137
|
-
- lib/rdf/reader.rb
|
138
|
-
- lib/rdf/repository.rb
|
139
|
-
- lib/rdf/transaction.rb
|
140
135
|
- lib/rdf/util/aliasing.rb
|
141
136
|
- lib/rdf/util/cache.rb
|
142
137
|
- lib/rdf/util/file.rb
|
143
138
|
- lib/rdf/util/uuid.rb
|
144
|
-
- lib/rdf/util.rb
|
145
|
-
- lib/rdf/version.rb
|
146
139
|
- lib/rdf/vocab/cc.rb
|
147
140
|
- lib/rdf/vocab/cert.rb
|
148
141
|
- lib/rdf/vocab/dc.rb
|
@@ -161,9 +154,16 @@ files:
|
|
161
154
|
- lib/rdf/vocab/wot.rb
|
162
155
|
- lib/rdf/vocab/xhtml.rb
|
163
156
|
- lib/rdf/vocab/xsd.rb
|
164
|
-
- lib/rdf/
|
165
|
-
- lib/rdf/
|
166
|
-
- lib/rdf.rb
|
157
|
+
- lib/rdf/model/literal/boolean.rb
|
158
|
+
- lib/rdf/model/literal/date.rb
|
159
|
+
- lib/rdf/model/literal/datetime.rb
|
160
|
+
- lib/rdf/model/literal/decimal.rb
|
161
|
+
- lib/rdf/model/literal/double.rb
|
162
|
+
- lib/rdf/model/literal/integer.rb
|
163
|
+
- lib/rdf/model/literal/numeric.rb
|
164
|
+
- lib/rdf/model/literal/time.rb
|
165
|
+
- lib/rdf/model/literal/token.rb
|
166
|
+
- lib/rdf/model/literal/xml.rb
|
167
167
|
homepage: http://ruby-rdf.github.com/rdf
|
168
168
|
licenses:
|
169
169
|
- Public Domain
|
@@ -172,17 +172,17 @@ rdoc_options: []
|
|
172
172
|
require_paths:
|
173
173
|
- lib
|
174
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
-
none: false
|
176
175
|
requirements:
|
177
176
|
- - ! '>='
|
178
177
|
- !ruby/object:Gem::Version
|
179
178
|
version: 1.8.1
|
180
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
179
|
none: false
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
181
|
requirements:
|
183
182
|
- - ! '>='
|
184
183
|
- !ruby/object:Gem::Version
|
185
184
|
version: '0'
|
185
|
+
none: false
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project: rdf
|
188
188
|
rubygems_version: 1.8.24
|