rdf 3.1.3 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -15
- data/VERSION +1 -1
- data/bin/rdf +2 -2
- data/lib/rdf.rb +27 -0
- data/lib/rdf/cli.rb +21 -4
- data/lib/rdf/model/list.rb +44 -19
- data/lib/rdf/model/literal.rb +1 -0
- data/lib/rdf/model/literal/decimal.rb +12 -6
- data/lib/rdf/model/literal/double.rb +8 -8
- data/lib/rdf/model/literal/numeric.rb +34 -0
- data/lib/rdf/model/node.rb +2 -6
- data/lib/rdf/model/uri.rb +24 -17
- data/lib/rdf/nquads.rb +2 -2
- data/lib/rdf/ntriples/reader.rb +9 -6
- data/lib/rdf/ntriples/writer.rb +1 -1
- data/lib/rdf/query.rb +8 -1
- data/lib/rdf/query/pattern.rb +26 -32
- data/lib/rdf/query/variable.rb +12 -1
- data/lib/rdf/reader.rb +6 -19
- data/lib/rdf/repository.rb +6 -6
- data/lib/rdf/util/cache.rb +6 -3
- data/lib/rdf/util/file.rb +3 -3
- data/lib/rdf/util/logger.rb +1 -1
- data/lib/rdf/vocab/writer.rb +3 -2
- data/lib/rdf/vocabulary.rb +1 -1
- data/lib/rdf/writer.rb +2 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2becf1b8beb0505402d0b4d2a6f7795cca3657bc579ffac31f3b6037d34e550
|
4
|
+
data.tar.gz: 14b57058dab38a7f7a23df435b83ce8e45c56c51ef718a107e1f1fedb6939a63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 685797b5318d90aeba5755a88cc4aa0acc37b69bcc209d579d52910f0940cdf93d2b453cb3b60a0779cfadda80a2bc050afad2d18b276d973b21e6f1e3f79317
|
7
|
+
data.tar.gz: a13b21146dfa64967464026e99d80bff9f6b472f4ef7d8079ee53a7e80d80f8577b4b7deee9b60643697354e6b42d093b4229d21978f93b5c65b4a2fa050270f
|
data/README.md
CHANGED
@@ -6,9 +6,9 @@ This is a pure-Ruby library for working with [Resource Description Framework
|
|
6
6
|
* <https://ruby-rdf.github.com/rdf>
|
7
7
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
|
9
|
-
[![Build Status](https://
|
10
|
-
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/
|
11
|
-
[![
|
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)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf)
|
11
|
+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
|
12
12
|
|
13
13
|
## Features
|
14
14
|
|
@@ -39,6 +39,22 @@ resources. Clients may also consider using [RestClient Components][] to enable
|
|
39
39
|
client-side caching of HTTP results using [Rack::Cache][] or other Rack
|
40
40
|
middleware.
|
41
41
|
|
42
|
+
See {RDF::Util::File} for configuring other mechanisms for retrieving resources.
|
43
|
+
|
44
|
+
### Term caching and configuration.
|
45
|
+
|
46
|
+
RDF.rb uses a weak-reference cache for storing internalized versions of URIs and Nodes. This is particularly useful for Nodes as two nodes are equivalent only if they're the same node.
|
47
|
+
|
48
|
+
By default, each cache can grow to an unlimited size, but this can be configured using {RDF.config}, for general limits, along with URI- or Node-specific limits.
|
49
|
+
|
50
|
+
For example, to limit the size of the URI intern cache only:
|
51
|
+
|
52
|
+
RDF.config.uri_cache_size = 10_000
|
53
|
+
|
54
|
+
The default for creating new caches without a specific initialization size can be set using:
|
55
|
+
|
56
|
+
RDF.config.cache_size = 100_000
|
57
|
+
|
42
58
|
## Differences between RDF 1.0 and RDF 1.1
|
43
59
|
|
44
60
|
This version of RDF.rb is fully compatible with [RDF 1.1][], but it creates some
|
@@ -246,17 +262,10 @@ By default, the N-Triples reader will reject a document containing a subject res
|
|
246
262
|
end
|
247
263
|
# => RDF::ReaderError
|
248
264
|
|
249
|
-
Readers support a `rdfstar` option
|
250
|
-
|
251
|
-
graph = RDF::Graph.new do |graph|
|
252
|
-
RDF::NTriples::Reader.new(nt, rdfstar: :PG) {|reader| graph << reader}
|
253
|
-
end
|
254
|
-
graph.count #=> 2
|
255
|
-
|
256
|
-
When using the `:SA` mode, only one statement is asserted, although the reified statement is contained within the graph.
|
265
|
+
Readers support a boolean valued `rdfstar` option.
|
257
266
|
|
258
267
|
graph = RDF::Graph.new do |graph|
|
259
|
-
RDF::NTriples::Reader.new(nt, rdfstar:
|
268
|
+
RDF::NTriples::Reader.new(nt, rdfstar: true) {|reader| graph << reader}
|
260
269
|
end
|
261
270
|
graph.count #=> 1
|
262
271
|
|
@@ -438,7 +447,10 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
438
447
|
enough, be assured we will eventually add you in there.
|
439
448
|
* Do note that in order for us to merge any non-trivial changes (as a rule
|
440
449
|
of thumb, additions larger than about 15 lines of code), we need an
|
441
|
-
explicit [public domain dedication][PDD] on record from you
|
450
|
+
explicit [public domain dedication][PDD] on record from you,
|
451
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
452
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
453
|
+
|
442
454
|
|
443
455
|
## License
|
444
456
|
|
@@ -450,7 +462,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
450
462
|
[N-Quads]: https://www.w3.org/TR/n-quads/
|
451
463
|
[YARD]: https://yardoc.org/
|
452
464
|
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
453
|
-
[PDD]: https://
|
465
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
454
466
|
[JSONLD doc]: https://rubydoc.info/github/ruby-rdf/json-ld
|
455
467
|
[LinkedData doc]: https://rubydoc.info/github/ruby-rdf/linkeddata
|
456
468
|
[Microdata doc]: https://rubydoc.info/github/ruby-rdf/rdf-microdata
|
@@ -475,7 +487,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
475
487
|
[RDF::TriX]: https://ruby-rdf.github.com/rdf-trix
|
476
488
|
[RDF::Turtle]: https://ruby-rdf.github.com/rdf-turtle
|
477
489
|
[RDF::Raptor]: https://ruby-rdf.github.com/rdf-raptor
|
478
|
-
[RDF*]: https://
|
490
|
+
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
|
479
491
|
[LinkedData]: https://ruby-rdf.github.com/linkeddata
|
480
492
|
[JSON::LD]: https://ruby-rdf.github.com/json-ld
|
481
493
|
[RestClient]: https://rubygems.org/gems/rest-client
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.8
|
data/bin/rdf
CHANGED
data/lib/rdf.rb
CHANGED
@@ -2,6 +2,7 @@ require 'stringio'
|
|
2
2
|
require 'bigdecimal'
|
3
3
|
require 'date'
|
4
4
|
require 'time'
|
5
|
+
require "ostruct"
|
5
6
|
|
6
7
|
require 'rdf/version'
|
7
8
|
require 'rdf/extensions'
|
@@ -76,6 +77,32 @@ module RDF
|
|
76
77
|
# Utilities
|
77
78
|
autoload :Util, 'rdf/util'
|
78
79
|
|
80
|
+
# CLI
|
81
|
+
autoload :CLI, 'rdf/cli'
|
82
|
+
|
83
|
+
##
|
84
|
+
# Configuration, used open for configuring constants used within the codebase.
|
85
|
+
#
|
86
|
+
# @example set default cache size to be at most 10,000 entries
|
87
|
+
#
|
88
|
+
# RDF.config.cache_size = 10_000
|
89
|
+
#
|
90
|
+
# @example set cache size for interned URIs to 5,000 entries
|
91
|
+
#
|
92
|
+
# RDF.config.uri_cache_size = 5_000
|
93
|
+
#
|
94
|
+
# Defaults:
|
95
|
+
# * `cache_size`: -1
|
96
|
+
# * `uri_cache_size`: `cache_size`
|
97
|
+
# * `node_cache_size`: `cache_size`
|
98
|
+
#
|
99
|
+
# @note cache configurations must be set before initial use, when the caches are allocated.
|
100
|
+
# @see RDF::Util::Cache.new
|
101
|
+
# @return [Object]
|
102
|
+
def self.config
|
103
|
+
@config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
|
104
|
+
end
|
105
|
+
|
79
106
|
##
|
80
107
|
# Alias for `RDF::Resource.new`.
|
81
108
|
#
|
data/lib/rdf/cli.rb
CHANGED
@@ -8,7 +8,7 @@ begin
|
|
8
8
|
require 'linkeddata'
|
9
9
|
rescue LoadError
|
10
10
|
# Silently load without linkeddata, but try some others
|
11
|
-
%w(
|
11
|
+
%w(microdata n3 rdfa rdfxml reasoner tabular trig trix turtle vocab xsd json/ld ld/patch).each do |ser|
|
12
12
|
begin
|
13
13
|
require ser.include?('/') ? ser : "rdf/#{ser}"
|
14
14
|
rescue LoadError
|
@@ -162,6 +162,7 @@ module RDF
|
|
162
162
|
# * `lambda` code run to execute command.
|
163
163
|
# * `filter` Option values that must match for command to be used
|
164
164
|
# * `control` Used to indicate how (if) command is displayed
|
165
|
+
# * `repository` Use this repository, if set
|
165
166
|
# * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
|
166
167
|
# * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
|
167
168
|
# @return [Hash{Symbol => Hash{Symbol => Object}}]
|
@@ -296,6 +297,12 @@ module RDF
|
|
296
297
|
control: :none,
|
297
298
|
on: ["-o", "--output FILE"],
|
298
299
|
description: "File to write output, defaults to STDOUT") {|arg| File.open(arg, "w")},
|
300
|
+
RDF::CLI::Option.new(
|
301
|
+
symbol: :ordered,
|
302
|
+
control: :checkbox,
|
303
|
+
datatype: TrueClass,
|
304
|
+
on: ["--ordered"],
|
305
|
+
description: "Use order preserving repository"),
|
299
306
|
RDF::CLI::Option.new(
|
300
307
|
symbol: :format,
|
301
308
|
control: :select,
|
@@ -487,6 +494,9 @@ module RDF
|
|
487
494
|
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
|
488
495
|
end
|
489
496
|
end
|
497
|
+
|
498
|
+
# The command may specify a repository instance to use
|
499
|
+
options[:repository] ||= COMMANDS[c.to_sym][:repository]
|
490
500
|
end
|
491
501
|
|
492
502
|
# Hacks for specific options
|
@@ -495,14 +505,18 @@ module RDF
|
|
495
505
|
options[:format] = options[:format].to_sym if options[:format]
|
496
506
|
options[:output_format] = options[:output_format].to_sym if options[:output_format]
|
497
507
|
|
498
|
-
|
508
|
+
# Allow repository to be set via option.
|
509
|
+
@repository = options[:repository] ||
|
510
|
+
(options[:ordered] ?
|
511
|
+
[].extend(RDF::Enumerable, RDF::Queryable) :
|
512
|
+
RDF::Repository.new)
|
499
513
|
|
500
514
|
# Parse input files if any command requires it
|
501
515
|
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
|
502
516
|
start = Time.new
|
503
517
|
count = 0
|
504
518
|
self.parse(args, **options) do |reader|
|
505
|
-
@repository <<
|
519
|
+
reader.each_statement {|st| @repository << st}
|
506
520
|
end
|
507
521
|
secs = Time.new - start
|
508
522
|
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."
|
@@ -510,7 +524,10 @@ module RDF
|
|
510
524
|
|
511
525
|
# Run each command in sequence
|
512
526
|
cmds.each do |command|
|
513
|
-
COMMANDS[command.to_sym][:lambda].call(args,
|
527
|
+
COMMANDS[command.to_sym][:lambda].call(args,
|
528
|
+
output: output,
|
529
|
+
messages: messages,
|
530
|
+
**options.merge(repository: repository))
|
514
531
|
end
|
515
532
|
|
516
533
|
# Normalize messages
|
data/lib/rdf/model/list.rb
CHANGED
@@ -45,18 +45,27 @@ module RDF
|
|
45
45
|
# identified by `subject`, but will be invalid.
|
46
46
|
#
|
47
47
|
# @example add constructed list to existing graph
|
48
|
-
# l = RDF::List(
|
48
|
+
# l = RDF::List(values: (1, 2, 3))
|
49
49
|
# g = RDF::Graph.new << l
|
50
50
|
# g.count # => l.count
|
51
51
|
#
|
52
|
+
# @example use a transaction for block initialization
|
53
|
+
# l = RDF::List(graph: graph, wrap_transaction: true) do |list|
|
54
|
+
# list << RDF::Literal(1)
|
55
|
+
# # list.graph.rollback will rollback all list changes within this block.
|
56
|
+
# end
|
57
|
+
# list.count #=> 1
|
58
|
+
#
|
52
59
|
# @param [RDF::Resource] subject (RDF.nil)
|
53
60
|
# Subject should be an {RDF::Node}, not a {RDF::URI}. A list with an IRI head will not validate, but is commonly used to detect if a list is valid.
|
54
61
|
# @param [RDF::Graph] graph (RDF::Graph.new)
|
55
62
|
# @param [Array<RDF::Term>] values
|
56
63
|
# Any values which are not terms are coerced to `RDF::Literal`.
|
64
|
+
# @param [Boolean] wrap_transaction (false)
|
65
|
+
# Wraps the callback in a transaction, and replaces the graph with that transaction for the duraction of the callback. This has the effect of allowing any list changes to be made atomically, or rolled back.
|
57
66
|
# @yield [list]
|
58
67
|
# @yieldparam [RDF::List] list
|
59
|
-
def initialize(subject: nil, graph: nil, values: nil, &block)
|
68
|
+
def initialize(subject: nil, graph: nil, values: nil, wrap_transaction: false, &block)
|
60
69
|
@subject = subject || RDF.nil
|
61
70
|
@graph = graph || RDF::Graph.new
|
62
71
|
is_empty = @graph.query({subject: subject, predicate: RDF.first}).empty?
|
@@ -68,8 +77,8 @@ module RDF
|
|
68
77
|
if first || values.length > 0
|
69
78
|
# Intantiate the list from values, and insert the first value using subject.
|
70
79
|
values.reverse_each {|value| self.unshift(value)}
|
71
|
-
graph.insert RDF::Statement(subject, RDF.first, first || RDF.nil)
|
72
|
-
graph.insert RDF::Statement(subject, RDF.rest, @subject)
|
80
|
+
@graph.insert RDF::Statement(subject, RDF.first, first || RDF.nil)
|
81
|
+
@graph.insert RDF::Statement(subject, RDF.rest, @subject)
|
73
82
|
end
|
74
83
|
@subject = subject
|
75
84
|
else
|
@@ -78,9 +87,25 @@ module RDF
|
|
78
87
|
end
|
79
88
|
|
80
89
|
if block_given?
|
81
|
-
|
82
|
-
|
83
|
-
|
90
|
+
if wrap_transaction
|
91
|
+
old_graph = @graph
|
92
|
+
begin
|
93
|
+
Transaction.begin(@graph, graph_name: @graph.graph_name, mutable: @graph.mutable?) do |trans|
|
94
|
+
@graph = trans
|
95
|
+
case block.arity
|
96
|
+
when 1 then block.call(self)
|
97
|
+
else instance_eval(&block)
|
98
|
+
end
|
99
|
+
trans.execute if trans.mutated?
|
100
|
+
end
|
101
|
+
ensure
|
102
|
+
@graph = old_graph
|
103
|
+
end
|
104
|
+
else
|
105
|
+
case block.arity
|
106
|
+
when 1 then block.call(self)
|
107
|
+
else instance_eval(&block)
|
108
|
+
end
|
84
109
|
end
|
85
110
|
end
|
86
111
|
end
|
@@ -175,7 +200,7 @@ module RDF
|
|
175
200
|
# @return [RDF::List]
|
176
201
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-26
|
177
202
|
def &(other)
|
178
|
-
|
203
|
+
self.class.new(values: (to_a & other.to_a))
|
179
204
|
end
|
180
205
|
|
181
206
|
##
|
@@ -193,7 +218,7 @@ module RDF
|
|
193
218
|
# @return [RDF::List]
|
194
219
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-7C
|
195
220
|
def |(other)
|
196
|
-
|
221
|
+
self.class.new(values: (to_a | other.to_a))
|
197
222
|
end
|
198
223
|
|
199
224
|
##
|
@@ -206,7 +231,7 @@ module RDF
|
|
206
231
|
# @return [RDF::List]
|
207
232
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2B
|
208
233
|
def +(other)
|
209
|
-
|
234
|
+
self.class.new(values: (to_a + other.to_a))
|
210
235
|
end
|
211
236
|
|
212
237
|
##
|
@@ -220,7 +245,7 @@ module RDF
|
|
220
245
|
# @return [RDF::List]
|
221
246
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2D
|
222
247
|
def -(other)
|
223
|
-
|
248
|
+
self.class.new(values: (to_a - other.to_a))
|
224
249
|
end
|
225
250
|
|
226
251
|
##
|
@@ -250,7 +275,7 @@ module RDF
|
|
250
275
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2A
|
251
276
|
def *(int_or_str)
|
252
277
|
case int_or_str
|
253
|
-
when Integer then
|
278
|
+
when Integer then self.class.new(values: (to_a * int_or_str))
|
254
279
|
else join(int_or_str.to_s)
|
255
280
|
end
|
256
281
|
end
|
@@ -538,13 +563,13 @@ module RDF
|
|
538
563
|
##
|
539
564
|
# @private
|
540
565
|
def slice_with_start_and_length(start, length)
|
541
|
-
|
566
|
+
self.class.new(values: to_a.slice(start, length))
|
542
567
|
end
|
543
568
|
|
544
569
|
##
|
545
570
|
# @private
|
546
571
|
def slice_with_range(range)
|
547
|
-
|
572
|
+
self.class.new(values: to_a.slice(range))
|
548
573
|
end
|
549
574
|
|
550
575
|
protected :slice_with_start_and_length
|
@@ -851,7 +876,7 @@ module RDF
|
|
851
876
|
# @return [RDF::List]
|
852
877
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-reverse
|
853
878
|
def reverse
|
854
|
-
|
879
|
+
self.class.new(values: to_a.reverse)
|
855
880
|
end
|
856
881
|
|
857
882
|
##
|
@@ -863,7 +888,7 @@ module RDF
|
|
863
888
|
# @return [RDF::List]
|
864
889
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-sort
|
865
890
|
def sort(&block)
|
866
|
-
|
891
|
+
self.class.new(values: super)
|
867
892
|
end
|
868
893
|
|
869
894
|
##
|
@@ -875,7 +900,7 @@ module RDF
|
|
875
900
|
# @return [RDF::List]
|
876
901
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-sort_by
|
877
902
|
def sort_by(&block)
|
878
|
-
|
903
|
+
self.class.new(values: super)
|
879
904
|
end
|
880
905
|
|
881
906
|
##
|
@@ -887,7 +912,7 @@ module RDF
|
|
887
912
|
# @return [RDF::List]
|
888
913
|
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-uniq
|
889
914
|
def uniq
|
890
|
-
|
915
|
+
self.class.new(values: to_a.uniq)
|
891
916
|
end
|
892
917
|
|
893
918
|
##
|
@@ -964,7 +989,7 @@ module RDF
|
|
964
989
|
case value
|
965
990
|
when nil then RDF.nil
|
966
991
|
when RDF::Value then value
|
967
|
-
when Array then
|
992
|
+
when Array then self.class.new(subject: nil, graph: graph, values: value)
|
968
993
|
else value
|
969
994
|
end
|
970
995
|
end
|
data/lib/rdf/model/literal.rb
CHANGED
@@ -118,6 +118,7 @@ module RDF
|
|
118
118
|
when ::Integer then RDF::Literal::Integer
|
119
119
|
when ::Float then RDF::Literal::Double
|
120
120
|
when ::BigDecimal then RDF::Literal::Decimal
|
121
|
+
when ::Rational then RDF::Literal::Double
|
121
122
|
when ::DateTime then RDF::Literal::DateTime
|
122
123
|
when ::Time then RDF::Literal::DateTime
|
123
124
|
when ::Date then RDF::Literal::Date
|
@@ -63,9 +63,15 @@ module RDF; class Literal
|
|
63
63
|
##
|
64
64
|
# 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
65
|
#
|
66
|
-
# @return [RDF::Literal]
|
66
|
+
# @return [RDF::Literal::Decimal]
|
67
67
|
def round
|
68
|
-
|
68
|
+
rounded = to_d.round(half: (to_d < 0 ? :down : :up))
|
69
|
+
if rounded == -0.0
|
70
|
+
# to avoid -0.0
|
71
|
+
self.class.new(0.0)
|
72
|
+
else
|
73
|
+
self.class.new(rounded)
|
74
|
+
end
|
69
75
|
end
|
70
76
|
|
71
77
|
##
|
@@ -74,9 +80,9 @@ module RDF; class Literal
|
|
74
80
|
# @example
|
75
81
|
# RDF::Literal(1).ceil #=> RDF::Literal(1)
|
76
82
|
#
|
77
|
-
# @return [RDF::Literal]
|
83
|
+
# @return [RDF::Literal::Integer]
|
78
84
|
def ceil
|
79
|
-
|
85
|
+
RDF::Literal::Integer.new(to_d.ceil)
|
80
86
|
end
|
81
87
|
|
82
88
|
##
|
@@ -85,9 +91,9 @@ module RDF; class Literal
|
|
85
91
|
# @example
|
86
92
|
# RDF::Literal(1).floor #=> RDF::Literal(1)
|
87
93
|
#
|
88
|
-
# @return [RDF::Literal]
|
94
|
+
# @return [RDF::Literal::Integer]
|
89
95
|
def floor
|
90
|
-
|
96
|
+
RDF::Literal::Integer.new(to_d.floor)
|
91
97
|
end
|
92
98
|
|
93
99
|
##
|
@@ -142,7 +142,7 @@ module RDF; class Literal
|
|
142
142
|
end
|
143
143
|
|
144
144
|
##
|
145
|
-
# Returns the smallest
|
145
|
+
# Returns the smallest integer greater than or equal to `self`.
|
146
146
|
#
|
147
147
|
# @example
|
148
148
|
# RDF::Literal(1.2).ceil #=> RDF::Literal(2)
|
@@ -150,14 +150,14 @@ module RDF; class Literal
|
|
150
150
|
# RDF::Literal(2.0).ceil #=> RDF::Literal(2)
|
151
151
|
# RDF::Literal(-2.0).ceil #=> RDF::Literal(-2)
|
152
152
|
#
|
153
|
-
# @return [RDF::Literal]
|
153
|
+
# @return [RDF::Literal::Integer]
|
154
154
|
# @since 0.2.3
|
155
155
|
def ceil
|
156
|
-
|
156
|
+
RDF::Literal::Integer.new(to_f.ceil)
|
157
157
|
end
|
158
158
|
|
159
159
|
##
|
160
|
-
# Returns the largest
|
160
|
+
# Returns the largest integer less than or equal to `self`.
|
161
161
|
#
|
162
162
|
# @example
|
163
163
|
# RDF::Literal(1.2).floor #=> RDF::Literal(1)
|
@@ -165,10 +165,10 @@ module RDF; class Literal
|
|
165
165
|
# RDF::Literal(2.0).floor #=> RDF::Literal(2)
|
166
166
|
# RDF::Literal(-2.0).floor #=> RDF::Literal(-2)
|
167
167
|
#
|
168
|
-
# @return [RDF::Literal]
|
168
|
+
# @return [RDF::Literal::Integer]
|
169
169
|
# @since 0.2.3
|
170
170
|
def floor
|
171
|
-
|
171
|
+
RDF::Literal::Integer.new(to_f.floor)
|
172
172
|
end
|
173
173
|
|
174
174
|
##
|
@@ -183,9 +183,9 @@ module RDF; class Literal
|
|
183
183
|
##
|
184
184
|
# 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.
|
185
185
|
#
|
186
|
-
# @return [RDF::Literal]
|
186
|
+
# @return [RDF::Literal::Double]
|
187
187
|
def round
|
188
|
-
self.class.new(
|
188
|
+
self.class.new(to_d.round(half: (to_d < 0 ? :down : :up)))
|
189
189
|
end
|
190
190
|
|
191
191
|
##
|
@@ -123,6 +123,40 @@ module RDF; class Literal
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
##
|
127
|
+
# Exponent − Performs exponential (power) calculation on operators.
|
128
|
+
#
|
129
|
+
# Promotes values, as necessary, with the result type depending on the input values.
|
130
|
+
#
|
131
|
+
# @param [Literal::Numeric, #to_i, #to_f, #to_d] other
|
132
|
+
# @return [RDF::Literal::Numeric]
|
133
|
+
# @since 0.2.3
|
134
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-math-pow
|
135
|
+
def **(other)
|
136
|
+
RDF::Literal(object ** (other.is_a?(RDF::Literal::Numeric) ? other.object : other))
|
137
|
+
rescue ZeroDivisionError
|
138
|
+
RDF::Literal::Double.new('INF')
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Exponent − Performs remainder of `self` divided by `other`.
|
143
|
+
#
|
144
|
+
# @param [Literal::Numeric, #to_i, #to_f, #to_d] other
|
145
|
+
# @return [RDF::Literal]
|
146
|
+
# @since 0.2.3
|
147
|
+
# @see https://www.w3.org/TR/xpath-functions/#func-numeric-mod
|
148
|
+
def %(other)
|
149
|
+
if self.class == Double || [Double, ::Float].include?(other.class)
|
150
|
+
self.class.new(to_f % other.to_f)
|
151
|
+
elsif ((self.class == RDF::Literal::Float || other.class == RDF::Literal::Float) rescue false)
|
152
|
+
self.class.new(to_f % other.to_f)
|
153
|
+
elsif self.class == Decimal || other.class == Decimal
|
154
|
+
self.class.new(to_d % (other.respond_to?(:to_d) ? other.to_d : BigDecimal(other.to_s)))
|
155
|
+
else
|
156
|
+
self.class.new(to_i % other.to_i)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
126
160
|
##
|
127
161
|
# Returns the quotient of `self` divided by `other`.
|
128
162
|
#
|
data/lib/rdf/model/node.rb
CHANGED
@@ -13,18 +13,14 @@ module RDF
|
|
13
13
|
include RDF::Resource
|
14
14
|
|
15
15
|
##
|
16
|
-
#
|
17
|
-
# cached in memory at any one time.
|
16
|
+
# Cache size may be set through {RDF.config} using `node_cache_size`.
|
18
17
|
#
|
19
18
|
# @note caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the graph from which it is used. RDF requires that bnodes with the same label are, in fact, different bnodes, unless they are used within the same document.
|
20
|
-
CACHE_SIZE = -1 # unlimited by default
|
21
|
-
|
22
|
-
##
|
23
19
|
# @return [RDF::Util::Cache]
|
24
20
|
# @private
|
25
21
|
def self.cache
|
26
22
|
require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
|
27
|
-
@cache ||= RDF::Util::Cache.new(
|
23
|
+
@cache ||= RDF::Util::Cache.new(RDF.config.node_cache_size)
|
28
24
|
end
|
29
25
|
|
30
26
|
##
|
data/lib/rdf/model/uri.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require '
|
2
|
+
require 'cgi'
|
3
3
|
|
4
4
|
module RDF
|
5
5
|
##
|
@@ -27,11 +27,6 @@ module RDF
|
|
27
27
|
class URI
|
28
28
|
include RDF::Resource
|
29
29
|
|
30
|
-
##
|
31
|
-
# Defines the maximum number of interned URI references that can be held
|
32
|
-
# cached in memory at any one time.
|
33
|
-
CACHE_SIZE = -1 # unlimited by default
|
34
|
-
|
35
30
|
# IRI components
|
36
31
|
UCSCHAR = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
|
37
32
|
[\\u00A0-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFEF]|
|
@@ -117,11 +112,13 @@ module RDF
|
|
117
112
|
).freeze
|
118
113
|
|
119
114
|
##
|
115
|
+
# Cache size may be set through {RDF.config} using `uri_cache_size`.
|
116
|
+
#
|
120
117
|
# @return [RDF::Util::Cache]
|
121
118
|
# @private
|
122
119
|
def self.cache
|
123
120
|
require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
|
124
|
-
@cache ||= RDF::Util::Cache.new(
|
121
|
+
@cache ||= RDF::Util::Cache.new(RDF.config.uri_cache_size)
|
125
122
|
end
|
126
123
|
|
127
124
|
##
|
@@ -311,12 +308,22 @@ module RDF
|
|
311
308
|
# @param [#to_s] base_uri
|
312
309
|
# @return [RDF::URI]
|
313
310
|
def relativize(base_uri)
|
314
|
-
if base_uri.to_s.
|
311
|
+
if self.to_s.start_with?(base_uri.to_s) && %w(# ?).include?(self.to_s[base_uri.to_s.length, 1]) ||
|
312
|
+
base_uri.to_s.end_with?("/", "#") &&
|
315
313
|
self.to_s.start_with?(base_uri.to_s)
|
316
|
-
RDF::URI(self.to_s[base_uri.to_s.length..-1])
|
314
|
+
return RDF::URI(self.to_s[base_uri.to_s.length..-1])
|
317
315
|
else
|
318
|
-
|
316
|
+
# Create a list of parents, for which this IRI may be relative.
|
317
|
+
u = RDF::URI(base_uri)
|
318
|
+
iri_set = u.to_s.end_with?('/') ? [u.to_s] : []
|
319
|
+
iri_set << u.to_s while (u = u.parent)
|
320
|
+
iri_set.each_with_index do |bb, index|
|
321
|
+
next unless self.to_s.start_with?(bb)
|
322
|
+
rel = "../" * index + self.to_s[bb.length..-1]
|
323
|
+
return rel.empty? ? "./" : rel
|
324
|
+
end
|
319
325
|
end
|
326
|
+
self
|
320
327
|
end
|
321
328
|
|
322
329
|
##
|
@@ -846,7 +853,7 @@ module RDF
|
|
846
853
|
parts[:user] = (user.dup.force_encoding(Encoding::UTF_8) if user)
|
847
854
|
parts[:password] = (password.dup.force_encoding(Encoding::UTF_8) if password)
|
848
855
|
parts[:host] = (host.dup.force_encoding(Encoding::UTF_8) if host)
|
849
|
-
parts[:port] = (
|
856
|
+
parts[:port] = (CGI.unescape(port).to_i if port)
|
850
857
|
parts[:path] = (path.to_s.dup.force_encoding(Encoding::UTF_8) unless path.empty?)
|
851
858
|
parts[:query] = (query[1..-1].dup.force_encoding(Encoding::UTF_8) if query)
|
852
859
|
parts[:fragment] = (fragment[1..-1].dup.force_encoding(Encoding::UTF_8) if fragment)
|
@@ -902,7 +909,7 @@ module RDF
|
|
902
909
|
# Normalized version of user
|
903
910
|
# @return [String]
|
904
911
|
def normalized_user
|
905
|
-
URI.encode(
|
912
|
+
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if user
|
906
913
|
end
|
907
914
|
|
908
915
|
##
|
@@ -928,7 +935,7 @@ module RDF
|
|
928
935
|
# Normalized version of password
|
929
936
|
# @return [String]
|
930
937
|
def normalized_password
|
931
|
-
URI.encode(
|
938
|
+
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if password
|
932
939
|
end
|
933
940
|
|
934
941
|
HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
|
@@ -1180,8 +1187,8 @@ module RDF
|
|
1180
1187
|
inject(return_type == Hash ? {} : []) do |memo,kv|
|
1181
1188
|
k,v = kv.to_s.split('=', 2)
|
1182
1189
|
next if k.to_s.empty?
|
1183
|
-
k =
|
1184
|
-
v =
|
1190
|
+
k = CGI.unescape(k)
|
1191
|
+
v = CGI.unescape(v) if v
|
1185
1192
|
if return_type == Hash
|
1186
1193
|
case memo[k]
|
1187
1194
|
when nil then memo[k] = v
|
@@ -1293,9 +1300,9 @@ module RDF
|
|
1293
1300
|
def normalize_segment(value, expr, downcase = false)
|
1294
1301
|
if value
|
1295
1302
|
value = value.dup.force_encoding(Encoding::UTF_8)
|
1296
|
-
decoded =
|
1303
|
+
decoded = CGI.unescape(value)
|
1297
1304
|
decoded.downcase! if downcase
|
1298
|
-
URI.encode(decoded, /[^(?:#{expr})]/)
|
1305
|
+
URI.encode(decoded, /[^(?:#{expr})]/).force_encoding(Encoding::UTF_8)
|
1299
1306
|
end
|
1300
1307
|
end
|
1301
1308
|
|
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_embTriple || 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_embTriple || 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
@@ -1,4 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'strscan'
|
4
|
+
|
2
5
|
module RDF::NTriples
|
3
6
|
##
|
4
7
|
# N-Triples parser.
|
@@ -210,7 +213,7 @@ module RDF::NTriples
|
|
210
213
|
begin
|
211
214
|
read_statement
|
212
215
|
rescue RDF::ReaderError
|
213
|
-
value = read_uriref || read_node || read_literal ||
|
216
|
+
value = read_uriref || read_node || read_literal || read_embTriple
|
214
217
|
log_recover
|
215
218
|
value
|
216
219
|
end
|
@@ -226,9 +229,9 @@ module RDF::NTriples
|
|
226
229
|
|
227
230
|
begin
|
228
231
|
unless blank? || read_comment
|
229
|
-
subject = read_uriref || read_node ||
|
232
|
+
subject = read_uriref || read_node || read_embTriple || fail_subject
|
230
233
|
predicate = read_uriref(intern: true) || fail_predicate
|
231
|
-
object = read_uriref || read_node || read_literal ||
|
234
|
+
object = read_uriref || read_node || read_literal || read_embTriple || fail_object
|
232
235
|
|
233
236
|
if validate? && !read_eos
|
234
237
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
@@ -244,11 +247,11 @@ module RDF::NTriples
|
|
244
247
|
|
245
248
|
##
|
246
249
|
# @return [RDF::Statement]
|
247
|
-
def
|
250
|
+
def read_embTriple
|
248
251
|
if @options[:rdfstar] && match(ST_START)
|
249
|
-
subject = read_uriref || read_node ||
|
252
|
+
subject = read_uriref || read_node || read_embTriple || fail_subject
|
250
253
|
predicate = read_uriref(intern: true) || fail_predicate
|
251
|
-
object = read_uriref || read_node || read_literal ||
|
254
|
+
object = read_uriref || read_node || read_literal || read_embTriple || fail_object
|
252
255
|
if !match(ST_END)
|
253
256
|
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
|
254
257
|
end
|
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_embTriple(statement, **options)
|
231
231
|
"<<%s %s %s>>" % statement.to_a.map { |value| format_term(value, **options) }
|
232
232
|
end
|
233
233
|
##
|
data/lib/rdf/query.rb
CHANGED
@@ -247,15 +247,22 @@ module RDF
|
|
247
247
|
# Optimizes this query by reordering its constituent triple patterns
|
248
248
|
# according to their cost estimates.
|
249
249
|
#
|
250
|
+
# Optional patterns have greater cost than non-optional patterns so they will always come after non-optional patterns
|
251
|
+
#
|
250
252
|
# @param [Hash{Symbol => Object}] options
|
251
253
|
# any additional options for optimization
|
252
254
|
# @return [self]
|
253
255
|
# @see RDF::Query::Pattern#cost
|
254
256
|
# @since 0.3.0
|
255
257
|
def optimize!(**options)
|
256
|
-
@patterns.
|
258
|
+
optional, required = @patterns.uniq.partition(&:optional?)
|
259
|
+
required.sort! do |a, b|
|
260
|
+
(a.cost || 0) <=> (b.cost || 0)
|
261
|
+
end
|
262
|
+
optional.sort! do |a, b|
|
257
263
|
(a.cost || 0) <=> (b.cost || 0)
|
258
264
|
end
|
265
|
+
@patterns = required + optional
|
259
266
|
self
|
260
267
|
end
|
261
268
|
|
data/lib/rdf/query/pattern.rb
CHANGED
@@ -181,16 +181,10 @@ module RDF; class Query
|
|
181
181
|
|
182
182
|
# No, some terms actually refer to the same variable...
|
183
183
|
else
|
184
|
-
#
|
185
|
-
|
186
|
-
terms = variable_terms(name)
|
187
|
-
break terms if terms.size > 1
|
188
|
-
end
|
184
|
+
# Considering embedding, figure out if variables that may appear more than once resolve to the same value.
|
185
|
+
vars = variables.keys
|
189
186
|
queryable.query(query).select do |statement|
|
190
|
-
|
191
|
-
# constraint is also satisfied:
|
192
|
-
# FIXME: `Array#uniq` uses `#eql?` and `#hash`, not `#==`
|
193
|
-
if terms.map { |term| statement.send(term) }.uniq.size.equal?(1)
|
187
|
+
if vars.all? {|var| self.var_values(var, statement).uniq.size == 1}
|
194
188
|
yield statement if block_given?
|
195
189
|
true
|
196
190
|
end
|
@@ -220,8 +214,8 @@ module RDF; class Query
|
|
220
214
|
solution[predicate.to_sym] = statement.predicate if predicate.is_a?(Variable)
|
221
215
|
solution[object.to_sym] = statement.object if object.is_a?(Variable)
|
222
216
|
solution[graph_name.to_sym] = statement.graph_name if graph_name.is_a?(Variable)
|
223
|
-
solution.merge!(subject.solution(statement.subject)) if subject.
|
224
|
-
solution.merge!(object.solution(statement.object)) if object.
|
217
|
+
solution.merge!(subject.solution(statement.subject)) if subject.respond_to?(:solution)
|
218
|
+
solution.merge!(object.solution(statement.object)) if object.respond_to?(:solution)
|
225
219
|
end
|
226
220
|
end
|
227
221
|
|
@@ -234,8 +228,11 @@ module RDF; class Query
|
|
234
228
|
# @param [Symbol, #to_sym] name
|
235
229
|
# an optional variable name
|
236
230
|
# @return [Array<Symbol>]
|
231
|
+
# @deprecated use {#var_values} instead
|
237
232
|
# @since 0.3.0
|
238
233
|
def variable_terms(name = nil)
|
234
|
+
warn "[DEPRECATION] RDF::Query::Pattern#variable_terms is deprecated and will be removed in a future version.\n" +
|
235
|
+
"Called from #{Gem.location_of_caller.join(':')}"
|
239
236
|
terms = []
|
240
237
|
terms << :subject if subject.is_a?(Variable) && (!name || name.eql?(subject.name))
|
241
238
|
terms << :predicate if predicate.is_a?(Variable) && (!name || name.eql?(predicate.name))
|
@@ -244,6 +241,20 @@ module RDF; class Query
|
|
244
241
|
terms
|
245
242
|
end
|
246
243
|
|
244
|
+
##
|
245
|
+
# Returns all values the statement in the same pattern position
|
246
|
+
#
|
247
|
+
# @param [Symbol] var
|
248
|
+
# @param [RDF::Statement] statement
|
249
|
+
# @return [Array<RDF::Term>]
|
250
|
+
def var_values(var, statement)
|
251
|
+
[:subject, :predicate, :object, :graph_name].map do |position|
|
252
|
+
po = self.send(position)
|
253
|
+
so = statement.send(position)
|
254
|
+
po.var_values(var, so) if po.respond_to?(:var_values)
|
255
|
+
end.flatten.compact
|
256
|
+
end
|
257
|
+
|
247
258
|
##
|
248
259
|
# Returns the number of variables in this pattern.
|
249
260
|
#
|
@@ -254,7 +265,7 @@ module RDF; class Query
|
|
254
265
|
def variable_count
|
255
266
|
[subject, predicate, object, graph_name].inject(0) do |memo, term|
|
256
267
|
memo += (term.is_a?(Variable) ? 1 :
|
257
|
-
(term.
|
268
|
+
(term.respond_to?(:variable_count) ? term.variable_count : 0))
|
258
269
|
end
|
259
270
|
end
|
260
271
|
alias_method :cardinality, :variable_count
|
@@ -311,9 +322,9 @@ module RDF; class Query
|
|
311
322
|
def bindings
|
312
323
|
bindings = {}
|
313
324
|
bindings.merge!(subject.bindings) if subject && subject.variable?
|
314
|
-
bindings.merge!(predicate.bindings) if predicate.
|
325
|
+
bindings.merge!(predicate.bindings) if predicate && predicate.variable?
|
315
326
|
bindings.merge!(object.bindings) if object && object.variable?
|
316
|
-
bindings.merge!(graph_name.bindings) if graph_name.
|
327
|
+
bindings.merge!(graph_name.bindings) if graph_name && graph_name.variable?
|
317
328
|
bindings
|
318
329
|
end
|
319
330
|
|
@@ -354,24 +365,7 @@ module RDF; class Query
|
|
354
365
|
#
|
355
366
|
# @return [String]
|
356
367
|
def to_s
|
357
|
-
|
358
|
-
buffer << 'OPTIONAL ' if optional?
|
359
|
-
buffer << [subject, predicate, object].map do |r|
|
360
|
-
if r.is_a?(RDF::Query::Variable)
|
361
|
-
r.to_s
|
362
|
-
elsif r.is_a?(RDF::Query::Pattern)
|
363
|
-
"<<#{r.to_s[0..-3]}>>"
|
364
|
-
else
|
365
|
-
RDF::NTriples.serialize(r)
|
366
|
-
end
|
367
|
-
end.join(" ")
|
368
|
-
buffer << case graph_name
|
369
|
-
when nil, false then " ."
|
370
|
-
when Variable then " #{graph_name.to_s} ."
|
371
|
-
else " #{RDF::NTriples.serialize(graph_name)} ."
|
372
|
-
end
|
373
|
-
buffer.string
|
374
|
-
end
|
368
|
+
(optional? ? 'OPTIONAL ' : '') + super
|
375
369
|
end
|
376
370
|
end # Pattern
|
377
371
|
end; end # RDF::Query
|
data/lib/rdf/query/variable.rb
CHANGED
@@ -65,7 +65,7 @@ class RDF::Query
|
|
65
65
|
# the variable name
|
66
66
|
# @param [RDF::Term] value
|
67
67
|
# an optional variable value
|
68
|
-
# @param [Boolean] distinguished (true) Also interpreted by leading '
|
68
|
+
# @param [Boolean] distinguished (true) Also interpreted by leading '?' or '$' in name. If non-distinguished, '??' or '$$'.
|
69
69
|
# @param [Boolean] existential (true) Also interpreted by leading '$' in name
|
70
70
|
def initialize(name = nil, value = nil, distinguished: nil, existential: nil)
|
71
71
|
name = (name || "g#{__id__.to_i.abs}").to_s
|
@@ -246,6 +246,16 @@ class RDF::Query
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
|
+
##
|
250
|
+
# Returns term if var is the same as this variable.
|
251
|
+
#
|
252
|
+
# @param [Symbol] var
|
253
|
+
# @param [RDF::Term] term
|
254
|
+
# @return [RDF::Term]
|
255
|
+
def var_values(var, term)
|
256
|
+
term if var == name
|
257
|
+
end
|
258
|
+
|
249
259
|
##
|
250
260
|
# Returns a string representation of this variable.
|
251
261
|
#
|
@@ -265,5 +275,6 @@ class RDF::Query
|
|
265
275
|
prefix = distinguished? ? (existential? ? '$' : '?') : (existential? ? '$$' : '??')
|
266
276
|
unbound? ? "#{prefix}#{name}" : "#{prefix}#{name}=#{value}"
|
267
277
|
end
|
278
|
+
alias_method :to_base, :to_s
|
268
279
|
end # Variable
|
269
280
|
end # RDF::Query
|
data/lib/rdf/reader.rb
CHANGED
@@ -160,10 +160,10 @@ module RDF
|
|
160
160
|
end,
|
161
161
|
RDF::CLI::Option.new(
|
162
162
|
symbol: :rdfstar,
|
163
|
-
|
164
|
-
|
165
|
-
on: ["--
|
166
|
-
description: "Parse RDF
|
163
|
+
datatype: TrueClass,
|
164
|
+
control: :checkbox,
|
165
|
+
on: ["--rdfstar"],
|
166
|
+
description: "Parse RDF*."),
|
167
167
|
RDF::CLI::Option.new(
|
168
168
|
symbol: :validate,
|
169
169
|
datatype: TrueClass,
|
@@ -276,10 +276,8 @@ module RDF
|
|
276
276
|
# the encoding of the input stream
|
277
277
|
# @param [Boolean] intern (true)
|
278
278
|
# whether to intern all parsed URIs
|
279
|
-
# @param [
|
279
|
+
# @param [Boolean] rdfstar (false)
|
280
280
|
# support parsing RDF* statement resources.
|
281
|
-
# If `:PG`, referenced statements are also emitted.
|
282
|
-
# If `:SA`, referenced statements are not emitted.
|
283
281
|
# @param [Hash] prefixes (Hash.new)
|
284
282
|
# the prefix mappings to use (not supported by all readers)
|
285
283
|
# @param [Hash{Symbol => Object}] options
|
@@ -295,7 +293,7 @@ module RDF
|
|
295
293
|
encoding: Encoding::UTF_8,
|
296
294
|
intern: true,
|
297
295
|
prefixes: Hash.new,
|
298
|
-
rdfstar:
|
296
|
+
rdfstar: false,
|
299
297
|
validate: false,
|
300
298
|
**options,
|
301
299
|
&block)
|
@@ -401,9 +399,6 @@ module RDF
|
|
401
399
|
# Statements are yielded in the order that they are read from the input
|
402
400
|
# stream.
|
403
401
|
#
|
404
|
-
# If the `rdfstar` option is `:PG` and triples include
|
405
|
-
# embedded statements, they are also enumerated.
|
406
|
-
#
|
407
402
|
# @overload each_statement
|
408
403
|
# @yield [statement]
|
409
404
|
# each statement
|
@@ -423,7 +418,6 @@ module RDF
|
|
423
418
|
loop do
|
424
419
|
st = read_statement
|
425
420
|
block.call(st)
|
426
|
-
each_pg_statement(st, &block) if options[:rdfstar] == :PG
|
427
421
|
end
|
428
422
|
rescue EOFError
|
429
423
|
rewind rescue nil
|
@@ -441,9 +435,6 @@ module RDF
|
|
441
435
|
# Triples are yielded in the order that they are read from the input
|
442
436
|
# stream.
|
443
437
|
#
|
444
|
-
# If the `rdfstar` option is `:PG` and triples include
|
445
|
-
# embedded statements, they are also enumerated.
|
446
|
-
#
|
447
438
|
# @overload each_triple
|
448
439
|
# @yield [subject, predicate, object]
|
449
440
|
# each triple
|
@@ -464,10 +455,6 @@ module RDF
|
|
464
455
|
loop do
|
465
456
|
triple = read_triple
|
466
457
|
block.call(*triple)
|
467
|
-
if options[:rdfstar] == :PG
|
468
|
-
block.call(*triple[0].to_a) if triple[0].is_a?(Statement)
|
469
|
-
block.call(*triple[2].to_a) if triple[2].is_a?(Statement)
|
470
|
-
end
|
471
458
|
end
|
472
459
|
rescue EOFError
|
473
460
|
rewind rescue nil
|
data/lib/rdf/repository.rb
CHANGED
@@ -410,12 +410,12 @@ module RDF
|
|
410
410
|
end
|
411
411
|
ss.each do |s, ps|
|
412
412
|
ps = if predicate.nil? || predicate.is_a?(RDF::Query::Variable)
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
413
|
+
ps
|
414
|
+
elsif ps.has_key?(predicate)
|
415
|
+
{ predicate => ps[predicate] }
|
416
|
+
else
|
417
|
+
[]
|
418
|
+
end
|
419
419
|
ps.each do |p, os|
|
420
420
|
os.each do |o, object_options|
|
421
421
|
next unless object.nil? || object.eql?(o)
|
data/lib/rdf/util/cache.rb
CHANGED
@@ -17,6 +17,9 @@ module RDF; module Util
|
|
17
17
|
# @see http://en.wikipedia.org/wiki/Weak_reference
|
18
18
|
# @since 0.2.0
|
19
19
|
class Cache
|
20
|
+
# The configured cache capacity.
|
21
|
+
attr_reader :capacity
|
22
|
+
|
20
23
|
##
|
21
24
|
# @private
|
22
25
|
def self.new(*args)
|
@@ -36,8 +39,8 @@ module RDF; module Util
|
|
36
39
|
|
37
40
|
##
|
38
41
|
# @param [Integer] capacity
|
39
|
-
def initialize(capacity =
|
40
|
-
@capacity = capacity
|
42
|
+
def initialize(capacity = nil)
|
43
|
+
@capacity = capacity || RDF.config.cache_size
|
41
44
|
@cache ||= {}
|
42
45
|
@index ||= {}
|
43
46
|
end
|
@@ -106,7 +109,7 @@ module RDF; module Util
|
|
106
109
|
class WeakRefCache < Cache
|
107
110
|
##
|
108
111
|
# @param [Integer] capacity
|
109
|
-
def initialize(capacity =
|
112
|
+
def initialize(capacity = nil)
|
110
113
|
require 'weakref' unless defined?(::WeakRef)
|
111
114
|
super
|
112
115
|
end
|
data/lib/rdf/util/file.rb
CHANGED
@@ -14,7 +14,7 @@ module RDF; module Util
|
|
14
14
|
# allowing the use of `Rack::Cache` to avoid network access.
|
15
15
|
#
|
16
16
|
# To use other HTTP clients, consumers can subclass
|
17
|
-
# {RDF::Util::File::HttpAdapter} and set the {RDF::Util::File.
|
17
|
+
# {RDF::Util::File::HttpAdapter} and set the {RDF::Util::File.}.
|
18
18
|
#
|
19
19
|
# Also supports the file: scheme for access to local files.
|
20
20
|
#
|
@@ -121,8 +121,8 @@ module RDF; module Util
|
|
121
121
|
|
122
122
|
redirect_count = 0
|
123
123
|
max_redirects = 5
|
124
|
-
parsed_url = ::URI.parse(base_uri)
|
125
|
-
parsed_proxy = ::URI.parse(proxy.to_s)
|
124
|
+
parsed_url = RDF::URI.parse(base_uri)
|
125
|
+
parsed_proxy = RDF::URI.parse(proxy.to_s)
|
126
126
|
base_uri = parsed_url.to_s
|
127
127
|
remote_document = nil
|
128
128
|
|
data/lib/rdf/util/logger.rb
CHANGED
@@ -219,9 +219,9 @@ module RDF; module Util
|
|
219
219
|
# @return [void]
|
220
220
|
def logger_common(*args, level:, **options)
|
221
221
|
logger = self.logger(**options)
|
222
|
-
logger.log_statistics[level] = logger.log_statistics[level].to_i + 1
|
223
222
|
# Some older code uses integer level numbers
|
224
223
|
level = LOGGER_COMMON_LEVELS_REVERSE.fetch(level) if level.is_a?(Integer)
|
224
|
+
logger.log_statistics[level] = logger.log_statistics[level].to_i + 1
|
225
225
|
return if logger.level > LOGGER_COMMON_LEVELS.fetch(level)
|
226
226
|
|
227
227
|
depth = options.fetch(:depth, logger.log_depth)
|
data/lib/rdf/vocab/writer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rdf'
|
2
2
|
require 'rdf/vocabulary'
|
3
|
+
require 'cgi'
|
3
4
|
|
4
5
|
module RDF
|
5
6
|
##
|
@@ -84,7 +85,7 @@ module RDF
|
|
84
85
|
on: ["--extra URIEncodedJSON"],
|
85
86
|
description: "URI Encoded JSON representation of extra data"
|
86
87
|
) do |arg|
|
87
|
-
::JSON.parse(::
|
88
|
+
::JSON.parse(::CGI.unescape(arg)).inject({}) do |m1, (term, defs)|
|
88
89
|
d1 = defs.inject({}) {|m, (k,v)| m.merge(k.to_sym => v)}
|
89
90
|
m1.merge(term.to_sym => d1)
|
90
91
|
end
|
@@ -262,7 +263,7 @@ module RDF
|
|
262
263
|
|
263
264
|
def serialize_value(value, key, indent: "")
|
264
265
|
if value.is_a?(Literal) && %w(: comment definition notation note editorialNote).include?(key.to_s)
|
265
|
-
"
|
266
|
+
"#{value.to_s.inspect}.freeze"
|
266
267
|
elsif value.is_a?(RDF::URI)
|
267
268
|
"#{value.pname.inspect}.freeze"
|
268
269
|
elsif value.is_a?(RDF::Vocabulary::Term)
|
data/lib/rdf/vocabulary.rb
CHANGED
@@ -731,7 +731,7 @@ module RDF
|
|
731
731
|
# @param [#to_s] property
|
732
732
|
# @return [URI]
|
733
733
|
def [](property)
|
734
|
-
Term.intern([to_s, property.to_s].join(''), vocab: self
|
734
|
+
Term.intern([to_s, property.to_s].join(''), vocab: self, attributes: {})
|
735
735
|
end
|
736
736
|
|
737
737
|
##
|
data/lib/rdf/writer.rb
CHANGED
@@ -516,7 +516,7 @@ module RDF
|
|
516
516
|
when RDF::Literal then format_literal(term, **options)
|
517
517
|
when RDF::URI then format_uri(term, **options)
|
518
518
|
when RDF::Node then format_node(term, **options)
|
519
|
-
when RDF::Statement then
|
519
|
+
when RDF::Statement then format_embTriple(term, **options)
|
520
520
|
else nil
|
521
521
|
end
|
522
522
|
end
|
@@ -574,7 +574,7 @@ module RDF
|
|
574
574
|
# @return [String]
|
575
575
|
# @raise [NotImplementedError] unless implemented in subclass
|
576
576
|
# @abstract
|
577
|
-
def
|
577
|
+
def format_embTriple(value, **options)
|
578
578
|
raise NotImplementedError.new("#{self.class}#format_statement") # override in subclasses
|
579
579
|
end
|
580
580
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
8
8
|
- Ben Lavender
|
9
9
|
- Gregg Kellogg
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: link_header
|
@@ -164,42 +164,42 @@ dependencies:
|
|
164
164
|
requirements:
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: 0.9
|
167
|
+
version: '0.9'
|
168
168
|
type: :development
|
169
169
|
prerelease: false
|
170
170
|
version_requirements: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
172
|
- - "~>"
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 0.9
|
174
|
+
version: '0.9'
|
175
175
|
- !ruby/object:Gem::Dependency
|
176
176
|
name: faraday
|
177
177
|
requirement: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
179
|
- - "~>"
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: '
|
181
|
+
version: '1.2'
|
182
182
|
type: :development
|
183
183
|
prerelease: false
|
184
184
|
version_requirements: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
186
|
- - "~>"
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version: '
|
188
|
+
version: '1.2'
|
189
189
|
- !ruby/object:Gem::Dependency
|
190
190
|
name: faraday_middleware
|
191
191
|
requirement: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
193
|
- - "~>"
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: '0
|
195
|
+
version: '1.0'
|
196
196
|
type: :development
|
197
197
|
prerelease: false
|
198
198
|
version_requirements: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
200
|
- - "~>"
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version: '0
|
202
|
+
version: '1.0'
|
203
203
|
description: RDF.rb is a pure-Ruby library for working with Resource Description Framework
|
204
204
|
(RDF) data.
|
205
205
|
email: public-rdf-ruby@w3.org
|
@@ -288,7 +288,7 @@ metadata:
|
|
288
288
|
homepage_uri: https://ruby-rdf.github.io/rdf
|
289
289
|
mailing_list_uri: https://lists.w3.org/Archives/Public/public-rdf-ruby/
|
290
290
|
source_code_uri: https://github.com/ruby-rdf/rdf
|
291
|
-
post_install_message:
|
291
|
+
post_install_message:
|
292
292
|
rdoc_options: []
|
293
293
|
require_paths:
|
294
294
|
- lib
|
@@ -303,8 +303,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
- !ruby/object:Gem::Version
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
|
-
rubygems_version: 3.
|
307
|
-
signing_key:
|
306
|
+
rubygems_version: 3.2.3
|
307
|
+
signing_key:
|
308
308
|
specification_version: 4
|
309
309
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|
310
310
|
test_files: []
|