rdf 3.1.15 → 3.2.4
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 +4 -4
- data/README.md +40 -40
- data/VERSION +1 -1
- data/lib/rdf/mixin/countable.rb +5 -1
- data/lib/rdf/mixin/enumerable.rb +13 -1
- data/lib/rdf/mixin/queryable.rb +13 -1
- data/lib/rdf/model/list.rb +1 -1
- data/lib/rdf/model/literal/double.rb +1 -0
- data/lib/rdf/model/literal.rb +6 -12
- data/lib/rdf/model/statement.rb +3 -1
- data/lib/rdf/model/uri.rb +37 -8
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples/reader.rb +7 -7
- data/lib/rdf/ntriples/writer.rb +1 -1
- data/lib/rdf/reader.rb +1 -1
- data/lib/rdf/repository.rb +18 -94
- data/lib/rdf/transaction.rb +76 -2
- data/lib/rdf/util/file.rb +2 -2
- data/lib/rdf/util/logger.rb +8 -5
- data/lib/rdf/vocab/owl.rb +450 -445
- data/lib/rdf/vocab/rdfs.rb +89 -88
- data/lib/rdf/vocab/writer.rb +84 -51
- data/lib/rdf/vocab/xsd.rb +249 -249
- data/lib/rdf/vocabulary.rb +148 -137
- data/lib/rdf/writer.rb +2 -2
- data/lib/rdf.rb +0 -3
- metadata +22 -37
- data/lib/rdf/mixin/enumerator.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fac2b932398cb302e6b2ecf300e6508879ed43314c52822d7a7ae9482127ea05
|
4
|
+
data.tar.gz: 6f78f54676b45f1bfd4767b30b545ec3016de440fcb8d5803ead213eed0e799d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa02358aa8f3362695cd433767c966a5c47fc3ba4c4bc8b95952e207dbf1e693a3468ea75735c34461d012b9efcd8f72e842d007e4dd1239b26d480d9e4f3f4c
|
7
|
+
data.tar.gz: e524ebef2e88903b3c8b0a48aa7b15b843924a8f6bc97fe06f524378d101409b1d88c07756b6a1be8002a38648b03d4ab362b6033f53bd810d05cc6dee141194
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
This is a pure-Ruby library for working with [Resource Description Framework
|
4
4
|
(RDF)][RDF] data.
|
5
5
|
|
6
|
-
* <https://ruby-rdf.github.
|
6
|
+
* <https://ruby-rdf.github.io/rdf>
|
7
7
|
|
8
8
|
[](https://badge.fury.io/rb/rdf)
|
9
9
|
[](https://github.com/ruby-rdf/rdf/actions?query=workflow%3ACI)
|
@@ -141,11 +141,11 @@ or
|
|
141
141
|
### Reading RDF data in the [N-Triples][] format
|
142
142
|
|
143
143
|
require 'rdf/ntriples'
|
144
|
-
graph = RDF::Graph.load("https://ruby-rdf.github.
|
144
|
+
graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nt")
|
145
145
|
|
146
146
|
or
|
147
147
|
|
148
|
-
RDF::Reader.open("https://ruby-rdf.github.
|
148
|
+
RDF::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nt") do |reader|
|
149
149
|
reader.each_statement do |statement|
|
150
150
|
puts statement.inspect
|
151
151
|
end
|
@@ -160,13 +160,13 @@ MimeType or file extension, where available.
|
|
160
160
|
|
161
161
|
require 'rdf/nquads'
|
162
162
|
|
163
|
-
graph = RDF::Graph.load("https://ruby-rdf.github.
|
163
|
+
graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nq", format: :nquads)
|
164
164
|
|
165
165
|
A specific sub-type of Reader can also be invoked directly:
|
166
166
|
|
167
167
|
require 'rdf/nquads'
|
168
168
|
|
169
|
-
RDF::NQuads::Reader.open("https://ruby-rdf.github.
|
169
|
+
RDF::NQuads::Reader.open("https://ruby-rdf.github.io/rdf/etc/doap.nq") do |reader|
|
170
170
|
reader.each_statement do |statement|
|
171
171
|
puts statement.inspect
|
172
172
|
end
|
@@ -220,7 +220,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
|
|
220
220
|
|
221
221
|
require 'rdf/ntriples'
|
222
222
|
|
223
|
-
graph = RDF::Graph.load("https://ruby-rdf.github.
|
223
|
+
graph = RDF::Graph.load("https://ruby-rdf.github.io/rdf/etc/doap.nt")
|
224
224
|
query = RDF::Query.new({
|
225
225
|
person: {
|
226
226
|
RDF.type => FOAF.Person,
|
@@ -295,7 +295,7 @@ Readers support a boolean valued `rdfstar` option.
|
|
295
295
|
|
296
296
|
## Documentation
|
297
297
|
|
298
|
-
<https://
|
298
|
+
<https://ruby-rdf.github.io/rdf>
|
299
299
|
|
300
300
|
### RDF Object Model
|
301
301
|
|
@@ -309,7 +309,7 @@ Readers support a boolean valued `rdfstar` option.
|
|
309
309
|
* {RDF::Literal::Double}
|
310
310
|
* {RDF::Literal::Integer}
|
311
311
|
* {RDF::Literal::Time}
|
312
|
-
* [RDF::XSD](https://
|
312
|
+
* [RDF::XSD](https://ruby-rdf.github.io/rdf-xsd) (extension)
|
313
313
|
* {RDF::Resource}
|
314
314
|
* {RDF::Node}
|
315
315
|
* {RDF::URI}
|
@@ -371,10 +371,10 @@ from BNode identity (i.e., they each entail the other)
|
|
371
371
|
* {RDF::Mutable}
|
372
372
|
* {RDF::Durable}
|
373
373
|
* {RDF::Transaction}
|
374
|
-
* [RDF::AllegroGraph](https://
|
375
|
-
* [RDF::Mongo](https://
|
376
|
-
* [RDF::DataObjects](https://
|
377
|
-
* [RDF::Sesame](https://
|
374
|
+
* [RDF::AllegroGraph](https://ruby-rdf.github.io/rdf-agraph) (extension)
|
375
|
+
* [RDF::Mongo](https://ruby-rdf.github.io/rdf-mongo) (extension)
|
376
|
+
* [RDF::DataObjects](https://ruby-rdf.github.io/rdf-do) (extension)
|
377
|
+
* [RDF::Sesame](https://ruby-rdf.github.io/rdf-sesame) (extension)
|
378
378
|
|
379
379
|
### RDF Querying
|
380
380
|
|
@@ -384,7 +384,7 @@ from BNode identity (i.e., they each entail the other)
|
|
384
384
|
* {RDF::Query::Solution}
|
385
385
|
* {RDF::Query::Solutions}
|
386
386
|
* {RDF::Query::Variable}
|
387
|
-
* [SPARQL](https://
|
387
|
+
* [SPARQL](https://ruby-rdf.github.io/sparql) (extension)
|
388
388
|
|
389
389
|
|
390
390
|
### RDF Vocabularies
|
@@ -398,16 +398,16 @@ from BNode identity (i.e., they each entail the other)
|
|
398
398
|
|
399
399
|
## Dependencies
|
400
400
|
|
401
|
-
* [Ruby](https://ruby-lang.org/) (>= 2.
|
401
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.6)
|
402
402
|
* [LinkHeader][] (>= 0.0.8)
|
403
|
-
* Soft dependency on [RestClient][] (>= 1
|
403
|
+
* Soft dependency on [RestClient][] (>= 2.1)
|
404
404
|
|
405
405
|
## Installation
|
406
406
|
|
407
407
|
The recommended installation method is via [RubyGems](https://rubygems.org/).
|
408
408
|
To install the latest official release of RDF.rb, do:
|
409
409
|
|
410
|
-
% [sudo] gem install rdf # Ruby 2+
|
410
|
+
% [sudo] gem install rdf # Ruby 2.6+
|
411
411
|
|
412
412
|
## Download
|
413
413
|
|
@@ -422,7 +422,7 @@ follows:
|
|
422
422
|
|
423
423
|
## Resources
|
424
424
|
|
425
|
-
* <https://
|
425
|
+
* <https://ruby-rdf.github.io/rdf>
|
426
426
|
* <https://github.com/ruby-rdf/rdf>
|
427
427
|
* <https://rubygems.org/gems/rdf>
|
428
428
|
* <https://www.ohloh.net/p/rdf>
|
@@ -486,33 +486,33 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
486
486
|
[YARD]: https://yardoc.org/
|
487
487
|
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
488
488
|
[PDD]: https://unlicense.org/#unlicensing-contributions
|
489
|
-
[JSONLD doc]: https://
|
490
|
-
[LinkedData doc]: https://
|
491
|
-
[Microdata doc]: https://
|
492
|
-
[N3 doc]: https://
|
493
|
-
[RDFa doc]: https://
|
494
|
-
[RDFXML doc]: https://
|
495
|
-
[Turtle doc]: https://
|
496
|
-
[SPARQL doc]: https://
|
489
|
+
[JSONLD doc]: https://ruby-rdf.github.io/json-ld
|
490
|
+
[LinkedData doc]: https://ruby-rdf.github.io/linkeddata
|
491
|
+
[Microdata doc]: https://ruby-rdf.github.io/rdf-microdata
|
492
|
+
[N3 doc]: https://ruby-rdf.github.io/rdf-n3
|
493
|
+
[RDFa doc]: https://ruby-rdf.github.io/rdf-rdfa
|
494
|
+
[RDFXML doc]: https://ruby-rdf.github.io/rdf-rdfxml
|
495
|
+
[Turtle doc]: https://ruby-rdf.github.io/rdf-turtle
|
496
|
+
[SPARQL doc]: https://ruby-rdf.github.io/sparql
|
497
497
|
[RDF 1.0]: https://www.w3.org/TR/2004/REC-rdf-concepts-20040210/
|
498
498
|
[RDF 1.1]: https://www.w3.org/TR/rdf11-concepts/
|
499
499
|
[SPARQL 1.1]: https://www.w3.org/TR/sparql11-query/
|
500
|
-
[RDF.rb]: https://ruby-rdf.github.
|
501
|
-
[RDF::DO]: https://ruby-rdf.github.
|
502
|
-
[RDF::Mongo]: https://ruby-rdf.github.
|
503
|
-
[RDF::Sesame]: https://ruby-rdf.github.
|
504
|
-
[RDF::JSON]: https://ruby-rdf.github.
|
505
|
-
[RDF::Microdata]: https://ruby-rdf.github.
|
506
|
-
[RDF::N3]: https://ruby-rdf.github.
|
507
|
-
[RDF::RDFa]: https://ruby-rdf.github.
|
508
|
-
[RDF::RDFXML]: https://ruby-rdf.github.
|
509
|
-
[RDF::TriG]: https://ruby-rdf.github.
|
510
|
-
[RDF::TriX]: https://ruby-rdf.github.
|
511
|
-
[RDF::Turtle]: https://ruby-rdf.github.
|
512
|
-
[RDF::Raptor]: https://ruby-rdf.github.
|
500
|
+
[RDF.rb]: https://ruby-rdf.github.io/
|
501
|
+
[RDF::DO]: https://ruby-rdf.github.io/rdf-do
|
502
|
+
[RDF::Mongo]: https://ruby-rdf.github.io/rdf-mongo
|
503
|
+
[RDF::Sesame]: https://ruby-rdf.github.io/rdf-sesame
|
504
|
+
[RDF::JSON]: https://ruby-rdf.github.io/rdf-json
|
505
|
+
[RDF::Microdata]: https://ruby-rdf.github.io/rdf-microdata
|
506
|
+
[RDF::N3]: https://ruby-rdf.github.io/rdf-n3
|
507
|
+
[RDF::RDFa]: https://ruby-rdf.github.io/rdf-rdfa
|
508
|
+
[RDF::RDFXML]: https://ruby-rdf.github.io/rdf-rdfxml
|
509
|
+
[RDF::TriG]: https://ruby-rdf.github.io/rdf-trig
|
510
|
+
[RDF::TriX]: https://ruby-rdf.github.io/rdf-trix
|
511
|
+
[RDF::Turtle]: https://ruby-rdf.github.io/rdf-turtle
|
512
|
+
[RDF::Raptor]: https://ruby-rdf.github.io/rdf-raptor
|
513
513
|
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
|
514
|
-
[LinkedData]: https://ruby-rdf.github.
|
515
|
-
[JSON::LD]: https://ruby-rdf.github.
|
514
|
+
[LinkedData]: https://ruby-rdf.github.io/linkeddata
|
515
|
+
[JSON::LD]: https://ruby-rdf.github.io/json-ld
|
516
516
|
[RestClient]: https://rubygems.org/gems/rest-client
|
517
517
|
[RestClient Components]: https://rubygems.org/gems/rest-client-components
|
518
518
|
[Rack::Cache]: https://rtomayko.github.io/rack-cache/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.4
|
data/lib/rdf/mixin/countable.rb
CHANGED
@@ -2,9 +2,13 @@ module RDF
|
|
2
2
|
##
|
3
3
|
# @since 0.2.0
|
4
4
|
module Countable
|
5
|
-
autoload :Enumerator, 'rdf/mixin/enumerator'
|
6
5
|
extend RDF::Util::Aliasing::LateBound
|
7
6
|
|
7
|
+
# Extends Enumerator with {Countable}, which is used by {Countable#enum_for}
|
8
|
+
class Enumerator < ::Enumerator
|
9
|
+
include RDF::Countable
|
10
|
+
end
|
11
|
+
|
8
12
|
##
|
9
13
|
# Returns `true` if `self` contains no RDF statements.
|
10
14
|
#
|
data/lib/rdf/mixin/enumerable.rb
CHANGED
@@ -57,11 +57,23 @@ module RDF
|
|
57
57
|
# @see RDF::Graph
|
58
58
|
# @see RDF::Repository
|
59
59
|
module Enumerable
|
60
|
-
autoload :Enumerator, 'rdf/mixin/enumerator'
|
61
60
|
extend RDF::Util::Aliasing::LateBound
|
62
61
|
include ::Enumerable
|
63
62
|
include RDF::Countable # NOTE: must come after ::Enumerable
|
64
63
|
|
64
|
+
# Extends Enumerator with {Queryable} and {Enumerable}, which is used by {Enumerable#each_statement} and {Queryable#enum_for}
|
65
|
+
class Enumerator < ::Enumerator
|
66
|
+
include RDF::Queryable
|
67
|
+
include RDF::Enumerable
|
68
|
+
|
69
|
+
##
|
70
|
+
# @return [Array]
|
71
|
+
# @note Make sure returned arrays are also queryable
|
72
|
+
def to_a
|
73
|
+
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
##
|
66
78
|
# Returns `true` if this enumerable supports the given `feature`.
|
67
79
|
#
|
data/lib/rdf/mixin/queryable.rb
CHANGED
@@ -9,9 +9,21 @@ module RDF
|
|
9
9
|
# @see RDF::Graph
|
10
10
|
# @see RDF::Repository
|
11
11
|
module Queryable
|
12
|
-
autoload :Enumerator, 'rdf/mixin/enumerator'
|
13
12
|
include ::Enumerable
|
14
13
|
|
14
|
+
# Extends Enumerator with {Queryable} and {Enumerable}, which is used by {Enumerable#each_statement} and {Queryable#enum_for}
|
15
|
+
class Enumerator < ::Enumerator
|
16
|
+
include RDF::Queryable
|
17
|
+
include RDF::Enumerable
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [Array]
|
21
|
+
# @note Make sure returned arrays are also queryable
|
22
|
+
def to_a
|
23
|
+
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
##
|
16
28
|
# Queries `self` for RDF statements matching the given `pattern`.
|
17
29
|
#
|
data/lib/rdf/model/list.rb
CHANGED
@@ -43,6 +43,7 @@ module RDF; class Literal
|
|
43
43
|
# Can't use simple %f transformation due to special requirements from
|
44
44
|
# N3 tests in representation
|
45
45
|
@string = case
|
46
|
+
when @object.nil? then 'NaN'
|
46
47
|
when @object.nan? then 'NaN'
|
47
48
|
when @object.infinite? then @object.to_s[0...-'inity'.length].upcase
|
48
49
|
when @object.zero? then '0.0E0'
|
data/lib/rdf/model/literal.rb
CHANGED
@@ -166,12 +166,12 @@ module RDF
|
|
166
166
|
@object = value.freeze
|
167
167
|
@string = lexical if lexical
|
168
168
|
@string = value if !defined?(@string) && value.is_a?(String)
|
169
|
-
@string = @string.encode(Encoding::UTF_8).freeze if
|
170
|
-
@object = @string if
|
169
|
+
@string = @string.encode(Encoding::UTF_8).freeze if instance_variable_defined?(:@string)
|
170
|
+
@object = @string if instance_variable_defined?(:@string) && @object.is_a?(String)
|
171
171
|
@language = language.to_s.downcase.to_sym if language
|
172
172
|
@datatype = RDF::URI(datatype).freeze if datatype
|
173
173
|
@datatype ||= self.class.const_get(:DATATYPE) if self.class.const_defined?(:DATATYPE)
|
174
|
-
@datatype ||= @language ? RDF.langString : RDF::URI("http://www.w3.org/2001/XMLSchema#string")
|
174
|
+
@datatype ||= instance_variable_defined?(:@language) && @language ? RDF.langString : RDF::URI("http://www.w3.org/2001/XMLSchema#string")
|
175
175
|
end
|
176
176
|
|
177
177
|
##
|
@@ -179,7 +179,7 @@ module RDF
|
|
179
179
|
#
|
180
180
|
# @return [String]
|
181
181
|
def value
|
182
|
-
@string || to_s
|
182
|
+
instance_variable_defined?(:@string) && @string || to_s
|
183
183
|
end
|
184
184
|
|
185
185
|
##
|
@@ -431,12 +431,10 @@ module RDF
|
|
431
431
|
end
|
432
432
|
|
433
433
|
##
|
434
|
-
# Returns `true` if the
|
435
|
-
# return false instead of raise a type error.
|
434
|
+
# Returns `true` if the literals are comperable.
|
436
435
|
#
|
437
436
|
# Used for <=> operator.
|
438
437
|
#
|
439
|
-
# This behavior is intuited from SPARQL data-r2/expr-equal/eq-2-2
|
440
438
|
# @return [Boolean]
|
441
439
|
def comperable_datatype2?(other)
|
442
440
|
case self
|
@@ -445,13 +443,9 @@ module RDF
|
|
445
443
|
when RDF::Literal::Numeric, RDF::Literal::Boolean
|
446
444
|
true
|
447
445
|
else
|
448
|
-
|
449
|
-
self.language? || other.language? ||
|
450
|
-
self.datatype == other.datatype
|
446
|
+
false
|
451
447
|
end
|
452
448
|
else
|
453
|
-
self.plain? || other.plain? ||
|
454
|
-
self.language? || other.language? ||
|
455
449
|
self.datatype == other.datatype
|
456
450
|
end
|
457
451
|
end
|
data/lib/rdf/model/statement.rb
CHANGED
@@ -71,6 +71,7 @@ module RDF
|
|
71
71
|
# @option options [RDF::Term] :graph_name (nil)
|
72
72
|
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
|
73
73
|
# @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
|
74
|
+
# @option options [Boolean] :quoted used as a marker to record that this statement quoted and appears as the subject or object of another RDF::Statement.
|
74
75
|
# @return [RDF::Statement]
|
75
76
|
#
|
76
77
|
# @overload initialize(subject, predicate, object, **options)
|
@@ -83,6 +84,7 @@ module RDF
|
|
83
84
|
# @option options [RDF::Term] :graph_name (nil)
|
84
85
|
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
|
85
86
|
# @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
|
87
|
+
# @option options [Boolean] :quoted used as a marker to record that this statement quoted and appears as the subject or object of another RDF::Statement.
|
86
88
|
# @return [RDF::Statement]
|
87
89
|
def initialize(subject = nil, predicate = nil, object = nil, options = {})
|
88
90
|
if subject.is_a?(Hash)
|
@@ -209,7 +211,7 @@ module RDF
|
|
209
211
|
##
|
210
212
|
# @return [Boolean]
|
211
213
|
def quoted?
|
212
|
-
|
214
|
+
!!@options[:quoted]
|
213
215
|
end
|
214
216
|
|
215
217
|
##
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -111,6 +111,11 @@ module RDF
|
|
111
111
|
tag tel turn turns tv urn javascript
|
112
112
|
).freeze
|
113
113
|
|
114
|
+
# Characters in a PName which must be escaped
|
115
|
+
# Note: not all reserved characters need to be escaped in SPARQL/Turtle, but they must be unescaped when encountered
|
116
|
+
PN_ESCAPE_CHARS = /[~\.!\$&'\(\)\*\+,;=\/\?\#@%]/.freeze
|
117
|
+
PN_ESCAPES = /\\#{Regexp.union(PN_ESCAPE_CHARS, /[\-_]/)}/.freeze
|
118
|
+
|
114
119
|
##
|
115
120
|
# Cache size may be set through {RDF.config} using `uri_cache_size`.
|
116
121
|
#
|
@@ -621,16 +626,26 @@ module RDF
|
|
621
626
|
end
|
622
627
|
|
623
628
|
##
|
624
|
-
# Returns a qualified name (QName) for this URI based on available vocabularies, if possible.
|
629
|
+
# Returns a qualified name (QName) as a tuple of `[prefix, suffix]` for this URI based on available vocabularies, if possible.
|
625
630
|
#
|
626
631
|
# @example
|
627
632
|
# RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname #=> [:rdfs, nil]
|
628
633
|
# RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname #=> [:rdfs, :label]
|
629
634
|
# RDF::RDFS.label.qname #=> [:rdfs, :label]
|
630
|
-
#
|
631
|
-
#
|
632
|
-
|
633
|
-
|
635
|
+
# RDF::Vocab::DC.title.qname(
|
636
|
+
# prefixes: {dcterms: 'http://purl.org/dc/terms/'}) #=> [:dcterms, :title]
|
637
|
+
#
|
638
|
+
# @note within this software, the term QName is used to describe the tuple of prefix and suffix for a given IRI, where the prefix identifies some defined vocabulary. This somewhat contrasts with the notion of a [Qualified Name](https://www.w3.org/TR/2006/REC-xml-names11-20060816/#ns-qualnames) from XML, which are a subset of Prefixed Names.
|
639
|
+
#
|
640
|
+
# @param [Hash{Symbol => String}] prefixes
|
641
|
+
# Explicit set of prefixes to look for matches, defaults to loaded vocabularies.
|
642
|
+
# @return [Array(Symbol, Symbol)] or `nil` if no QName found. The suffix component will not have [reserved characters](https://www.w3.org/TR/turtle/#reserved) escaped.
|
643
|
+
def qname(prefixes: nil)
|
644
|
+
if prefixes
|
645
|
+
prefixes.each do |prefix, uri|
|
646
|
+
return [prefix, self.to_s[uri.length..-1].to_sym] if self.start_with?(uri)
|
647
|
+
end
|
648
|
+
elsif self.to_s =~ %r([:/#]([^:/#]*)$)
|
634
649
|
local_name = $1
|
635
650
|
vocab_uri = local_name.empty? ? self.to_s : self.to_s[0...-(local_name.length)]
|
636
651
|
Vocabulary.each do |vocab|
|
@@ -653,11 +668,25 @@ module RDF
|
|
653
668
|
end
|
654
669
|
|
655
670
|
##
|
656
|
-
# Returns a
|
671
|
+
# Returns a Prefixed Name (PName) or the full IRI with any [reserved characters](https://www.w3.org/TR/turtle/#reserved) in the suffix escaped.
|
672
|
+
#
|
673
|
+
# @example Using a custom prefix for creating a PNname.
|
674
|
+
# RDF::URI('http://purl.org/dc/terms/creator').
|
675
|
+
# pname(prefixes: {dcterms: 'http://purl.org/dc/terms/'})
|
676
|
+
# #=> "dcterms:creator"
|
657
677
|
#
|
678
|
+
# @param [Hash{Symbol => String}] prefixes
|
679
|
+
# Explicit set of prefixes to look for matches, defaults to loaded vocabularies.
|
658
680
|
# @return [String] or `nil`
|
659
|
-
|
660
|
-
|
681
|
+
# @see #qname
|
682
|
+
# @see https://www.w3.org/TR/rdf-sparql-query/#prefNames
|
683
|
+
def pname(prefixes: nil)
|
684
|
+
q = self.qname(prefixes: prefixes)
|
685
|
+
return self.to_s unless q
|
686
|
+
prefix, suffix = q
|
687
|
+
suffix = suffix.to_s.gsub(PN_ESCAPE_CHARS) {|c| "\\#{c}"} if
|
688
|
+
suffix.to_s.match?(PN_ESCAPE_CHARS)
|
689
|
+
[prefix, suffix].join(":")
|
661
690
|
end
|
662
691
|
|
663
692
|
##
|
data/lib/rdf/nquads.rb
CHANGED
@@ -69,9 +69,9 @@ module RDF
|
|
69
69
|
|
70
70
|
begin
|
71
71
|
unless blank? || read_comment
|
72
|
-
subject = read_uriref || read_node ||
|
72
|
+
subject = read_uriref || read_node || read_quotedTriple || fail_subject
|
73
73
|
predicate = read_uriref(intern: true) || fail_predicate
|
74
|
-
object = read_uriref || read_node || read_literal ||
|
74
|
+
object = read_uriref || read_node || read_literal || read_quotedTriple || fail_object
|
75
75
|
graph_name = read_uriref || read_node
|
76
76
|
if validate? && !read_eos
|
77
77
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
data/lib/rdf/ntriples/reader.rb
CHANGED
@@ -213,7 +213,7 @@ module RDF::NTriples
|
|
213
213
|
begin
|
214
214
|
read_statement
|
215
215
|
rescue RDF::ReaderError
|
216
|
-
value = read_uriref || read_node || read_literal ||
|
216
|
+
value = read_uriref || read_node || read_literal || read_quotedTriple
|
217
217
|
log_recover
|
218
218
|
value
|
219
219
|
end
|
@@ -229,9 +229,9 @@ module RDF::NTriples
|
|
229
229
|
|
230
230
|
begin
|
231
231
|
unless blank? || read_comment
|
232
|
-
subject = read_uriref || read_node ||
|
232
|
+
subject = read_uriref || read_node || read_quotedTriple || fail_subject
|
233
233
|
predicate = read_uriref(intern: true) || fail_predicate
|
234
|
-
object = read_uriref || read_node || read_literal ||
|
234
|
+
object = read_uriref || read_node || read_literal || read_quotedTriple || fail_object
|
235
235
|
|
236
236
|
if validate? && !read_eos
|
237
237
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
@@ -247,15 +247,15 @@ module RDF::NTriples
|
|
247
247
|
|
248
248
|
##
|
249
249
|
# @return [RDF::Statement]
|
250
|
-
def
|
250
|
+
def read_quotedTriple
|
251
251
|
if @options[:rdfstar] && match(ST_START)
|
252
|
-
subject = read_uriref || read_node ||
|
252
|
+
subject = read_uriref || read_node || read_quotedTriple || fail_subject
|
253
253
|
predicate = read_uriref(intern: true) || fail_predicate
|
254
|
-
object = read_uriref || read_node || read_literal ||
|
254
|
+
object = read_uriref || read_node || read_literal || read_quotedTriple || fail_object
|
255
255
|
if !match(ST_END)
|
256
256
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
257
257
|
end
|
258
|
-
RDF::Statement.new(subject, predicate, object)
|
258
|
+
RDF::Statement.new(subject, predicate, object, quoted: true)
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
data/lib/rdf/ntriples/writer.rb
CHANGED
@@ -227,7 +227,7 @@ module RDF::NTriples
|
|
227
227
|
# @param [RDF::Statement] statement
|
228
228
|
# @param [Hash{Symbol => Object}] options ({})
|
229
229
|
# @return [String]
|
230
|
-
def
|
230
|
+
def format_quotedTriple(statement, **options)
|
231
231
|
"<<%s %s %s>>" % statement.to_a.map { |value| format_term(value, **options) }
|
232
232
|
end
|
233
233
|
##
|
data/lib/rdf/reader.rb
CHANGED
@@ -647,7 +647,7 @@ module RDF
|
|
647
647
|
##
|
648
648
|
# @return [String]
|
649
649
|
def readline
|
650
|
-
@line = @line_rest || @input.readline
|
650
|
+
@line = instance_variable_defined?(:@line_rest) && @line_rest || @input.readline
|
651
651
|
@line, @line_rest = @line.split("\r", 2)
|
652
652
|
@line = String.new if @line.nil? # not frozen
|
653
653
|
@line.chomp!
|