rdf 3.1.5 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3024b8471983ae96eef2df1b95ef2fc1d72bba082d43e3567c9e8c30970cb6db
4
- data.tar.gz: 3104532cffa328bb403fe3403deb30188ceb00a119b8f4e1dbccc7c01fd69712
3
+ metadata.gz: 5de713395026fd70491ac47ef4c5c89e63681bccf27d8b9e39fe21fcf63c1344
4
+ data.tar.gz: a2bc97b12d11858f4089fba2915f358ba28db0bb4704ce70e668f17c80e9a739
5
5
  SHA512:
6
- metadata.gz: 2b62e3081278305f44f09c7aa77d3143a5110779bd1963e702ffde2ffacae8fa4ee0abcb861441675ea70c409f33270e7f4a2e0cf45c66c4956188bebef6ae80
7
- data.tar.gz: 23674e4180517963dd92f26ac4d40c7c3eea672be96e64f8d719ff94c084ef229e5e21473d1d4dd0336fbb8ae3ad2c3b200ff1f7da6b7a352ead2ff98d4dd83c
6
+ metadata.gz: 334cf936abb27e4c0a8fe225c4bd309b455ab96fcf1e79369abe3a763b28e922172b5d477a9a2112677f3ae21d8b3a0fdb9696d6d89bb6ce85bf49831464f611
7
+ data.tar.gz: 76d46e91f93f70e021f482b089fb4a5afebb955e835d89965e270688a46fb938a5b1e334d2c0e5d9992a149de97bb84c5f14e8f4da62019aaa7bec7fcb7f582e
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://travis-ci.org/ruby-rdf/rdf.png?branch=master)](https://travis-ci.org/ruby-rdf/rdf)
10
- [![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf)
11
- [![Join the chat at https://gitter.im/ruby-rdf/rdf](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruby-rdf/rdf?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
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?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf?branch=develop)
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 with either `:PG` (Property Graph) or `:SA` (Separate Assertions) modes. In `:PG` mode, statements that are used in the subject or object positions are also implicitly added to the graph:
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: :SA) {|reader| graph << reader}
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://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
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://lists.w3.org/Archives/Public/public-rdf-star/
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.5
1
+ 3.1.10
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'
@@ -79,6 +80,29 @@ module RDF
79
80
  # CLI
80
81
  autoload :CLI, 'rdf/cli'
81
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
+
82
106
  ##
83
107
  # Alias for `RDF::Resource.new`.
84
108
  #
data/lib/rdf/cli.rb CHANGED
@@ -8,9 +8,26 @@ begin
8
8
  require 'linkeddata'
9
9
  rescue LoadError
10
10
  # Silently load without linkeddata, but try some others
11
- %w(microdata n3 rdfa rdfxml reasoner tabular trig trix turtle vocab xsd json/ld ld/patch).each do |ser|
11
+ %w(
12
+ json/ld
13
+ ld/patch
14
+ rdf/microdata
15
+ rdf/n3
16
+ rdf/ordered_repo
17
+ rdf/rdfa
18
+ rdf/rdfxml
19
+ rdf/reasoner
20
+ rdf/tabular
21
+ rdf/trig
22
+ rdf/trix
23
+ rdf/turtle
24
+ rdf/vocab
25
+ rdf/xsd
26
+ shacl
27
+ shex
28
+ ).each do |ser|
12
29
  begin
13
- require ser.include?('/') ? ser : "rdf/#{ser}"
30
+ require ser
14
31
  rescue LoadError
15
32
  end
16
33
  end
@@ -162,6 +179,7 @@ module RDF
162
179
  # * `lambda` code run to execute command.
163
180
  # * `filter` Option values that must match for command to be used
164
181
  # * `control` Used to indicate how (if) command is displayed
182
+ # * `repository` Use this repository, if set
165
183
  # * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
166
184
  # * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
167
185
  # @return [Hash{Symbol => Hash{Symbol => Object}}]
@@ -315,7 +333,7 @@ module RDF
315
333
 
316
334
  # Add format-specific reader options
317
335
  reader.options.each do |cli_opt|
318
- next if options.options.has_key?(cli_opt.symbol)
336
+ next if options.options.key?(cli_opt.symbol)
319
337
  on_args = cli_opt.on || []
320
338
  on_args << cli_opt.description if cli_opt.description
321
339
  options.on(*on_args) do |opt_arg|
@@ -337,7 +355,7 @@ module RDF
337
355
 
338
356
  # Add format-specific writer options
339
357
  writer.options.each do |cli_opt|
340
- next if options.options.has_key?(cli_opt.symbol)
358
+ next if options.options.key?(cli_opt.symbol)
341
359
  on_args = cli_opt.on || []
342
360
  on_args << cli_opt.description if cli_opt.description
343
361
  options.on(*on_args) do |opt_arg|
@@ -401,7 +419,7 @@ module RDF
401
419
  end
402
420
 
403
421
  cli_opts.each do |cli_opt|
404
- next if opts.has_key?(cli_opt.symbol)
422
+ next if opts.key?(cli_opt.symbol)
405
423
  on_args = cli_opt.on || []
406
424
  on_args << cli_opt.description if cli_opt.description
407
425
  options.on(*on_args) do |arg|
@@ -456,7 +474,7 @@ module RDF
456
474
  # @param [Array<String>] args
457
475
  # @param [IO] output
458
476
  # @param [OptionParser] option_parser
459
- # @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for confeying non primary-output which is structured.
477
+ # @param [Hash{Symbol => Hash{Symbol => Array[String]}}] messages used for conveying non primary-output which is structured.
460
478
  # @param [Hash{Symbol => Object}] options
461
479
  # @return [Boolean]
462
480
  def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options)
@@ -493,6 +511,9 @@ module RDF
493
511
  raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
494
512
  end
495
513
  end
514
+
515
+ # The command may specify a repository instance to use
516
+ options[:repository] ||= COMMANDS[c.to_sym][:repository]
496
517
  end
497
518
 
498
519
  # Hacks for specific options
@@ -501,9 +522,13 @@ module RDF
501
522
  options[:format] = options[:format].to_sym if options[:format]
502
523
  options[:output_format] = options[:output_format].to_sym if options[:output_format]
503
524
 
504
- @repository = options[:ordered] ?
505
- [].extend(RDF::Enumerable, RDF::Queryable) :
506
- RDF::Repository.new
525
+ # Allow repository to be set via option.
526
+ # If RDF::OrderedRepo is present, use it if the `ordered` option is specified, otherwise extend an Array.
527
+ @repository = options[:repository] || case
528
+ when RDF.const_defined?(:OrderedRepo) then RDF::OrderedRepo.new
529
+ when options[:ordered] then [].extend(RDF::Enumerable, RDF::Queryable)
530
+ else RDF::Repository.new
531
+ end
507
532
 
508
533
  # Parse input files if any command requires it
509
534
  if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
@@ -518,7 +543,10 @@ module RDF
518
543
 
519
544
  # Run each command in sequence
520
545
  cmds.each do |command|
521
- COMMANDS[command.to_sym][:lambda].call(args, output: output, **options.merge(messages: messages))
546
+ COMMANDS[command.to_sym][:lambda].call(args,
547
+ output: output,
548
+ messages: messages,
549
+ **options.merge(repository: repository))
522
550
  end
523
551
 
524
552
  # Normalize messages
@@ -12,15 +12,15 @@ module RDF
12
12
  # enumerable.count
13
13
  #
14
14
  # @example Checking whether a specific statement exists
15
- # enumerable.has_statement?(RDF::Statement(subject, predicate, object))
16
- # enumerable.has_triple?([subject, predicate, object])
17
- # enumerable.has_quad?([subject, predicate, object, graph_name])
15
+ # enumerable.statement?(RDF::Statement(subject, predicate, object))
16
+ # enumerable.triple?([subject, predicate, object])
17
+ # enumerable.quad?([subject, predicate, object, graph_name])
18
18
  #
19
19
  # @example Checking whether a specific value exists
20
- # enumerable.has_subject?(RDF::URI("https://rubygems.org/gems/rdf"))
21
- # enumerable.has_predicate?(RDF::RDFS.label)
22
- # enumerable.has_object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
23
- # enumerable.has_graph?(RDF::URI("http://ar.to/#self"))
20
+ # enumerable.subject?(RDF::URI("https://rubygems.org/gems/rdf"))
21
+ # enumerable.predicate?(RDF::RDFS.label)
22
+ # enumerable.object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
23
+ # enumerable.graph?(RDF::URI("http://ar.to/#self"))
24
24
  #
25
25
  # @example Enumerating all statements
26
26
  # enumerable.each_statement do |statement|
@@ -127,14 +127,20 @@ module RDF
127
127
  end
128
128
 
129
129
  ##
130
- # Returns `true` if `self` contains the given RDF statement.
130
+ # @overload statement?
131
+ # Returns `false` indicating this is not an RDF::Statemenet.
132
+ # @return [Boolean]
133
+ # @see RDF::Value#statement?
134
+ # @overload statement?(statement)
135
+ # Returns `true` if `self` contains the given RDF statement.
131
136
  #
132
- # @param [RDF::Statement] statement
133
- # @return [Boolean]
134
- def has_statement?(statement)
135
- !enum_statement.find { |s| s.eql?(statement) }.nil?
137
+ # @param [RDF::Statement] statement
138
+ # @return [Boolean]
139
+ def statement?(statement = nil)
140
+ statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
136
141
  end
137
- alias_method :include?, :has_statement?
142
+ alias_method :has_statement?, :statement?
143
+ alias_method :include?, :statement?
138
144
 
139
145
  ##
140
146
  # Iterates the given block for each RDF statement.
@@ -194,9 +200,10 @@ module RDF
194
200
  #
195
201
  # @param [Array(RDF::Resource, RDF::URI, RDF::Term)] triple
196
202
  # @return [Boolean]
197
- def has_triple?(triple)
203
+ def triple?(triple)
198
204
  triples.include?(triple)
199
205
  end
206
+ alias_method :has_triple?, :triple?
200
207
 
201
208
  ##
202
209
  # Iterates the given block for each RDF triple.
@@ -255,9 +262,10 @@ module RDF
255
262
  #
256
263
  # @param [Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)] quad
257
264
  # @return [Boolean]
258
- def has_quad?(quad)
265
+ def quad?(quad)
259
266
  quads.include?(quad)
260
267
  end
268
+ alias_method :has_quad?, :quad?
261
269
 
262
270
  ##
263
271
  # Iterates the given block for each RDF quad.
@@ -321,9 +329,10 @@ module RDF
321
329
  #
322
330
  # @param [RDF::Resource] value
323
331
  # @return [Boolean]
324
- def has_subject?(value)
332
+ def subject?(value)
325
333
  enum_subject.include?(value)
326
334
  end
335
+ alias_method :has_subject?, :subject?
327
336
 
328
337
  ##
329
338
  # Iterates the given block for each unique RDF subject term.
@@ -386,9 +395,10 @@ module RDF
386
395
  #
387
396
  # @param [RDF::URI] value
388
397
  # @return [Boolean]
389
- def has_predicate?(value)
398
+ def predicate?(value)
390
399
  enum_predicate.include?(value)
391
400
  end
401
+ alias_method :has_predicate?, :predicate?
392
402
 
393
403
  ##
394
404
  # Iterates the given block for each unique RDF predicate term.
@@ -451,9 +461,10 @@ module RDF
451
461
  #
452
462
  # @param [RDF::Term] value
453
463
  # @return [Boolean]
454
- def has_object?(value)
464
+ def object?(value)
455
465
  enum_object.include?(value)
456
466
  end
467
+ alias_method :has_object?, :object?
457
468
 
458
469
  ##
459
470
  # Iterates the given block for each unique RDF object term.
@@ -511,7 +522,7 @@ module RDF
511
522
  def terms(unique: true)
512
523
  unless unique
513
524
  enum_statement.
514
- map(&:to_quad).
525
+ map(&:terms).
515
526
  flatten.
516
527
  compact
517
528
  else
@@ -520,14 +531,20 @@ module RDF
520
531
  end
521
532
 
522
533
  ##
523
- # Returns `true` if `self` contains the given RDF subject term.
534
+ # @overload term?
535
+ # Returns `false` indicating this is not an RDF::Statemenet.
536
+ # @see RDF::Value#statement?
537
+ # @return [Boolean]
538
+ # @overload term?(value)
539
+ # Returns `true` if `self` contains the given RDF subject term.
524
540
  #
525
- # @param [RDF::Resource] value
526
- # @return [Boolean]
527
- # @since 2.0
528
- def has_term?(value)
529
- enum_term.include?(value)
541
+ # @param [RDF::Resource] value
542
+ # @return [Boolean]
543
+ # @since 2.0
544
+ def term?(value = nil)
545
+ value && enum_term.include?(value)
530
546
  end
547
+ alias_method :has_term?, :term?
531
548
 
532
549
  ##
533
550
  # Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
@@ -551,8 +568,8 @@ module RDF
551
568
  if block_given?
552
569
  values = {}
553
570
  each_statement do |statement|
554
- statement.to_quad.each do |value|
555
- unless value.nil? || values.include?(value.hash)
571
+ statement.terms.each do |value|
572
+ unless values.include?(value.hash)
556
573
  values[value.hash] = true
557
574
  yield value
558
575
  end
@@ -595,9 +612,10 @@ module RDF
595
612
  # @param [RDF::Resource, false] graph_name
596
613
  # Use value `false` to query for the default graph_name
597
614
  # @return [Boolean]
598
- def has_graph?(graph_name)
615
+ def graph?(graph_name)
599
616
  enum_statement.any? {|s| s.graph_name == graph_name}
600
617
  end
618
+ alias_method :has_graph?, :graph?
601
619
 
602
620
  ##
603
621
  # Limits statements to be from a specific graph.
@@ -122,7 +122,7 @@ module RDF
122
122
 
123
123
  statements.each do |statement|
124
124
  if (statement = Statement.from(statement))
125
- if statement.has_object?
125
+ if statement.object?
126
126
  delete_insert([[statement.subject, statement.predicate, nil]], [statement])
127
127
  else
128
128
  delete([statement.subject, statement.predicate, nil])
@@ -104,7 +104,7 @@ module RDF
104
104
  # @private
105
105
  # @see RDF::Enumerable#supports?
106
106
  def supports?(feature)
107
- return true if [:graph_name, :rdfstar].include?(feature)
107
+ return true if %i(graph_name rdfstar).include?(feature)
108
108
  super
109
109
  end
110
110
 
@@ -215,18 +215,25 @@ module RDF
215
215
  end
216
216
 
217
217
  ##
218
- # Returns `true` if this graph contains the given RDF statement.
218
+ # @overload statement?
219
+ # Returns `false` indicating this is not an RDF::Statemenet.
220
+ # @see RDF::Value#statement?
221
+ # @return [Boolean]
222
+ # @overload statement?(statement)
223
+ # Returns `true` if this graph contains the given RDF statement.
219
224
  #
220
- # A statement is in a graph if the statement if it has the same triples without regard to graph_name.
225
+ # A statement is in a graph if the statement if it has the same triples without regard to graph_name.
221
226
  #
222
- # @param [Statement] statement
223
- # @return [Boolean]
224
- # @see RDF::Enumerable#has_statement?
225
- def has_statement?(statement)
227
+ # @param [Statement] statement
228
+ # @return [Boolean]
229
+ # @see RDF::Enumerable#statement?
230
+ def statement?(statement = nil)
231
+ return false if statement.nil?
226
232
  statement = statement.dup
227
233
  statement.graph_name = graph_name
228
- @data.has_statement?(statement)
234
+ @data.statement?(statement)
229
235
  end
236
+ alias_method :has_statement?, :statement?
230
237
 
231
238
  ##
232
239
  # Enumerates each RDF statement in this graph.