rdf 3.2.2 → 3.2.3

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: 2224a9a63fc05ccc786d780252f85ae706edd75f44ee7b459fedc824e53a9098
4
- data.tar.gz: 7768cfaff9ccfc49f4f96fcf896b084250a8d973277d113c87b8e90a5d7c818d
3
+ metadata.gz: 4482866c0eb2c223af0f3a88f1eba8e1e2126c238c1136ff992a795de5047699
4
+ data.tar.gz: 38e58d5e2bab26f76b55affe2cb362aff85afb49c7692056837b69d34cad6081
5
5
  SHA512:
6
- metadata.gz: bb59046c5aaa422b005d58b1f25eb8d9e2acd967116c55d2e657abb269256c1dc1c2706ebf555a82ddc3f1e3bddba23ce3d0f0f6581a5180ae7d9989764aee5b
7
- data.tar.gz: 13592fb59a53b641a970abc239e3c561e4c2ba1f2c85a1a7fe2003a897dd8305f3127fba4106a330a0fadff0083d66bc0d1d8572c30504eba369902d7fefec42
6
+ metadata.gz: 464c0043d3238fc3c4b077dfe6144a145b2c636b0e7de53ea6e8ce7ea96d2fd196b88053b1974d939650295416a2e4f07d298009d06d3a0320c297caf7883309
7
+ data.tar.gz: 0b27d632fe51c621bd50c27c2b7ecf5da91cd615e4e39ddf82e9f65517bddadcba4adb387a33807f8f2f0851b3a1d3c0429ccf41f4ec1610371c57fe28bd0709
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.2
1
+ 3.2.3
data/lib/rdf/model/uri.rb CHANGED
@@ -111,6 +111,10 @@ module RDF
111
111
  tag tel turn turns tv urn javascript
112
112
  ).freeze
113
113
 
114
+ # Characters in a PName which must be escaped
115
+ PN_ESCAPE_CHARS = /[~\.\-!\$&'\(\)\*\+,;=\/\?\#@%_]/.freeze
116
+ PN_ESCAPES = /\\#{PN_ESCAPE_CHARS}/.freeze
117
+
114
118
  ##
115
119
  # Cache size may be set through {RDF.config} using `uri_cache_size`.
116
120
  #
@@ -627,10 +631,14 @@ module RDF
627
631
  # RDF::URI('http://www.w3.org/2000/01/rdf-schema#').qname #=> [:rdfs, nil]
628
632
  # RDF::URI('http://www.w3.org/2000/01/rdf-schema#label').qname #=> [:rdfs, :label]
629
633
  # RDF::RDFS.label.qname #=> [:rdfs, :label]
634
+ # RDF::Vocab::DC.title.qname(
635
+ # prefixes: {dcterms: 'http://purl.org/dc/terms/'}) #=> [:dcterms, :title]
636
+ #
637
+ # @note within this software, the term QName is used to describe the tuple of prefix and suffix for a given IRI, where the prefix identifies some defined vocabulary. This somewhat contrasts with the notion of a [Qualified Name](https://www.w3.org/TR/2006/REC-xml-names11-20060816/#ns-qualnames) from XML, which are a subset of Prefixed Names.
630
638
  #
631
639
  # @param [Hash{Symbol => String}] prefixes
632
640
  # Explicit set of prefixes to look for matches, defaults to loaded vocabularies.
633
- # @return [Array(Symbol, Symbol)] or `nil` if no QName found
641
+ # @return [Array(Symbol, Symbol)] or `nil` if no QName found. The suffix component will not have [reserved characters](https://www.w3.org/TR/turtle/#reserved) escaped.
634
642
  def qname(prefixes: nil)
635
643
  if prefixes
636
644
  prefixes.each do |prefix, uri|
@@ -659,13 +667,25 @@ module RDF
659
667
  end
660
668
 
661
669
  ##
662
- # Returns a string version of the QName or the full IRI
670
+ # Returns a Prefixed Name (PName) or the full IRI with any [reserved characters](https://www.w3.org/TR/turtle/#reserved) in the suffix escaped.
671
+ #
672
+ # @example Using a custom prefix for creating a PNname.
673
+ # RDF::URI('http://purl.org/dc/terms/creator').
674
+ # pname(prefixes: {dcterms: 'http://purl.org/dc/terms/'})
675
+ # #=> "dcterms:creator"
663
676
  #
664
677
  # @param [Hash{Symbol => String}] prefixes
665
678
  # Explicit set of prefixes to look for matches, defaults to loaded vocabularies.
666
679
  # @return [String] or `nil`
680
+ # @see #qname
681
+ # @see https://www.w3.org/TR/rdf-sparql-query/#prefNames
667
682
  def pname(prefixes: nil)
668
- (q = self.qname(prefixes: prefixes)) ? q.join(":") : to_s
683
+ q = self.qname(prefixes: prefixes)
684
+ return self.to_s unless q
685
+ prefix, suffix = q
686
+ suffix = suffix.to_s.gsub(PN_ESCAPE_CHARS) {|c| "\\#{c}"} if
687
+ suffix.to_s.match?(PN_ESCAPE_CHARS)
688
+ [prefix, suffix].join(":")
669
689
  end
670
690
 
671
691
  ##
@@ -53,8 +53,7 @@ module RDF
53
53
  # "rdfs:subClassOf" => "http://example/SuperClass"
54
54
  # end
55
55
  #
56
- # @see http://www.w3.org/TR/curie/
57
- # @see http://en.wikipedia.org/wiki/QName
56
+ # @see https://www.w3.org/TR/rdf-sparql-query/#prefNames
58
57
  class Vocabulary
59
58
  extend ::Enumerable
60
59
 
@@ -379,15 +378,20 @@ module RDF
379
378
  alias_method :__properties__, :properties
380
379
 
381
380
  ##
382
- # Attempt to expand a Compact IRI/PName/QName using loaded vocabularies
381
+ # Attempt to expand a Compact IRI/PName using loaded vocabularies
383
382
  #
384
383
  # @param [String, #to_s] pname
384
+ # The local-part of the PName will will have [reserved character escapes](https://www.w3.org/TR/turtle/#reserved) unescaped.
385
385
  # @return [Term]
386
- # @raise [KeyError] if pname suffix not found in identified vocabulary
386
+ # @raise [KeyError] if pname suffix not found in identified vocabulary.
387
387
  # @raise [ArgumentError] if resulting URI is not valid
388
388
  def expand_pname(pname)
389
389
  return pname unless pname.is_a?(String) || pname.is_a?(Symbol)
390
390
  prefix, suffix = pname.to_s.split(":", 2)
391
+ # Unescape escaped PN_ESCAPE_CHARS
392
+ if suffix.match?(/\\#{RDF::URI::PN_ESCAPE_CHARS}/)
393
+ suffix = suffix.gsub(RDF::URI::PN_ESCAPES) {|matched| matched[1..-1]}
394
+ end
391
395
  if prefix == "rdf"
392
396
  RDF[suffix]
393
397
  elsif vocab_detail = RDF::Vocabulary.vocab_map[prefix.to_sym]
@@ -417,9 +421,10 @@ module RDF
417
421
  end
418
422
 
419
423
  ##
420
- # Return the Vocabulary term associated with a URI
424
+ # Return the Vocabulary term associated with a URI
421
425
  #
422
- # @param [RDF::URI] uri
426
+ # @param [RDF::URI, String] uri
427
+ # If `uri` has is a pname in a locded vocabulary, the suffix portion of the PName will have escape characters unescaped before resolving against the vocabulary.
423
428
  # @return [Vocabulary::Term]
424
429
  def find_term(uri)
425
430
  uri = RDF::URI(uri)
@@ -428,7 +433,8 @@ module RDF
428
433
  if vocab.ontology == uri
429
434
  vocab.ontology
430
435
  else
431
- vocab[uri.to_s[vocab.to_uri.to_s.length..-1].to_s]
436
+ suffix = uri.to_s[vocab.to_uri.to_s.length..-1].to_s
437
+ vocab[suffix]
432
438
  end
433
439
  end
434
440
  end
@@ -643,12 +649,31 @@ module RDF
643
649
  alias_method :__name__, :name
644
650
 
645
651
  ##
646
- # Returns a suggested CURIE/PName prefix for this vocabulary class.
652
+ # Returns a suggested vocabulary prefix for this vocabulary class.
647
653
  #
648
654
  # @return [Symbol]
649
655
  # @since 0.3.0
650
656
  def __prefix__
651
- __name__.split('::').last.downcase.to_sym
657
+ instance_variable_defined?(:@__prefix__) ?
658
+ @__prefix__ :
659
+ __name__.split('::').last.downcase.to_sym
660
+ end
661
+
662
+ ##
663
+ # Sets the vocabulary prefix to use for this vocabulary..
664
+ #
665
+ # @example Overriding a standard vocabulary prefix.
666
+ # RDF::Vocab::DC.__prefix__ = :dcterms
667
+ # RDF::Vocab::DC.title.pname #=> 'dcterms:title'
668
+ #
669
+ # @param [Symbol] prefix
670
+ # @return [Symbol]
671
+ # @since 3.2.3
672
+ def __prefix__=(prefix)
673
+ params = RDF::Vocabulary.vocab_map[__prefix__]
674
+ @__prefix__ = prefix.to_sym
675
+ RDF::Vocabulary.register(@__prefix__, self, **params)
676
+ @__prefix__
652
677
  end
653
678
 
654
679
  protected
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.2
4
+ version: 3.2.3
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-01-03 00:00:00.000000000 Z
13
+ date: 2022-01-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header