rdf 3.2.6 → 3.2.9

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: 58dcc9836c4302cad4bb46a86596235794a664d508cc002ce298b6c964265ba9
4
- data.tar.gz: 941a3daf3a379acf33fe09688ea9cabefd25eb88dc80a7b31d05ac380b2cb2f9
3
+ metadata.gz: 73bbb2bcc84c974f9ecfe2b1f9a41cf445273e76cfdbd6fd84b6141790b85092
4
+ data.tar.gz: 5a339b4166238e83c491555bc084e9132491da17c54234252b4bc60b5b8451db
5
5
  SHA512:
6
- metadata.gz: f384a93b62b93d574c3dae02e8285f77a3ea6fa26c60eb30aa387e7213343e763a00d9a58f33d0caf4acc5f68a4b27e55361beb792127486059e8afeb333053e
7
- data.tar.gz: ed8a19309a2b2f042a3f10df60465b56bd5ea9ace1a305cbe595bab507a7606eae99438fe3ce1edbcd653f513bd015aaf19d5e7203c5903278e275dc591e9d15
6
+ metadata.gz: d083cfe87a7894a616966a8d0bdc9a4d0b11814fde48a95bf94f83cc0fcc6ffd939b0ddd765079e0ca2514fbc7df182bebea0870d4a7d8f2817bba72cb7c4bab
7
+ data.tar.gz: ce59b7a5f8340f9fee88ad374c1452df356312ad3621e64e678054508616b32648e7cb49fc9fd42563cc8c8079d99500d9c779a9dcf1924e0804ca97e17ea69e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.6
1
+ 3.2.9
data/lib/rdf/cli.rb CHANGED
@@ -25,6 +25,7 @@ rescue LoadError
25
25
  rdf/xsd
26
26
  shacl
27
27
  shex
28
+ yaml_ld
28
29
  ).each do |ser|
29
30
  begin
30
31
  require ser
@@ -177,7 +178,10 @@ module RDF
177
178
  # * `parse` Boolean value to determine if input files should automatically be parsed into `repository`.
178
179
  # * `help` used for the CLI help output.
179
180
  # * `lambda` code run to execute command.
180
- # * `filter` Option values that must match for command to be used
181
+ # * `filter` value is a Hash whose keys are matched against selected command options. All specified `key/value` pairs are compared against the equivalent key in the current invocation.
182
+ # If an Array, option value (as a string) must match any value of the array (as a string)
183
+ # If a Proc, it is passed the option value and must return `true`.
184
+ # Otherwise, the option value (as a string) must equal the `value` (as a string).
181
185
  # * `control` Used to indicate how (if) command is displayed
182
186
  # * `repository` Use this repository, if set
183
187
  # * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
@@ -505,9 +509,22 @@ module RDF
505
509
  # Make sure any selected command isn't filtered out
506
510
  cmds.each do |c|
507
511
  COMMANDS[c.to_sym].fetch(:filter, {}).each do |opt, val|
508
- if options[opt].to_s != val.to_s
509
- usage(option_parser, banner: "Command #{c.inspect} requires #{opt}: #{val}, not #{options.fetch(opt, 'null')}")
510
- raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
512
+ case val
513
+ when Array
514
+ unless val.map(&:to_s).include?(options[opt].to_s)
515
+ usage(option_parser, banner: "Command #{c.inspect} requires #{opt} in #{val.map(&:to_s).inspect}, not #{options.fetch(opt, 'null')}")
516
+ raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
517
+ end
518
+ when Proc
519
+ unless val.call(options[opt])
520
+ usage(option_parser, banner: "Command #{c.inspect} #{opt} inconsistent with #{options.fetch(opt, 'null')}")
521
+ raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
522
+ end
523
+ else
524
+ unless val.to_s == options[opt].to_s
525
+ usage(option_parser, banner: "Command #{c.inspect} requires compatible value for #{opt}, not #{options.fetch(opt, 'null')}")
526
+ raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
527
+ end
511
528
  end
512
529
  end
513
530
 
@@ -572,7 +589,8 @@ module RDF
572
589
  # @param [Hash{Symbol => Object}] options already set
573
590
  # @return [Array<String>] list of executable commands
574
591
  # @overload commands(format: :json, **options)
575
- # @param [:json] format (:json)
592
+ # Returns commands as JSON, for API usage.
593
+ # @param [:json] format
576
594
  # @param [Hash{Symbol => Object}] options already set
577
595
  # @return [Array{Object}]
578
596
  # Returns an array of commands including the command symbol
@@ -593,7 +611,14 @@ module RDF
593
611
  # Subset commands based on filter options
594
612
  cmds = COMMANDS.reject do |k, c|
595
613
  c.fetch(:filter, {}).any? do |opt, val|
596
- options[opt].to_s != val.to_s
614
+ case val
615
+ when Array
616
+ !val.map(&:to_s).include?(options[opt].to_s)
617
+ when Proc
618
+ !val.call(options[opt])
619
+ else
620
+ val.to_s != options[opt].to_s
621
+ end
597
622
  end
598
623
  end
599
624
 
data/lib/rdf/format.rb CHANGED
@@ -23,7 +23,9 @@ module RDF
23
23
  #
24
24
  # @example Defining a new RDF serialization format class
25
25
  # class RDF::NTriples::Format < RDF::Format
26
- # content_type 'application/n-triples', extension: :nt
26
+ # content_type 'application/n-triples',
27
+ # extension: :nt,
28
+ # uri: RDF::URI("http://www.w3.org/ns/formats/N-Triples")
27
29
  # content_encoding 'utf-8'
28
30
  #
29
31
  # reader RDF::NTriples::Reader
@@ -222,6 +224,19 @@ module RDF
222
224
  @@file_extensions
223
225
  end
224
226
 
227
+ ##
228
+ # Returns the unique URI for the format.
229
+ #
230
+ # @example retrieving a list of supported file format URIs
231
+ #
232
+ # RDF::Format.uris.keys
233
+ #
234
+ # @see https://www.w3.org/ns/formats/
235
+ # @return [Hash{Symbol => URI}]
236
+ def self.uris
237
+ @@uris
238
+ end
239
+
225
240
  ##
226
241
  # Returns the set of format symbols for available RDF::Reader subclasses.
227
242
  #
@@ -465,6 +480,7 @@ module RDF
465
480
  # @option options [Array<String>] :aliases (nil)
466
481
  # @option options [Symbol] :extension (nil)
467
482
  # @option options [Array<Symbol>] :extensions (nil)
483
+ # @option options [URI] :uri (nil)
468
484
  # @return [void]
469
485
  #
470
486
  # @overload content_type
@@ -504,6 +520,10 @@ module RDF
504
520
  @@content_types[aa] << self unless @@content_types[aa].include?(self)
505
521
  end
506
522
  end
523
+ # URI identifying this format
524
+ if uri = options[:uri]
525
+ @@uris[RDF::URI(uri)] = self
526
+ end
507
527
  end
508
528
  end
509
529
 
@@ -517,7 +537,7 @@ module RDF
517
537
  end
518
538
 
519
539
  ##
520
- # Retrieves or defines file extensions for this RDF serialization format.
540
+ # Retrieves file extensions for this RDF serialization format.
521
541
  #
522
542
  # The return is an array where the first element is the cannonical
523
543
  # file extension for the format and following elements are alias file extensions.
@@ -527,6 +547,17 @@ module RDF
527
547
  @@file_extensions.map {|ext, formats| ext if formats.include?(self)}.compact
528
548
  end
529
549
 
550
+ ##
551
+ # Retrieves any format URI defined for this format..
552
+ #
553
+ # @return [URI]
554
+ def self.uri
555
+ @@uris.invert[self]
556
+ end
557
+ class << self
558
+ alias_method :to_uri, :uri
559
+ end
560
+
530
561
  protected
531
562
 
532
563
  ##
@@ -568,6 +599,7 @@ module RDF
568
599
  @@readers = {} # @private
569
600
  @@writers = {} # @private
570
601
  @@subclasses = [] # @private
602
+ @@uris = {} # @private
571
603
 
572
604
  ##
573
605
  # @private
@@ -79,7 +79,7 @@ module RDF
79
79
  #
80
80
  # @return [String]
81
81
  def inspect
82
- sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, uri.to_s)
82
+ sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, count.to_s)
83
83
  end
84
84
 
85
85
  ##
@@ -3,10 +3,11 @@ module RDF; class Literal
3
3
  # A date literal.
4
4
  #
5
5
  # @see http://www.w3.org/TR/xmlschema11-2/#date
6
+ # @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
6
7
  # @since 0.2.1
7
8
  class Date < Temporal
8
9
  DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#date")
9
- GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
10
+ GRAMMAR = %r(\A(#{YEARFRAG}-#{MONTHFRAG}-#{DAYFRAG})(#{TZFRAG})?\z).freeze
10
11
  FORMAT = '%Y-%m-%d'.freeze
11
12
 
12
13
  ##
@@ -3,10 +3,22 @@ module RDF; class Literal
3
3
  # A date/time literal.
4
4
  #
5
5
  # @see http://www.w3.org/TR/xmlschema11-2/#dateTime
6
+ # @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
6
7
  # @since 0.2.1
7
8
  class DateTime < Temporal
8
9
  DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
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
+ GRAMMAR = %r(\A
11
+ (#{YEARFRAG}
12
+ -#{MONTHFRAG}
13
+ -#{DAYFRAG}
14
+ T
15
+ (?:
16
+ (?:
17
+ #{HOURFRAG}
18
+ :#{MINUTEFRAG}
19
+ :#{SECONDFRAG})
20
+ | #{EODFRAG}))
21
+ (#{TZFRAG})?\z)x.freeze
10
22
  FORMAT = '%Y-%m-%dT%H:%M:%S.%L'.freeze
11
23
 
12
24
  ##
@@ -10,6 +10,15 @@ module RDF; class Literal
10
10
  |(?:(?<si>-)?PT(?<hr>\d{1,2})H(?:(?<mi>\d{1,2})M)?)
11
11
  \z)x.freeze
12
12
 
13
+ YEARFRAG = %r(-?(?:(?:[1-9]\d{3,})|(?:0\d{3})))
14
+ MONTHFRAG = %r((?:(?:0[1-9])|(?:1[0-2])))
15
+ DAYFRAG = %r((?:(?:0[1-9])|(?:[12]\d)|(?:3[01])))
16
+ HOURFRAG = %r((?:[01]\d)|(?:2[0-3]))
17
+ MINUTEFRAG = %r([0-5]\d)
18
+ SECONDFRAG = %r([0-5]\d(?:\.\d+)?)
19
+ EODFRAG = %r(24:00:00(?:\.0+)?)
20
+ TZFRAG = %r((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)
21
+
13
22
  ##
14
23
  # Compares this literal to `other` for sorting purposes.
15
24
  #
@@ -8,10 +8,11 @@ module RDF; class Literal
8
8
  # following time zone indicator.
9
9
  #
10
10
  # @see http://www.w3.org/TR/xmlschema11-2/#time
11
+ # @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
11
12
  # @since 0.2.1
12
13
  class Time < Temporal
13
14
  DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#time")
14
- GRAMMAR = %r(\A(\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
15
+ GRAMMAR = %r(\A((?:#{HOURFRAG}:#{MINUTEFRAG}:#{SECONDFRAG})|#{EODFRAG})(#{TZFRAG})?\z).freeze
15
16
  FORMAT = '%H:%M:%S.%L'.freeze
16
17
 
17
18
  ##
data/lib/rdf/model/uri.rb CHANGED
@@ -76,6 +76,7 @@ module RDF
76
76
  IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
77
77
 
78
78
  # Split an IRI into it's component parts
79
+ # scheme, authority, path, query, fragment
79
80
  IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze
80
81
 
81
82
  # Remove dot expressions regular expressions
@@ -872,6 +873,12 @@ module RDF
872
873
  parts = {}
873
874
  if matchdata = IRI_PARTS.match(value)
874
875
  scheme, authority, path, query, fragment = matchdata[1..-1]
876
+
877
+ if Gem.win_platform? && scheme && !authority && scheme.match?(/^[a-zA-Z]$/)
878
+ # A drive letter, not a scheme
879
+ scheme, path = nil, "#{scheme}:#{path}"
880
+ end
881
+
875
882
  userinfo, hostport = authority.to_s.split('@', 2)
876
883
  hostport, userinfo = userinfo, nil unless hostport
877
884
  user, password = userinfo.to_s.split(':', 2)
data/lib/rdf/nquads.rb CHANGED
@@ -20,7 +20,10 @@ module RDF
20
20
  # @see http://www.w3.org/TR/n-quads/
21
21
  # @since 0.4.0
22
22
  class Format < RDF::Format
23
- content_type 'application/n-quads', extension: :nq, alias: 'text/x-nquads;q=0.2'
23
+ content_type 'application/n-quads',
24
+ extension: :nq,
25
+ alias: 'text/x-nquads;q=0.2',
26
+ uri: RDF::URI("http://www.w3.org/ns/formats/N-Quads")
24
27
  content_encoding 'utf-8'
25
28
 
26
29
  reader { RDF::NQuads::Reader }
@@ -16,7 +16,10 @@ module RDF::NTriples
16
16
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
17
17
  # @see http://www.w3.org/TR/n-triples/
18
18
  class Format < RDF::Format
19
- content_type 'application/n-triples', extension: :nt, alias: 'text/plain;q=0.2'
19
+ content_type 'application/n-triples',
20
+ extension: :nt,
21
+ alias: 'text/plain;q=0.2',
22
+ uri: RDF::URI("http://www.w3.org/ns/formats/N-Triples")
20
23
  content_encoding 'utf-8'
21
24
 
22
25
  reader { RDF::NTriples::Reader }
@@ -160,7 +160,7 @@ module RDF; class Query
160
160
  #
161
161
  # @param [RDF::Queryable] queryable
162
162
  # the graph or repository to query
163
- # @param [Hash{Symbol => RDF::Term}] bindings
163
+ # @param [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
164
164
  # optional variable bindings to use
165
165
  # @yield [statement]
166
166
  # each matching statement
@@ -171,6 +171,7 @@ module RDF; class Query
171
171
  # @see RDF::Queryable#query
172
172
  # @since 0.3.0
173
173
  def execute(queryable, bindings = {}, &block)
174
+ bindings = bindings.to_h if bindings.is_a?(Solution)
174
175
  query = {
175
176
  subject: subject.is_a?(Variable) && bindings[subject.to_sym] ? bindings[subject.to_sym] : subject,
176
177
  predicate: predicate.is_a?(Variable) && bindings[predicate.to_sym] ? bindings[predicate.to_sym] : predicate,
data/lib/rdf/query.rb CHANGED
@@ -294,7 +294,7 @@ module RDF
294
294
  # Alias for `:graph_name`.
295
295
  # @param [Hash{Symbol => Object}] options
296
296
  # any additional keyword options
297
- # @option options [Hash{Symbol => RDF::Term}] bindings
297
+ # @option options [Hash{Symbol => RDF::Term}, RDF::Query::Solution] bindings
298
298
  # optional variable bindings to use
299
299
  # @option options [Boolean] :optimize
300
300
  # Optimize query before execution.
@@ -313,6 +313,7 @@ module RDF
313
313
  # Otherwise, a quick empty solution simplifies the logic below; no special case for
314
314
  # the first pattern
315
315
  @solutions = Query::Solutions(solutions)
316
+ bindings = bindings.to_h if bindings.is_a?(Solution)
316
317
 
317
318
  # If there are no patterns, just return the empty solution
318
319
  if empty?
@@ -341,7 +342,7 @@ module RDF
341
342
  bindings.each_key do |variable|
342
343
  if pattern.variables.include?(variable)
343
344
  unbound_solutions, old_solutions = old_solutions, Query::Solutions()
344
- bindings[variable].each do |binding|
345
+ Array(bindings[variable]).each do |binding|
345
346
  unbound_solutions.each do |solution|
346
347
  old_solutions << solution.merge(variable => binding)
347
348
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-14 00:00:00.000000000 Z
13
+ date: 2022-08-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header