rdf 1.1.0.p0 → 1.1.0.p1
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.
- checksums.yaml +8 -8
- data/README +8 -6
- data/VERSION +1 -1
- data/lib/rdf.rb +8 -8
- data/lib/rdf/mixin/mutable.rb +4 -1
- data/lib/rdf/model/literal.rb +8 -3
- data/lib/rdf/model/statement.rb +12 -0
- data/lib/rdf/model/term.rb +0 -9
- data/lib/rdf/model/uri.rb +596 -71
- data/lib/rdf/model/value.rb +10 -1
- data/lib/rdf/ntriples/format.rb +1 -0
- data/lib/rdf/ntriples/reader.rb +3 -0
- data/lib/rdf/ntriples/writer.rb +19 -6
- data/lib/rdf/query/pattern.rb +0 -23
- data/lib/rdf/reader.rb +8 -6
- data/lib/rdf/writer.rb +11 -3
- metadata +5 -21
- data/lib/rdf/model/literal/string.rb +0 -38
- data/lib/rdf/model/literal/xml.rb +0 -41
data/lib/rdf/model/value.rb
CHANGED
@@ -103,7 +103,7 @@ module RDF
|
|
103
103
|
end
|
104
104
|
|
105
105
|
##
|
106
|
-
# Returns `true`
|
106
|
+
# Returns `true` this value is a {RDF::Query::Variable}, or is contains a variable.
|
107
107
|
#
|
108
108
|
# @return [Boolean]
|
109
109
|
# @since 0.1.7
|
@@ -111,6 +111,15 @@ 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
|
+
|
114
123
|
##
|
115
124
|
# Is this an anonymous value?
|
116
125
|
#
|
data/lib/rdf/ntriples/format.rb
CHANGED
@@ -15,6 +15,7 @@ module RDF::NTriples
|
|
15
15
|
# RDF::Format.for(:content_type => "text/plain")
|
16
16
|
#
|
17
17
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
18
|
+
# @see http://www.w3.org/TR/n-triples/
|
18
19
|
class Format < RDF::Format
|
19
20
|
content_type 'application/n-triples', :extension => :nt, :alias => ['text/plain']
|
20
21
|
content_encoding 'utf-8'
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -25,6 +25,7 @@ module RDF::NTriples
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
28
|
+
# @see http://www.w3.org/TR/n-triples/
|
28
29
|
class Reader < RDF::Reader
|
29
30
|
format RDF::NTriples::Format
|
30
31
|
|
@@ -239,6 +240,8 @@ module RDF::NTriples
|
|
239
240
|
uri.canonicalize! if canonicalize?
|
240
241
|
uri
|
241
242
|
end
|
243
|
+
rescue ArgumentError => e
|
244
|
+
raise RDF::ReaderError, "invalid URI"
|
242
245
|
end
|
243
246
|
|
244
247
|
##
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -35,6 +35,7 @@ module RDF::NTriples
|
|
35
35
|
# end
|
36
36
|
#
|
37
37
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
38
|
+
# @see http://www.w3.org/TR/n-triples/
|
38
39
|
class Writer < RDF::Writer
|
39
40
|
format RDF::NTriples::Format
|
40
41
|
|
@@ -43,6 +44,10 @@ module RDF::NTriples
|
|
43
44
|
ESCAPE_ASCII = /\A[\x00-\x7F]*\z/m.freeze
|
44
45
|
|
45
46
|
##
|
47
|
+
# Escape Literal and URI content. If encoding is ASCII, all unicode
|
48
|
+
# is escaped, otherwise only ASCII characters that must be escaped are
|
49
|
+
# escaped.
|
50
|
+
#
|
46
51
|
# @param [String] string
|
47
52
|
# @param [Encoding] encoding
|
48
53
|
# @return [String]
|
@@ -53,7 +58,7 @@ module RDF::NTriples
|
|
53
58
|
string
|
54
59
|
when string.ascii_only?
|
55
60
|
StringIO.open do |buffer|
|
56
|
-
string.each_byte { |u| buffer << escape_ascii(u) }
|
61
|
+
string.each_byte { |u| buffer << escape_ascii(u, encoding) }
|
57
62
|
buffer.string
|
58
63
|
end
|
59
64
|
when encoding && encoding != Encoding::ASCII
|
@@ -62,7 +67,7 @@ module RDF::NTriples
|
|
62
67
|
string.each_char do |u|
|
63
68
|
buffer << case u.ord
|
64
69
|
when (0x00..0x7F)
|
65
|
-
escape_ascii(u)
|
70
|
+
escape_ascii(u, encoding)
|
66
71
|
else
|
67
72
|
u
|
68
73
|
end
|
@@ -70,6 +75,7 @@ module RDF::NTriples
|
|
70
75
|
buffer.string
|
71
76
|
end
|
72
77
|
else
|
78
|
+
# Encode ASCII && UTF-8 characters
|
73
79
|
StringIO.open do |buffer|
|
74
80
|
string.each_codepoint { |u| buffer << escape_unicode(u, encoding) }
|
75
81
|
buffer.string
|
@@ -89,7 +95,7 @@ module RDF::NTriples
|
|
89
95
|
def self.escape_unicode(u, encoding)
|
90
96
|
case (u = u.ord)
|
91
97
|
when (0x00..0x7F) # ASCII 7-bit
|
92
|
-
escape_ascii(u)
|
98
|
+
escape_ascii(u, encoding)
|
93
99
|
when (0x80..0xFFFF) # Unicode BMP
|
94
100
|
escape_utf16(u)
|
95
101
|
when (0x10000..0x10FFFF) # Unicode
|
@@ -100,15 +106,22 @@ module RDF::NTriples
|
|
100
106
|
end
|
101
107
|
|
102
108
|
##
|
109
|
+
# Standard ASCII escape sequences. If encoding is ASCII, use Test-Cases
|
110
|
+
# sequences, otherwise, assume the test-cases escape sequences. Otherwise,
|
111
|
+
# the N-Triples recommendation includes `\b` and `\f` escape sequences.
|
112
|
+
#
|
103
113
|
# @param [Integer, #ord] u
|
104
114
|
# @return [String]
|
105
115
|
# @see http://www.w3.org/TR/rdf-testcases/#ntrip_strings
|
106
|
-
|
116
|
+
# @see http://www.w3.org/TR/n-triples/
|
117
|
+
def self.escape_ascii(u, encoding)
|
107
118
|
case (u = u.ord)
|
108
|
-
when (0x00..
|
119
|
+
when (0x00..0x07) then escape_utf16(u)
|
120
|
+
when (0x08) then (encoding && encoding == Encoding::ASCII ? escape_utf16(u) : "\\b")
|
109
121
|
when (0x09) then "\\t"
|
110
122
|
when (0x0A) then "\\n"
|
111
|
-
when (0x0B
|
123
|
+
when (0x0B) then escape_utf16(u)
|
124
|
+
when (0x0C) then (encoding && encoding == Encoding::ASCII ? escape_utf16(u) : "\\f")
|
112
125
|
when (0x0D) then "\\r"
|
113
126
|
when (0x0E..0x1F) then escape_utf16(u)
|
114
127
|
when (0x22) then "\\\""
|
data/lib/rdf/query/pattern.rb
CHANGED
@@ -67,29 +67,6 @@ module RDF; class Query
|
|
67
67
|
subject.nil? && predicate.nil? && object.nil? && context.nil?
|
68
68
|
end
|
69
69
|
|
70
|
-
##
|
71
|
-
# Returns `true` if this is a constant pattern, with all terms being
|
72
|
-
# either URIs, blank nodes, or literals.
|
73
|
-
#
|
74
|
-
# A constant pattern is structurally and functionally equivalent to an
|
75
|
-
# RDF statement.
|
76
|
-
#
|
77
|
-
# @return [Boolean] `true` or `false`
|
78
|
-
# @since 0.3.0
|
79
|
-
def constant?
|
80
|
-
!(variable?)
|
81
|
-
end
|
82
|
-
|
83
|
-
##
|
84
|
-
# Returns `true` if this is a variable pattern, with any term being
|
85
|
-
# `nil` or a variable.
|
86
|
-
#
|
87
|
-
# @return [Boolean] `true` or `false`
|
88
|
-
# @since 0.3.0
|
89
|
-
def variable?
|
90
|
-
subject.nil? || predicate.nil? || object.nil? || context.nil? || has_variables?
|
91
|
-
end
|
92
|
-
|
93
70
|
##
|
94
71
|
# Returns `true` if this pattern contains any variables.
|
95
72
|
#
|
data/lib/rdf/reader.rb
CHANGED
@@ -189,6 +189,7 @@ module RDF
|
|
189
189
|
@options[:canonicalize] ||= false
|
190
190
|
@options[:intern] ||= true
|
191
191
|
@options[:prefixes] ||= Hash.new
|
192
|
+
@options[:base_uri] ||= input.base_uri if input.respond_to?(:base_uri)
|
192
193
|
|
193
194
|
@input = case input
|
194
195
|
when String then StringIO.new(input)
|
@@ -362,6 +363,13 @@ module RDF
|
|
362
363
|
end
|
363
364
|
alias_method :close!, :close
|
364
365
|
|
366
|
+
##
|
367
|
+
# Current line number being processed. For formats that can associate generated {Statement} with a particular line number from input, this value reflects that line number.
|
368
|
+
# @return [Integer]
|
369
|
+
def lineno
|
370
|
+
@input.lineno
|
371
|
+
end
|
372
|
+
|
365
373
|
protected
|
366
374
|
|
367
375
|
##
|
@@ -465,12 +473,6 @@ module RDF
|
|
465
473
|
super
|
466
474
|
end
|
467
475
|
|
468
|
-
##
|
469
|
-
# @return [Integer]
|
470
|
-
def lineno
|
471
|
-
@input.lineno
|
472
|
-
end
|
473
|
-
|
474
476
|
##
|
475
477
|
# @private
|
476
478
|
# @return [String] The most recently read line of the input
|
data/lib/rdf/writer.rb
CHANGED
@@ -105,13 +105,18 @@ module RDF
|
|
105
105
|
##
|
106
106
|
# @param [RDF::Enumerable, #each] data
|
107
107
|
# the graph or repository to dump
|
108
|
-
# @param [IO, File] io
|
108
|
+
# @param [IO, File, String] io
|
109
109
|
# the output stream or file to write to
|
110
110
|
# @param [Hash{Symbol => Object}] options
|
111
111
|
# passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
|
112
112
|
# @return [void]
|
113
113
|
def self.dump(data, io = nil, options = {})
|
114
|
-
|
114
|
+
if io.is_a?(String)
|
115
|
+
io = File.open(io, 'w')
|
116
|
+
elsif io.respond_to?(:external_encoding) && io.external_encoding
|
117
|
+
options = {:encoding => io.external_encoding}.merge(options)
|
118
|
+
end
|
119
|
+
io.set_encoding(options[:encoding]) if io.respond_to?(:set_encoding) && options[:encoding]
|
115
120
|
method = data.respond_to?(:each_statement) ? :each_statement : :each
|
116
121
|
if io
|
117
122
|
new(io, options) do |writer|
|
@@ -138,9 +143,11 @@ module RDF
|
|
138
143
|
# @return [String]
|
139
144
|
# @raise [ArgumentError] if no block is provided
|
140
145
|
def self.buffer(*args, &block)
|
146
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
141
147
|
raise ArgumentError, "block expected" unless block_given?
|
142
148
|
|
143
149
|
StringIO.open do |buffer|
|
150
|
+
buffer.set_encoding(options[:encoding]) if options[:encoding]
|
144
151
|
self.new(buffer, *args) { |writer| block.call(writer) }
|
145
152
|
buffer.string
|
146
153
|
end
|
@@ -156,6 +163,7 @@ module RDF
|
|
156
163
|
# @return [RDF::Writer]
|
157
164
|
def self.open(filename, options = {}, &block)
|
158
165
|
File.open(filename, 'wb') do |file|
|
166
|
+
file.set_encoding(options[:encoding]) if options[:encoding]
|
159
167
|
format_options = options.dup
|
160
168
|
format_options[:file_name] ||= filename
|
161
169
|
self.for(options[:format] || format_options).new(file, options, &block)
|
@@ -436,7 +444,7 @@ module RDF
|
|
436
444
|
##
|
437
445
|
# @return [void]
|
438
446
|
def puts(*args)
|
439
|
-
@output.puts(*args)
|
447
|
+
@output.puts(*args.map {|s| s.force_encoding(encoding)})
|
440
448
|
end
|
441
449
|
|
442
450
|
##
|
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.1.0.
|
4
|
+
version: 1.1.0.p1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,36 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: addressable
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '2.2'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ! '>='
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '2.2'
|
29
15
|
- !ruby/object:Gem::Dependency
|
30
16
|
name: rdf-spec
|
31
17
|
requirement: !ruby/object:Gem::Requirement
|
32
18
|
requirements:
|
33
19
|
- - ~>
|
34
20
|
- !ruby/object:Gem::Version
|
35
|
-
version: 1.1.0
|
21
|
+
version: 1.1.0
|
36
22
|
type: :development
|
37
23
|
prerelease: false
|
38
24
|
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
requirements:
|
40
26
|
- - ~>
|
41
27
|
- !ruby/object:Gem::Version
|
42
|
-
version: 1.1.0
|
28
|
+
version: 1.1.0
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
30
|
name: rspec
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,10 +91,8 @@ files:
|
|
105
91
|
- lib/rdf/model/literal/double.rb
|
106
92
|
- lib/rdf/model/literal/integer.rb
|
107
93
|
- lib/rdf/model/literal/numeric.rb
|
108
|
-
- lib/rdf/model/literal/string.rb
|
109
94
|
- lib/rdf/model/literal/time.rb
|
110
95
|
- lib/rdf/model/literal/token.rb
|
111
|
-
- lib/rdf/model/literal/xml.rb
|
112
96
|
- lib/rdf/model/literal.rb
|
113
97
|
- lib/rdf/model/node.rb
|
114
98
|
- lib/rdf/model/resource.rb
|
@@ -170,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
154
|
requirements:
|
171
155
|
- - ! '>='
|
172
156
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.9.
|
157
|
+
version: 1.9.2
|
174
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
159
|
requirements:
|
176
160
|
- - ! '>'
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module RDF; class Literal
|
2
|
-
##
|
3
|
-
# A String literal.
|
4
|
-
#
|
5
|
-
# @see http://www.w3.org/TR/xmlschema-2/#string
|
6
|
-
# @since 0.3.11
|
7
|
-
class String < Literal
|
8
|
-
DATATYPE = XSD.string
|
9
|
-
GRAMMAR = nil
|
10
|
-
|
11
|
-
##
|
12
|
-
# @param [Object] value
|
13
|
-
# @option options [String] :lexical (nil)
|
14
|
-
def initialize(value, options = {})
|
15
|
-
@datatype = options[:datatype] || self.class.const_get(:DATATYPE)
|
16
|
-
@string = options[:lexical] if options.has_key?(:lexical)
|
17
|
-
@string ||= value if value.is_a?(String)
|
18
|
-
@object = value.to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
# Converts this literal into its canonical lexical representation.
|
23
|
-
#
|
24
|
-
# @return [RDF::Literal] `self`
|
25
|
-
# @see http://www.w3.org/TR/xml-exc-c14n/
|
26
|
-
def canonicalize!
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
# Returns the value as a string.
|
32
|
-
#
|
33
|
-
# @return [String]
|
34
|
-
def to_s
|
35
|
-
@string || @object
|
36
|
-
end
|
37
|
-
end # XML
|
38
|
-
end; end # RDF::Literal
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module RDF; class Literal
|
2
|
-
##
|
3
|
-
# An XML literal.
|
4
|
-
#
|
5
|
-
# This class exists mostly as a stub. See RDF::XSD gem for full support.
|
6
|
-
|
7
|
-
# @see https://github.com/ruby-rdf/rdf-xsd/blob/master/lib/rdf/xsd/xml.rb
|
8
|
-
# @see http://www.w3.org/TR/rdf-concepts/#section-XMLLiteral
|
9
|
-
# @see http://www.w3.org/TR/rdfa-core/#s_xml_literals
|
10
|
-
# @since 0.2.1
|
11
|
-
class XML < Literal
|
12
|
-
DATATYPE = RDF.XMLLiteral
|
13
|
-
GRAMMAR = nil
|
14
|
-
|
15
|
-
##
|
16
|
-
# @param [Object] value
|
17
|
-
# @option options [String] :lexical (nil)
|
18
|
-
def initialize(value, options = {})
|
19
|
-
@datatype = options[:datatype] || self.class.const_get(:DATATYPE)
|
20
|
-
@string = options[:lexical] if options.has_key?(:lexical)
|
21
|
-
@object = value # TODO: parse XML string using REXML
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Converts this literal into its canonical lexical representation.
|
26
|
-
#
|
27
|
-
# @return [RDF::Literal] `self`
|
28
|
-
# @see http://www.w3.org/TR/xml-exc-c14n/
|
29
|
-
def canonicalize!
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Returns the value as a string.
|
35
|
-
#
|
36
|
-
# @return [String]
|
37
|
-
def to_s
|
38
|
-
@string || @object.to_s
|
39
|
-
end
|
40
|
-
end # XML
|
41
|
-
end; end # RDF::Literal
|