rdf 3.2.3 → 3.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -37
- 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/date.rb +27 -82
- data/lib/rdf/model/literal/datetime.rb +22 -122
- data/lib/rdf/model/literal/decimal.rb +12 -0
- data/lib/rdf/model/literal/double.rb +20 -0
- data/lib/rdf/model/literal/integer.rb +6 -0
- data/lib/rdf/model/literal/numeric.rb +154 -4
- data/lib/rdf/model/literal/temporal.rb +310 -0
- data/lib/rdf/model/literal/time.rb +29 -98
- data/lib/rdf/model/literal.rb +2 -1
- data/lib/rdf/model/statement.rb +3 -1
- data/lib/rdf/model/uri.rb +3 -2
- data/lib/rdf/ntriples/reader.rb +1 -1
- data/lib/rdf/query/solution.rb +1 -2
- data/lib/rdf/query/solutions.rb +21 -0
- 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 +109 -124
- data/lib/rdf.rb +0 -3
- metadata +11 -5
- 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: 58dcc9836c4302cad4bb46a86596235794a664d508cc002ce298b6c964265ba9
|
4
|
+
data.tar.gz: 941a3daf3a379acf33fe09688ea9cabefd25eb88dc80a7b31d05ac380b2cb2f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f384a93b62b93d574c3dae02e8285f77a3ea6fa26c60eb30aa387e7213343e763a00d9a58f33d0caf4acc5f68a4b27e55361beb792127486059e8afeb333053e
|
7
|
+
data.tar.gz: ed8a19309a2b2f042a3f10df60465b56bd5ea9ace1a305cbe595bab507a7606eae99438fe3ce1edbcd653f513bd015aaf19d5e7203c5903278e275dc591e9d15
|
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
|
[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
|
9
9
|
[![Build Status](https://github.com/ruby-rdf/rdf/workflows/CI/badge.svg?branch=develop)](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
|
@@ -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.2.
|
1
|
+
3.2.6
|
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
@@ -4,67 +4,41 @@ module RDF; class Literal
|
|
4
4
|
#
|
5
5
|
# @see http://www.w3.org/TR/xmlschema11-2/#date
|
6
6
|
# @since 0.2.1
|
7
|
-
class Date <
|
7
|
+
class Date < Temporal
|
8
8
|
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#date")
|
9
9
|
GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
|
10
10
|
FORMAT = '%Y-%m-%d'.freeze
|
11
11
|
|
12
12
|
##
|
13
|
-
#
|
13
|
+
# Internally, a `Date` is represented using a native `::DateTime` object at midnight. If initialized from a `::Date`, there is no timezone component, If initialized from a `::DateTime`, the timezone is taken from that native object, otherwise, a timezone (or no timezone) is taken from the string representation having a matching `zzzzzz` component.
|
14
|
+
#
|
15
|
+
# @note If initialized using the `#to_datetime` method, time component is unchanged. Otherewise, it is set to 00:00 (midnight).
|
16
|
+
#
|
17
|
+
# @param [String, Date, #to_datetime] value
|
14
18
|
# @param (see Literal#initialize)
|
15
19
|
def initialize(value, datatype: nil, lexical: nil, **options)
|
16
20
|
@datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
|
17
21
|
@string = lexical || (value if value.is_a?(String))
|
18
22
|
@object = case
|
19
|
-
when value.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# Returns `true` if the value adheres to the defined grammar of the
|
39
|
-
# datatype.
|
40
|
-
#
|
41
|
-
# Special case for date and dateTime, for which '0000' is not a valid year
|
42
|
-
#
|
43
|
-
# @return [Boolean]
|
44
|
-
# @since 0.2.1
|
45
|
-
def valid?
|
46
|
-
super && object && value !~ %r(\A0000)
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# Does the literal representation include a timezone? Note that this is only possible if initialized using a string, or `:lexical` option.
|
51
|
-
#
|
52
|
-
# @return [Boolean]
|
53
|
-
# @since 1.1.6
|
54
|
-
def timezone?
|
55
|
-
md = self.to_s.match(GRAMMAR)
|
56
|
-
md && !!md[2]
|
57
|
-
end
|
58
|
-
alias_method :tz?, :timezone?
|
59
|
-
alias_method :has_tz?, :timezone?
|
60
|
-
alias_method :has_timezone?, :timezone?
|
61
|
-
|
62
|
-
##
|
63
|
-
# Returns the value as a string.
|
64
|
-
#
|
65
|
-
# @return [String]
|
66
|
-
def to_s
|
67
|
-
@string || @object.strftime(FORMAT)
|
23
|
+
when value.class == ::Date
|
24
|
+
@zone = nil
|
25
|
+
# Use midnight as midpoint of the interval
|
26
|
+
::DateTime.parse(value.strftime('%FT00:00:00'))
|
27
|
+
when value.respond_to?(:to_datetime)
|
28
|
+
dt = value.to_datetime
|
29
|
+
@zone = dt.zone
|
30
|
+
dt
|
31
|
+
else
|
32
|
+
md = value.to_s.match(GRAMMAR)
|
33
|
+
_, dt, tz = Array(md)
|
34
|
+
if tz
|
35
|
+
@zone = tz == 'Z' ? '+00:00' : tz
|
36
|
+
else
|
37
|
+
@zone = nil # No timezone
|
38
|
+
end
|
39
|
+
# Use midnight as midpoint of the interval
|
40
|
+
::DateTime.parse("#{dt}T00:00:00#{@zone}")
|
41
|
+
end rescue ::DateTime.new
|
68
42
|
end
|
69
43
|
|
70
44
|
##
|
@@ -75,42 +49,13 @@ module RDF; class Literal
|
|
75
49
|
def humanize(lang = :en)
|
76
50
|
d = object.strftime("%A, %d %B %Y")
|
77
51
|
if timezone?
|
78
|
-
d += if
|
52
|
+
d += if @zone == '+00:00'
|
79
53
|
" UTC"
|
80
54
|
else
|
81
|
-
" #{
|
55
|
+
" #{@zone}"
|
82
56
|
end
|
83
57
|
end
|
84
58
|
d
|
85
59
|
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Returns the timezone part of arg as a simple literal. Returns the empty string if there is no timezone.
|
89
|
-
#
|
90
|
-
# @return [RDF::Literal]
|
91
|
-
# @since 1.1.6
|
92
|
-
def tz
|
93
|
-
md = self.to_s.match(GRAMMAR)
|
94
|
-
zone = md[2].to_s
|
95
|
-
zone = "Z" if zone == "+00:00"
|
96
|
-
RDF::Literal(zone)
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
# Equal compares as Date objects
|
101
|
-
def ==(other)
|
102
|
-
# If lexically invalid, use regular literal testing
|
103
|
-
return super unless self.valid?
|
104
|
-
|
105
|
-
case other
|
106
|
-
when Literal::Date
|
107
|
-
return super unless other.valid?
|
108
|
-
self.object == other.object
|
109
|
-
when Literal::Time, Literal::DateTime
|
110
|
-
false
|
111
|
-
else
|
112
|
-
super
|
113
|
-
end
|
114
|
-
end
|
115
60
|
end # Date
|
116
61
|
end; end # RDF::Literal
|
@@ -2,117 +2,38 @@ module RDF; class Literal
|
|
2
2
|
##
|
3
3
|
# A date/time literal.
|
4
4
|
#
|
5
|
-
# @see http://www.w3.org/TR/xmlschema11-2/#dateTime
|
5
|
+
# @see http://www.w3.org/TR/xmlschema11-2/#dateTime
|
6
6
|
# @since 0.2.1
|
7
|
-
class DateTime <
|
7
|
+
class DateTime < Temporal
|
8
8
|
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
|
9
9
|
GRAMMAR = %r(\A(-?(?:\d{4}|[1-9]\d{4,})-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
|
10
|
-
FORMAT = '%Y-%m-%dT%H:%M:%S.%L
|
10
|
+
FORMAT = '%Y-%m-%dT%H:%M:%S.%L'.freeze
|
11
11
|
|
12
12
|
##
|
13
|
+
# Internally, a `DateTime` is represented using a native `::DateTime`. If initialized from a `::Date`, there is no timezone component, If initialized from a `::DateTime`, the timezone is taken from that native object, otherwise, a timezone (or no timezone) is taken from the string representation having a matching `zzzzzz` component.
|
14
|
+
#
|
13
15
|
# @param [DateTime] value
|
14
16
|
# @option options [String] :lexical (nil)
|
15
17
|
def initialize(value, datatype: nil, lexical: nil, **options)
|
16
18
|
@datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
|
17
19
|
@string = lexical || (value if value.is_a?(String))
|
18
20
|
@object = case
|
19
|
-
when value.is_a?(::DateTime)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
##
|
26
|
-
# Converts this literal into its canonical lexical representation.
|
27
|
-
# with date and time normalized to UTC.
|
28
|
-
#
|
29
|
-
# @return [RDF::Literal] `self`
|
30
|
-
# @see http://www.w3.org/TR/xmlschema11-2/#dateTime
|
31
|
-
def canonicalize!
|
32
|
-
if self.valid?
|
33
|
-
@string = if timezone?
|
34
|
-
@object.new_offset.new_offset.strftime(FORMAT[0..-4] + 'Z').sub('.000', '')
|
21
|
+
when value.is_a?(::DateTime)
|
22
|
+
@zone = value.zone
|
23
|
+
value
|
24
|
+
when value.respond_to?(:to_datetime)
|
25
|
+
@zone = value.to_datetime.zone
|
26
|
+
value.to_datetime
|
35
27
|
else
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# @return [RDF::Literal]
|
46
|
-
# @see http://www.w3.org/TR/sparql11-query/#func-tz
|
47
|
-
def tz
|
48
|
-
zone = timezone? ? object.zone : ""
|
49
|
-
zone = "Z" if zone == "+00:00"
|
50
|
-
RDF::Literal(zone)
|
51
|
-
end
|
52
|
-
|
53
|
-
##
|
54
|
-
# Returns the timezone part of arg as an xsd:dayTimeDuration, or `nil`
|
55
|
-
# if lexical form of literal does not include a timezone.
|
56
|
-
#
|
57
|
-
# @return [RDF::Literal]
|
58
|
-
def timezone
|
59
|
-
if tz == 'Z'
|
60
|
-
RDF::Literal("PT0S", datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
|
61
|
-
elsif md = tz.to_s.match(/^([+-])?(\d+):(\d+)?$/)
|
62
|
-
plus_minus, hour, min = md[1,3]
|
63
|
-
plus_minus = nil unless plus_minus == "-"
|
64
|
-
hour = hour.to_i
|
65
|
-
min = min.to_i
|
66
|
-
res = "#{plus_minus}PT#{hour}H#{"#{min}M" if min > 0}"
|
67
|
-
RDF::Literal(res, datatype: RDF::URI("http://www.w3.org/2001/XMLSchema#dayTimeDuration"))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
##
|
72
|
-
# Returns `true` if the value adheres to the defined grammar of the
|
73
|
-
# datatype.
|
74
|
-
#
|
75
|
-
# Special case for date and dateTime, for which '0000' is not a valid year
|
76
|
-
#
|
77
|
-
# @return [Boolean]
|
78
|
-
# @since 0.2.1
|
79
|
-
def valid?
|
80
|
-
super && object && value !~ %r(\A0000)
|
81
|
-
end
|
82
|
-
|
83
|
-
##
|
84
|
-
# Does the literal representation include millisectonds?
|
85
|
-
#
|
86
|
-
# @return [Boolean]
|
87
|
-
# @since 1.1.6
|
88
|
-
def milliseconds?
|
89
|
-
self.format("%L").to_i > 0
|
90
|
-
end
|
91
|
-
alias_method :has_milliseconds?, :milliseconds?
|
92
|
-
alias_method :has_ms?, :milliseconds?
|
93
|
-
alias_method :ms?, :milliseconds?
|
94
|
-
|
95
|
-
##
|
96
|
-
# Does the literal representation include a timezone? Note that this is only possible if initialized using a string, or `:lexical` option.
|
97
|
-
#
|
98
|
-
# @return [Boolean]
|
99
|
-
# @since 1.1.6
|
100
|
-
def timezone?
|
101
|
-
md = self.to_s.match(GRAMMAR)
|
102
|
-
md && !!md[2]
|
103
|
-
end
|
104
|
-
alias_method :tz?, :timezone?
|
105
|
-
alias_method :has_tz?, :timezone?
|
106
|
-
alias_method :has_timezone?, :timezone?
|
107
|
-
|
108
|
-
##
|
109
|
-
# Returns the `timezone` of the literal. If the
|
110
|
-
##
|
111
|
-
# Returns the value as a string.
|
112
|
-
#
|
113
|
-
# @return [String]
|
114
|
-
def to_s
|
115
|
-
@string || @object.strftime(FORMAT).sub("+00:00", 'Z').sub('.000', '')
|
28
|
+
md = value.to_s.match(GRAMMAR)
|
29
|
+
_, _, tz = Array(md)
|
30
|
+
if tz
|
31
|
+
@zone = tz == 'Z' ? '+00:00' : tz
|
32
|
+
else
|
33
|
+
@zone = nil # No timezone
|
34
|
+
end
|
35
|
+
::DateTime.parse(value.to_s)
|
36
|
+
end rescue ::DateTime.new
|
116
37
|
end
|
117
38
|
|
118
39
|
##
|
@@ -123,31 +44,10 @@ module RDF; class Literal
|
|
123
44
|
def humanize(lang = :en)
|
124
45
|
d = object.strftime("%r on %A, %d %B %Y")
|
125
46
|
if timezone?
|
126
|
-
|
127
|
-
|
128
|
-
else
|
129
|
-
self.tz
|
130
|
-
end
|
131
|
-
d.sub!(" on ", " #{zone} on ")
|
47
|
+
z = @zone == '+00:00' ? "UTC" : @zone
|
48
|
+
d.sub!(" on ", " #{z} on ")
|
132
49
|
end
|
133
50
|
d
|
134
51
|
end
|
135
|
-
|
136
|
-
##
|
137
|
-
# Equal compares as DateTime objects
|
138
|
-
def ==(other)
|
139
|
-
# If lexically invalid, use regular literal testing
|
140
|
-
return super unless self.valid?
|
141
|
-
|
142
|
-
case other
|
143
|
-
when Literal::DateTime
|
144
|
-
return super unless other.valid?
|
145
|
-
self.object == other.object
|
146
|
-
when Literal::Time, Literal::Date
|
147
|
-
false
|
148
|
-
else
|
149
|
-
super
|
150
|
-
end
|
151
|
-
end
|
152
52
|
end # DateTime
|
153
53
|
end; end # RDF::Literal
|
@@ -54,7 +54,10 @@ module RDF; class Literal
|
|
54
54
|
##
|
55
55
|
# Returns the absolute value of `self`.
|
56
56
|
#
|
57
|
+
# From the XQuery function [fn:abs](https://www.w3.org/TR/xpath-functions/#func-abs).
|
58
|
+
#
|
57
59
|
# @return [RDF::Literal]
|
60
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-abs
|
58
61
|
# @since 0.2.3
|
59
62
|
def abs
|
60
63
|
(d = to_d) && d > 0 ? self : RDF::Literal(d.abs)
|
@@ -63,7 +66,10 @@ module RDF; class Literal
|
|
63
66
|
##
|
64
67
|
# 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.
|
65
68
|
#
|
69
|
+
# From the XQuery function [fn:round](https://www.w3.org/TR/xpath-functions/#func-round).
|
70
|
+
#
|
66
71
|
# @return [RDF::Literal::Decimal]
|
72
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-round
|
67
73
|
def round
|
68
74
|
rounded = to_d.round(half: (to_d < 0 ? :down : :up))
|
69
75
|
if rounded == -0.0
|
@@ -77,10 +83,13 @@ module RDF; class Literal
|
|
77
83
|
##
|
78
84
|
# Returns the smallest integer greater than or equal to `self`.
|
79
85
|
#
|
86
|
+
# From the XQuery function [fn:ceil](https://www.w3.org/TR/xpath-functions/#func-ceil).
|
87
|
+
#
|
80
88
|
# @example
|
81
89
|
# RDF::Literal(1).ceil #=> RDF::Literal(1)
|
82
90
|
#
|
83
91
|
# @return [RDF::Literal::Integer]
|
92
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-ceil
|
84
93
|
def ceil
|
85
94
|
RDF::Literal::Integer.new(to_d.ceil)
|
86
95
|
end
|
@@ -88,10 +97,13 @@ module RDF; class Literal
|
|
88
97
|
##
|
89
98
|
# Returns the largest integer less than or equal to `self`.
|
90
99
|
#
|
100
|
+
# From the XQuery function [fn:floor](https://www.w3.org/TR/xpath-functions/#func-floor).
|
101
|
+
#
|
91
102
|
# @example
|
92
103
|
# RDF::Literal(1).floor #=> RDF::Literal(1)
|
93
104
|
#
|
94
105
|
# @return [RDF::Literal::Integer]
|
106
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-floor
|
95
107
|
def floor
|
96
108
|
RDF::Literal::Integer.new(to_d.floor)
|
97
109
|
end
|
@@ -34,6 +34,14 @@ module RDF; class Literal
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# Approximation of the mathematical constant π
|
38
|
+
#
|
39
|
+
# From the XQuery function [math:pi](https://www.w3.org/TR/xpath-functions/#func-math-pi).
|
40
|
+
#
|
41
|
+
# @return [Double]
|
42
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-math-pi
|
43
|
+
PI = Double.new(Math::PI)
|
44
|
+
|
37
45
|
##
|
38
46
|
# Converts this literal into its canonical lexical representation.
|
39
47
|
#
|
@@ -145,6 +153,8 @@ module RDF; class Literal
|
|
145
153
|
##
|
146
154
|
# Returns the smallest integer greater than or equal to `self`.
|
147
155
|
#
|
156
|
+
# From the XQuery function [fn:ceil](https://www.w3.org/TR/xpath-functions/#func-ceil).
|
157
|
+
#
|
148
158
|
# @example
|
149
159
|
# RDF::Literal(1.2).ceil #=> RDF::Literal(2)
|
150
160
|
# RDF::Literal(-1.2).ceil #=> RDF::Literal(-1)
|
@@ -152,6 +162,7 @@ module RDF; class Literal
|
|
152
162
|
# RDF::Literal(-2.0).ceil #=> RDF::Literal(-2)
|
153
163
|
#
|
154
164
|
# @return [RDF::Literal::Integer]
|
165
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-ceil
|
155
166
|
# @since 0.2.3
|
156
167
|
def ceil
|
157
168
|
RDF::Literal::Integer.new(to_f.ceil)
|
@@ -160,6 +171,8 @@ module RDF; class Literal
|
|
160
171
|
##
|
161
172
|
# Returns the largest integer less than or equal to `self`.
|
162
173
|
#
|
174
|
+
# From the XQuery function [fn:floor](https://www.w3.org/TR/xpath-functions/#func-floor).
|
175
|
+
#
|
163
176
|
# @example
|
164
177
|
# RDF::Literal(1.2).floor #=> RDF::Literal(1)
|
165
178
|
# RDF::Literal(-1.2).floor #=> RDF::Literal(-2)
|
@@ -167,6 +180,7 @@ module RDF; class Literal
|
|
167
180
|
# RDF::Literal(-2.0).floor #=> RDF::Literal(-2)
|
168
181
|
#
|
169
182
|
# @return [RDF::Literal::Integer]
|
183
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-floor
|
170
184
|
# @since 0.2.3
|
171
185
|
def floor
|
172
186
|
RDF::Literal::Integer.new(to_f.floor)
|
@@ -175,7 +189,10 @@ module RDF; class Literal
|
|
175
189
|
##
|
176
190
|
# Returns the absolute value of `self`.
|
177
191
|
#
|
192
|
+
# From the XQuery function [fn:abs](https://www.w3.org/TR/xpath-functions/#func-abs).
|
193
|
+
#
|
178
194
|
# @return [RDF::Literal]
|
195
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-abs
|
179
196
|
# @since 0.2.3
|
180
197
|
def abs
|
181
198
|
(f = to_f) && f > 0 ? self : self.class.new(f.abs)
|
@@ -184,7 +201,10 @@ module RDF; class Literal
|
|
184
201
|
##
|
185
202
|
# 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.
|
186
203
|
#
|
204
|
+
# From the XQuery function [fn:round](https://www.w3.org/TR/xpath-functions/#func-round).
|
205
|
+
#
|
187
206
|
# @return [RDF::Literal::Double]
|
207
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-round
|
188
208
|
def round
|
189
209
|
self.class.new(to_d.round(half: (to_d < 0 ? :down : :up)))
|
190
210
|
end
|