relaton 3.1.14 → 3.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11ab89b10403b98a447c659bfcff3c5797f6af404f83ea0951ad4c99381bdfc7
4
- data.tar.gz: a90519205d323c6298e4771ff59384492d3d145f492edecc90ae468e0d049824
3
+ metadata.gz: 41a7f64e787b24723fa113edb1e212d200ab7eb382db19d54bc5551623b4d18a
4
+ data.tar.gz: eeabf573cb7643a521426c129e0c1ada4c81ed2cf993dfbaa5bc0bb9b1423b59
5
5
  SHA512:
6
- metadata.gz: 641202b0d40c80638a5935638221a38b73b1de7cd8dfb6f9cc57e9a1747e9d076689325c665dbbaac6400c46d255acccfa4a32c478577c80705fa4f1076457da
7
- data.tar.gz: 7cb1528532f44ecc7a5aa1c4069b46e7224d4a7c06015f0f6ac47074e4983e5b0c8ff98e2dcb753d7c2ed073d5893e77dc77c19fb02da6695d2c13e88fe9a41b
6
+ metadata.gz: 6d731f599c71306c4d2f155dcb2974b9aaa690cde0ceedb4dbeaff9be571b4f8df10bec0ba848cb858be2a140a2c77ae1c43249d1f64419b463ebb73a12d5db8
7
+ data.tar.gz: 0f805d43da7544dbb09e14d34f89923fce20b1923562d16aa960a3ce002e87e85680521b64c45331d8b98e29f0c1b72fb28c329804ae5490027cd72d19f44d56
@@ -63,17 +63,59 @@ module Relaton
63
63
  # receives the String and normalizes it itself, and the query is not
64
64
  # keyed - the same reading as a flavor's own miss.
65
65
  #
66
+ # The parse is memoized per identifier class (relaton#633): it is pure,
67
+ # and one compile re-reads the same reference many times, so the key
68
+ # path must not re-run a parslet parse per access (the plateau v5
69
+ # campaign measured the MatchData/string churn). The map is bounded
70
+ # FIFO, mutex-guarded (Db serves lookups from a workers pool), and
71
+ # caches misses too. Memoized instances are shared: the key path never
72
+ # mutates a parsed identifier (`fold_year` and `to_all_parts` copy),
73
+ # and an override of this method keeps its own behaviour.
74
+ #
66
75
  # @param ref [String]
67
76
  # @return [Pubid::Identifier, nil]
68
77
  def cache_pubid(ref)
69
- pubid_class&.parse(ref)
70
- rescue ArgumentError, ::Pubid::Errors::Error
71
- # relaton-bib carries the log facade; core specs load without it.
78
+ klass = pubid_class
79
+ return nil unless klass
80
+
81
+ Core::Processor.cached_pubid(klass, ref)
82
+ end
83
+
84
+ # The bounded memo behind .cache_pubid: `[identifier class, reference]`
85
+ # → parsed identifier or nil. Insertion order is the eviction order;
86
+ # the limit covers a compile's reference working set with headroom.
87
+ MEMO_LIMIT = 2000
88
+
89
+ @pubid_memo = {}
90
+ @memo_mutex = Mutex.new
91
+
92
+ class << self
93
+ def cached_pubid(klass, ref)
94
+ key = [klass, ref]
95
+ hit = nil
96
+ present = @memo_mutex.synchronize do
97
+ hit = @pubid_memo[key]
98
+ @pubid_memo.key?(key)
99
+ end
100
+ return hit if present
101
+
102
+ parsed =
103
+ begin
104
+ klass.parse(ref)
105
+ rescue ArgumentError, ::Pubid::Errors::Error
106
+ # relaton-bib carries the log facade; core specs load without it.
72
107
  require_relative "../bib"
73
- Relaton::Bib::Util.info "does not parse as this flavor's pubid; " \
74
- "passing the reference to the flavor as " \
75
- "written", "relaton-db", key: ref
76
- nil
108
+ Relaton::Bib::Util.info "does not parse as this flavor's pubid; " \
109
+ "passing the reference to the flavor as " \
110
+ "written", "relaton-db", key: ref
111
+ nil
112
+ end
113
+ @memo_mutex.synchronize do
114
+ @pubid_memo.shift while @pubid_memo.size >= MEMO_LIMIT
115
+ @pubid_memo[key] = parsed
116
+ end
117
+ parsed
118
+ end
77
119
  end
78
120
 
79
121
  # The reference as `get` receives it and the cache keys it (relaton#205):
@@ -647,6 +647,7 @@ module Relaton
647
647
  bib = IdamsParser.new(doc, self, local_errors).parse
648
648
  if bib.docnumber.nil?
649
649
  Util.warn "PubID parse error. Normtitle: `#{doc.normtitle}`, file: `#{file}`"
650
+ report_missing_id(doc.normtitle, info&.stdnumber, file)
650
651
  return nil
651
652
  end
652
653
  [idx, file, doc, bib, local_errors]
@@ -655,6 +656,26 @@ module Relaton
655
656
  nil
656
657
  end
657
658
 
659
+ #
660
+ # A numbered record that gets no id, with nothing to explain it
661
+ # (`RawbibIdParser.unexpected_miss?`), is a new parse failure, so the
662
+ # record is skipped but not silently: `report_errors` sends the String
663
+ # to the crawl's GitHub issue. The key is the normtitle, because the
664
+ # rawbib dataset repeats a record in many files. A forked worker hands
665
+ # @errors to the parent with its state (`merge_errors`).
666
+ #
667
+ # @param [String, nil] normtitle
668
+ # @param [String, nil] stdnumber
669
+ # @param [String] file
670
+ #
671
+ def report_missing_id(normtitle, stdnumber, file)
672
+ key = :"no_id #{normtitle}"
673
+ # @errors defaults to true, so `||=` would never assign.
674
+ return if @errors.key?(key) || !RawbibIdParser.unexpected_miss?(normtitle, stdnumber)
675
+
676
+ @errors[key] = "No IEEE id for normtitle `#{normtitle}`, stdnumber `#{stdnumber}` (#{file})"
677
+ end
678
+
658
679
  #
659
680
  # Merge a worker's local errors hash into the shared @errors hash,
660
681
  # preserving the existing AND semantics (`@errors[k] &&= v`).
@@ -29,6 +29,9 @@ module Relaton
29
29
  # @return [::Pubid::Ieee::Identifier, nil]
30
30
  #
31
31
  def parse(normtitle, stdnumber)
32
+ return nil if NOT_A_DESIGNATION.include?(stdnumber.to_s)
33
+
34
+ normtitle = normalize(normtitle, stdnumber.to_s)
32
35
  # Bespoke canonical string is the faithfulness reference: for the ~6% of
33
36
  # normtitles pubid can't parse directly it's the recovery source, and for
34
37
  # the rest it guards against pubid parsing but silently dropping a digit.
@@ -40,6 +43,69 @@ module Relaton
40
43
  rendered # neither pubid parse kept every digit — keep the bespoke id
41
44
  end
42
45
 
46
+ # Records whose `stdnumber` is free text, not an IEEE designation
47
+ # (relaton-data-ieee#11). A stripped title would name another document
48
+ # (`IEEE 1512` is a different standard), so they get no id, and the
49
+ # crawler skips them without an error. Each is the record's stdnumber.
50
+ NOT_A_DESIGNATION = [
51
+ "1512 Guide", # a guide for implementing IEEE 1512
52
+ "802.11ba Battery Life Improvement", # a technology report
53
+ "3006HistoricalData-2012", # reliability data for IEEE 3006
54
+ "PR 1533-1998", # IEEE/NEMI specification
55
+ "ST 430-9:2008 Am1:2011", # a SMPTE amendment
56
+ ].freeze
57
+
58
+ #
59
+ # True when a record gets no id and nothing explains it, so the crawler
60
+ # must report it. A record is explained when it is in
61
+ # {NOT_A_DESIGNATION}, when its `stdnumber` has no digit (a category
62
+ # such as "White Paper": {#parse_fallback} gives it no id on purpose),
63
+ # or when {#parse} gives an id that the IdamsParser drops (the
64
+ # {#fabricated_title_id?} guard).
65
+ #
66
+ # @param [String, nil] normtitle
67
+ # @param [String, nil] stdnumber
68
+ #
69
+ # @return [Boolean]
70
+ #
71
+ def unexpected_miss?(normtitle, stdnumber)
72
+ return false if NOT_A_DESIGNATION.include?(stdnumber.to_s)
73
+ return false unless stdnumber.to_s.match?(/\d/)
74
+
75
+ parse(normtitle.to_s, stdnumber.to_s).nil?
76
+ end
77
+
78
+ #
79
+ # Repair vendor spellings that neither pubid nor {#parse_fallback} can
80
+ # read, before both see the normtitle (relaton-data-ieee#10). Each rule
81
+ # is narrow: an id that pubid already parses must not change.
82
+ #
83
+ # @param [String] normtitle
84
+ # @param [String] stdnumber
85
+ #
86
+ # @return [String]
87
+ #
88
+ def normalize(normtitle, stdnumber) # rubocop:disable Metrics/AbcSize
89
+ # The Spanish NESC Handbook has a title for normtitle; the year is in
90
+ # stdnumber (`NESC HBK-2018`).
91
+ if stdnumber =~ /\ANESC HBK-(\d{4})\z/ && normtitle.start_with?("NESC Handbook, Premier Edition")
92
+ return "#{Regexp.last_match(1)} NESC Handbook, Premier Edition"
93
+ end
94
+
95
+ nt = normtitle.sub(/\b(IEEE )St(?=\d)/, '\1Std ') # IEEE St802.3de
96
+ .sub(/(?<=\d)_FDIS_D(?=\d)/, "/D") # P61886-1_FDIS_D3.1
97
+ .sub(/(?<=[a-z\d])REVD(?=\d)/i, "-REV/D") # P802.1QREVD2.2 (keeps the revision)
98
+ # PC37.10.1D5BA. A letter after the draft digits keeps
99
+ # `P802.1D5` (802.1D is a real standard) as it is.
100
+ .sub(/\A(IEEE PC?\d+(?:\.\d+)+)D(?=\d+[A-Z])/, '\1/D')
101
+ # An empty draft (`P11073-10415/D, February 2019`) takes the draft of
102
+ # stdnumber (`P11073-10415/D6, Feb 2019`).
103
+ if nt.include?("/D,") && (draft = stdnumber[%r{/D(\w[\w.]*)}, 1])
104
+ nt = nt.sub("/D,", "/D#{draft},")
105
+ end
106
+ nt
107
+ end
108
+
43
109
  #
44
110
  # True when `pid` is not a real IEEE designation but a leading fragment
45
111
  # of the document's own title, coined by a generic {#parse_fallback}
@@ -113,6 +179,9 @@ module Relaton
113
179
  # when /^(\d+HistoricalData)-(\d{4})/ then "IEEE #{$1}.#{$2}"
114
180
  # when /^(\d+)\.(\w+)\sBattery\sLife\sImprovement/ then "IEEE #{$1}-#{$2}"
115
181
  # when /^(\d+)\.(\w+)-(\d{4})\s\(Amendment/ then "IEEE #{$1}-#{$2}.#{$3}"
182
+ # No month: pubid renders a three-part draft with a month badly.
183
+ when "IEEE P1901.2_vD0.07.01, March 2013" # "IEEE P1901.2/D0.07.01-2013"
184
+ Renderer.new(publisher: "IEEE", number: "P1901", part: "2", draft: "0.07.01", year: "2013")
116
185
  when "A.I.E.E. No. 15 May-1928" then Renderer.new(publisher: "AIEE", number: "15", year: "1928", month: "05")
117
186
  # when "AIEE Nos 72 and 73 - 1932" then "AIEE 72_73.1932"
118
187
  when "IEEE Std P1073.1.3.4/D3.0" then Renderer.new(publisher: "IEEE", std: true, number: "P11073", part: "00101") # "IEEE Std P11073-00101"
@@ -527,7 +596,8 @@ module Relaton
527
596
  # number, part, year
528
597
  when /^(\d{2})\sIRE\s(\w+)[\s.](\w+)/ # "IRE #{$2}-#{$3}.#{yn $1}"
529
598
  Renderer.new(publisher: "IRE", number: $2, part: $3, year: yn($1))
530
- when /^(\w+)\.(\w+)-(|d{4})/ then Renderer.new(publisher: "IEEE", number: $1, part: $2, year: $3)
599
+ when /^(\w+)\.(\w+)-(\d{4}).*?(\s-\sRedline)?\z/
600
+ Renderer.new(publisher: "IEEE", number: $1, part: $2, year: $3, redline: !$4.nil?)
531
601
 
532
602
  # number, year
533
603
  when /^(\w+)-(\d{4})\D/ then Renderer.new(publisher: "IEEE", number: $1, year: $2)
@@ -710,13 +780,19 @@ module Relaton
710
780
  end
711
781
 
712
782
  def edition_to_s = edition ? "/E-#{edition}" : ""
713
- def draft_to_s = draft ? "/D-#{draft}" : ""
783
+ def draft_to_s = blank?(draft) ? "" : "/D-#{draft}"
714
784
  def rev_to_s = rev ? "/R-#{rev}" : ""
715
785
  def corr_to_s = corr ? "/Cor#{corr}" : ""
716
786
  def amd_to_s = amd ? "/Amd #{amd}" : ""
717
- def year_to_s = year ? "-#{year}" : ""
718
- def month_to_s = month ? "-#{month}" : ""
787
+ def year_to_s = blank?(year) ? "" : "-#{year}"
788
+ def month_to_s = blank?(month) ? "" : "-#{month}"
719
789
  def redline_to_s = redline ? " Redline" : ""
790
+
791
+ private
792
+
793
+ # An empty capture must print nothing: `/D-` or a bare `-` gives an
794
+ # id that pubid cannot parse (relaton-data-ieee#10).
795
+ def blank?(value) = value.to_s.empty?
720
796
  end
721
797
 
722
798
  def initialize(pubid)
@@ -41,9 +41,13 @@ module Relaton
41
41
  # report; when an open issue with this title already exists, add the run's
42
42
  # log as a comment on it instead.
43
43
  #
44
+ # A request that raises (timeout, DNS, TLS) is printed and answers
45
+ # false: a crawl calls this from `report_errors`, and an escaped error
46
+ # would fail the fetch step before its data is committed.
47
+ #
44
48
  # @return [Boolean, nil] true when GitHub took the issue or the
45
- # comment, false when it refused it, nil when nothing was sent
46
- # (an empty log or no GITHUB_TOKEN)
49
+ # comment, false when it refused it or the request raised, nil when
50
+ # nothing was sent (an empty log or no GITHUB_TOKEN)
47
51
  def create_issue
48
52
  return if @log.empty? || ENV["GITHUB_TOKEN"].nil?
49
53
 
@@ -52,6 +56,9 @@ module Relaton
52
56
  else
53
57
  report_response post_issue, "Issue created!", 201
54
58
  end
59
+ rescue StandardError => e
60
+ puts "Failed to report issue: #{e.class}: #{e.message}"
61
+ false
55
62
  end
56
63
 
57
64
  private
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "3.1.14".freeze
2
+ VERSION = "3.1.15".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.14
4
+ version: 3.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-26 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable