rdf 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/rdf/format.rb +3 -1
- data/lib/rdf/model/literal.rb +2 -0
- data/lib/rdf/model/uri.rb +30 -4
- data/lib/rdf/nquads.rb +1 -0
- data/lib/rdf/ntriples/reader.rb +1 -0
- data/lib/rdf/ntriples/writer.rb +6 -1
- data/lib/rdf/reader.rb +1 -1
- data/lib/rdf/util/file.rb +9 -4
- data/lib/rdf/writer.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDY3ZTk0N2E2NGI5MzA0MDk3ZDJjZWU3MWY4Y2RjNDUyOGMxNDdhYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTdiN2I3Y2Q5ZmNiZWRlY2U3N2Q0MzU3OGNlODU5ZGE3NzIzYzEwMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmYxNjVmODNjNDE0NWQ2OWI4MTVjZDRhNDE0NzFiYTgwMzk2NjkyZmMyODU3
|
10
|
+
NTI5YWQ3OTI4NWYxYThlNDk1ZGM4OGNhMGU0NzgzYmVkNzk1ZjIxZTJiM2Ix
|
11
|
+
YzlhMTEyNGEzMThhZjhiNzdjODA2ZjM5NmE0YjE1NGRhODhhYjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njg1NjhiNDllYjM1ZTBkMDEyMjgxMDJmNWYwMjRmOTgzNDc4NGYxNjlkNjQ5
|
14
|
+
YWU3YmEyMWFlOThiYTA3ZDY2NWFiOTA3NjNiYjliMTczMTlhNDM3MWU0OGM2
|
15
|
+
NmE0MDliODBjZTBjOTY3NzVlMmRjZDAyNmU2NTM4MzFiNDJjZDc=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.10
|
data/lib/rdf/format.rb
CHANGED
@@ -142,12 +142,14 @@ module RDF
|
|
142
142
|
|
143
143
|
# If we have a sample, use that for format detection
|
144
144
|
if sample = (options[:sample] if options.is_a?(Hash)) || (yield if block_given?)
|
145
|
+
sample = sample.to_s
|
146
|
+
sample.force_encoding(Encoding::UTF_8) if sample.respond_to?(:force_encoding)
|
145
147
|
# Given a sample, perform format detection across the appropriate formats, choosing
|
146
148
|
# the first that matches
|
147
149
|
format ||= @@subclasses
|
148
150
|
|
149
151
|
# Return first format that has a positive detection
|
150
|
-
format.detect {|f| f.detect(sample
|
152
|
+
format.detect {|f| f.detect(sample)} || format.first
|
151
153
|
elsif format.is_a?(Array)
|
152
154
|
# Otherwise, just return the first matching format
|
153
155
|
format.first
|
data/lib/rdf/model/literal.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module RDF
|
2
3
|
##
|
3
4
|
# An RDF literal.
|
@@ -166,6 +167,7 @@ module RDF
|
|
166
167
|
@object = value
|
167
168
|
@string = options[:lexical] if options[:lexical]
|
168
169
|
@string = value if !defined?(@string) && value.is_a?(String)
|
170
|
+
@string.encode!(Encoding::UTF_8) if @string && @string.respond_to?(:encode!)
|
169
171
|
@language = options[:language].to_s.to_sym if options[:language]
|
170
172
|
@datatype = RDF::URI(options[:datatype]) if options[:datatype]
|
171
173
|
@datatype ||= self.class.const_get(:DATATYPE) if self.class.const_defined?(:DATATYPE)
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -90,7 +90,14 @@ module RDF
|
|
90
90
|
|
91
91
|
IHIER_PART = Regexp.compile("(?:(?://#{IAUTHORITY}#{IPATH_ABEMPTY})|(?:#{IPATH_ABSOLUTE})|(?:#{IPATH_ROOTLESS})|(?:#{IPATH_EMPTY}))").freeze
|
92
92
|
IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
|
93
|
-
|
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
|
+
|
94
101
|
##
|
95
102
|
# @return [RDF::Util::Cache]
|
96
103
|
# @private
|
@@ -174,6 +181,21 @@ module RDF
|
|
174
181
|
self.start_with?('urn:')
|
175
182
|
end
|
176
183
|
|
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
|
+
|
177
199
|
##
|
178
200
|
# Returns `true` if this URI is a URL.
|
179
201
|
#
|
@@ -358,15 +380,19 @@ module RDF
|
|
358
380
|
end
|
359
381
|
|
360
382
|
##
|
361
|
-
# Returns `true` if this URI's
|
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.
|
362
387
|
#
|
363
388
|
# @example
|
364
389
|
# RDF::URI('http://example.org/').root? #=> true
|
365
390
|
# RDF::URI('http://example.org/path/').root? #=> false
|
391
|
+
# RDF::URI('urn:isbn').root? #=> true
|
366
392
|
#
|
367
393
|
# @return [Boolean] `true` or `false`
|
368
394
|
def root?
|
369
|
-
self.path == '/' || self.path.empty?
|
395
|
+
!self.hier? || self.path == '/' || self.path.empty?
|
370
396
|
end
|
371
397
|
|
372
398
|
##
|
@@ -388,7 +414,7 @@ module RDF
|
|
388
414
|
end
|
389
415
|
|
390
416
|
##
|
391
|
-
# Returns `true` if this URI's path component isn't equal to `/`.
|
417
|
+
# Returns `true` if this URI is hierarchical and it's path component isn't equal to `/`.
|
392
418
|
#
|
393
419
|
# @example
|
394
420
|
# RDF::URI('http://example.org/').has_parent? #=> false
|
data/lib/rdf/nquads.rb
CHANGED
data/lib/rdf/ntriples/reader.rb
CHANGED
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module RDF::NTriples
|
2
3
|
##
|
3
4
|
# N-Triples serializer.
|
@@ -58,12 +59,14 @@ module RDF::NTriples
|
|
58
59
|
string
|
59
60
|
when string.respond_to?(:ascii_only?) && string.ascii_only?
|
60
61
|
StringIO.open do |buffer|
|
62
|
+
buffer.set_encoding(Encoding::ASCII) if buffer.respond_to?(:set_encoding)
|
61
63
|
string.each_byte { |u| buffer << escape_ascii(u, encoding) }
|
62
64
|
buffer.string
|
63
65
|
end
|
64
66
|
when string.respond_to?(:each_char) && encoding && encoding != Encoding::ASCII
|
65
67
|
# Not encoding UTF-8 characters
|
66
68
|
StringIO.open do |buffer|
|
69
|
+
buffer.set_encoding(encoding) if buffer.respond_to?(:set_encoding)
|
67
70
|
string.each_char do |u|
|
68
71
|
buffer << case u.ord
|
69
72
|
when (0x00..0x7F)
|
@@ -77,17 +80,19 @@ module RDF::NTriples
|
|
77
80
|
when string.respond_to?(:each_codepoint)
|
78
81
|
# Encode ASCII && UTF-8 characters
|
79
82
|
StringIO.open do |buffer|
|
83
|
+
buffer.set_encoding(Encoding::ASCII) if buffer.respond_to?(:set_encoding)
|
80
84
|
string.each_codepoint { |u| buffer << escape_unicode(u, encoding) }
|
81
85
|
buffer.string
|
82
86
|
end
|
83
87
|
else # works in Ruby 1.8.x, too
|
84
88
|
# Encode ASCII && UTF-8 characters
|
85
89
|
StringIO.open do |buffer|
|
90
|
+
buffer.set_encoding(Encoding::ASCII) if buffer.respond_to?(:set_encoding)
|
86
91
|
string.scan(/./mu) { |c| buffer << escape_unicode(u = c.unpack('U*').first, encoding) }
|
87
92
|
buffer.string
|
88
93
|
end
|
89
94
|
end
|
90
|
-
ret.respond_to?(:
|
95
|
+
ret.respond_to?(:encode) && encoding && ret.encoding != encoding ? ret.encode(encoding) : ret
|
91
96
|
end
|
92
97
|
|
93
98
|
##
|
data/lib/rdf/reader.rb
CHANGED
@@ -488,7 +488,7 @@ module RDF
|
|
488
488
|
@line = @line_rest || @input.readline
|
489
489
|
@line, @line_rest = @line.split("\r", 2)
|
490
490
|
@line = @line.to_s.chomp
|
491
|
-
@line.
|
491
|
+
@line.encode!(encoding) if @line.respond_to?(:encode!)
|
492
492
|
@line
|
493
493
|
end
|
494
494
|
|
data/lib/rdf/util/file.rb
CHANGED
@@ -27,7 +27,8 @@ module RDF; module Util
|
|
27
27
|
# @param [Hash{Symbol => Object}] options
|
28
28
|
# options are ignored in this implementation. Applications are encouraged
|
29
29
|
# to override this implementation to provide more control over HTTP
|
30
|
-
# headers and redirect following.
|
30
|
+
# headers and redirect following. If opening as a file,
|
31
|
+
# options are passed to `Kernel.open`.
|
31
32
|
# @option options [Array, String] :headers
|
32
33
|
# HTTP Request headers, passed to Kernel.open. (Ruby >= 1.9 only)
|
33
34
|
# @return [IO] File stream
|
@@ -37,10 +38,14 @@ module RDF; module Util
|
|
37
38
|
filename_or_url = $1 if filename_or_url.to_s.match(/^file:(.*)$/)
|
38
39
|
if RUBY_VERSION < "1.9"
|
39
40
|
Kernel.open(filename_or_url.to_s, &block)
|
41
|
+
elsif filename_or_url.to_s =~ /^#{RDF::URI::SCHEME}/
|
42
|
+
# Open as a URL
|
43
|
+
headers = options.fetch(:headers, {})
|
44
|
+
headers['Accept'] ||= (RDF::Format.reader_types + %w(*/*;q=0.1)).join(", ")
|
45
|
+
Kernel.open(filename_or_url.to_s, headers, &block)
|
40
46
|
else
|
41
|
-
|
42
|
-
|
43
|
-
Kernel.open(filename_or_url.to_s, options[:headers], &block)
|
47
|
+
# Open as a file, passing any options
|
48
|
+
Kernel.open(filename_or_url, "r", options, &block)
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end # File
|
data/lib/rdf/writer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
module RDF
|
2
3
|
##
|
3
4
|
# The base class for RDF serializers.
|
@@ -299,7 +300,7 @@ module RDF
|
|
299
300
|
#
|
300
301
|
# @return [Encoding]
|
301
302
|
def encoding
|
302
|
-
return nil unless "".respond_to?(:
|
303
|
+
return nil unless "".respond_to?(:encode!)
|
303
304
|
case @options[:encoding]
|
304
305
|
when String, Symbol
|
305
306
|
Encoding.find(@options[:encoding].to_s)
|
@@ -474,7 +475,7 @@ module RDF
|
|
474
475
|
##
|
475
476
|
# @return [void]
|
476
477
|
def puts(*args)
|
477
|
-
@output.puts(*args.map {|s| s.respond_to?(:
|
478
|
+
@output.puts(*args.map {|s| s.respond_to?(:encode!) ? s.encode!(encoding) : s})
|
478
479
|
end
|
479
480
|
|
480
481
|
##
|
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: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|