pubid 2.0.51 → 2.0.52

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.
@@ -0,0 +1,169 @@
1
+ = IHO URN schemes
2
+
3
+ This file is the single home of the IHO flavor's URN documentation (the
4
+ per-flavor split of the former `docs/URN-SCHEMES.adoc`, owner ruling
5
+ 2026-11-25: "for URN schemes how can we mix up different flavors in 1
6
+ file? SPLIT THE FILE!"). It covers the three schemes the flavor carries:
7
+
8
+ 1. the official URN (`#to_urn`) — the adopted IHO MRN guidance form for
9
+ the S/P/M series, the legacy positional form for the B/C series;
10
+ 2. the legacy positional `urn:iho:` grammar — decodable for every
11
+ series, emitted only by the B/C series;
12
+ 3. the pubid-scheme URN (`#to_pubid_urn`) — pubid's own
13
+ `urn:pubid:iho:` codec, not governed by the IHO guidance.
14
+
15
+ The implementations are `lib/pubid/iho/urn_generator.rb` and
16
+ `lib/pubid/iho/urn_parser.rb`; the flavor's component law lives in
17
+ `lib/pubid/iho/CLAUDE.md`.
18
+
19
+ == The adopted IHO MRN guidance (owner ruling, 2026-11-25)
20
+
21
+ Source: S-100WG4, "MRN Guidelines for IHO" (the IHO Level guidance for
22
+ publications, pages 8-9). The guidance proposes the Publications MRN
23
+
24
+ urn:mrn:iho:pub:<publication type>:<publication name or number>:<edition number>[:<correction number>[:<clarification number>[:<optional and additional version information>]]]
25
+
26
+ with the publication types `bathy` | `cb` | `reg` | `per` | `spec`, and
27
+ the example `urn:mrn:iho:pub:spec:s57:3:1:supplement3` (S-57 Ed 3,
28
+ Corr. 1, Supplement 3). IHO's own printed S-98 metadata carries
29
+ `urn:mrn:iho:pub:spec:s98:1.0.0` — the DOTTED edition in the canonical
30
+ 4th position, which this flavor adopts verbatim.
31
+
32
+ pubid adopts the guidance as the flavor's official-URN emission for the
33
+ series the guidance types:
34
+
35
+ [cols="3,1,4,4",options="header"]
36
+ |===
37
+ | series | type | law | example
38
+ | S (Standards and Specifications) | `spec` | the guidance's own code | `IHO S-44 5.0.0` → `urn:mrn:iho:pub:spec:s44:5.0.0`
39
+ | P (Publication, the periodic series) | `per` | the guidance's Periodic Publications code | `IHO P-5 Vol. 2024` → `urn:mrn:iho:pub:per:p5:vol-2024`
40
+ | M (Miscellaneous Base Regulatory Publications) | `reg` | the guidance's own code | `IHO M-2 Sup 1` → `urn:mrn:iho:pub:reg:m2:sup-1`
41
+ | B (Bibliographic) | — | no guidance code: the legacy emission below, until IHO assigns one | `IHO B-4 2.19.0` → `urn:iho:b:4:ed-2.19.0`
42
+ | C (Circular Letter) | — | no guidance code: the legacy emission below, until IHO assigns one | `IHO C-13 1.0.0` → `urn:iho:c:13:ed-1.0.0`
43
+ |===
44
+
45
+ === The name form
46
+
47
+ `<name>` is the lowercase series letter + number — the guidance's own
48
+ `s57`/`s98` spelling:
49
+
50
+ IHO S-100 -> urn:mrn:iho:pub:spec:s100
51
+
52
+ === The S-158 member encoding (issue #774)
53
+
54
+ S-158 is a framework publication defining a series of separate check
55
+ specifications (`S-158:100` generic, `S-158:1xx` product-specific,
56
+ `S-158:98` interoperability, `S-158:128` catalogue; the `checks_for`
57
+ component carries the member number). The member joins the name segment
58
+ hyphenated — the documented fleet extension of the guidance for
59
+ compound publication numbers — so the edition stays in its canonical
60
+ 4th position exactly like the S-98 metadata:
61
+
62
+ S-158 1.0.0 -> urn:mrn:iho:pub:spec:s158:1.0.0
63
+ S-158:102 1.0.0 -> urn:mrn:iho:pub:spec:s158-102:1.0.0
64
+
65
+ The member designator is order-stable: every citation spelling
66
+ (`S-158 0.2.0 Part S-102`, `S-158 Part S-102 0.2.0`, `S-158-S-102`,
67
+ the draft-era aliases of issue #775) emits the identical URN.
68
+
69
+ === The edition segment
70
+
71
+ The dotted `x.y.z` edition emits BARE (not `ed-`-prefixed), in the
72
+ canonical 4th segment — the S-98 precedent. An edition-non-specific
73
+ reference emits no edition segment. A component's own edition (the
74
+ separately-published mode) rides as `ed-` right after its component,
75
+ keeping the two modes decodable:
76
+
77
+ IHO P-6 Vol. 2 1.0.1 -> urn:mrn:iho:pub:per:p6:vol-2:ed-1.0.1
78
+ IHO S-98 Part A 1.0.0 (2024) -> urn:mrn:iho:pub:spec:s98:part-A:ed-1.0.0:year-2024
79
+
80
+ === The trailing atoms
81
+
82
+ The components the guidance's tail slots do not model emit as
83
+ lowercase marker segments, RFC 3986-safe, in the containment order.
84
+ Values are case-preserved (identity law: `part-A` and `part-a` are
85
+ distinct documents; `appendix-D-2` keeps its letter). The Appendix
86
+ subnumber hyphen-joins its appendix as one compound segment; the base
87
+ with-year qualifier keeps its `year-` marker; the S-4 spec citation is
88
+ a child of its part (`spec-`, `specsub-`, `specvar-`; the SECTION is
89
+ derivable, never emitted):
90
+
91
+ [:year-<yyyy>][:sup-<n>[:ed-…][:year-…]]
92
+ [:part-<X>[:ed-…][:year-…]]
93
+ [:spec-<n>[:specsub-<n>][:specvar-<X>]]
94
+ [:annex-<A>[…]]
95
+ [:appendix-<B>[-<sub>][…]]
96
+ [:vol-<n>[:issue-<n>][…]]
97
+
98
+ Examples:
99
+
100
+ IHO S-100 5.0.0 Part 2 (2024) -> urn:mrn:iho:pub:spec:s100:5.0.0:year-2024:part-2
101
+ IHO S-122 1.0.0 Appendix D-2 -> urn:mrn:iho:pub:spec:s122:1.0.0:appendix-D-2
102
+ IHO S-4 4.10.0 B-401 -> urn:mrn:iho:pub:spec:s4:4.10.0:part-B:spec-401
103
+ IHO P-1 Vol. 30 (2) -> urn:mrn:iho:pub:per:p1:vol-30:issue-2
104
+
105
+ The guidance's bare correction/clarification slots (the `s57:3:1`
106
+ form) are NOT modeled faces — the flavor has no correction component —
107
+ and a bare digit tail segment rejects on decode.
108
+
109
+ == The legacy positional grammar (decode-only for S/P/M; the B/C emission)
110
+
111
+ The pre-guidance emission — `urn:iho:<type>:<number>[:ed-<x.y.z>]
112
+ [:sup-…][:part-…][:annex-…][:appendix-…][:<sub>][:vol-…][:issue-…]
113
+ [:year-…]` — stays fully decodable for every series and remains the
114
+ emission of the B/C series (no guidance type code). Its laws:
115
+
116
+ - the docnumber occupies the first bare number segment; a further bare
117
+ digit segment binds the S-158 member (`urn:iho:s:158:100`), never
118
+ glued into the number (issue #774);
119
+ - `ed-` and `year-` are POSITIONAL: the edition attaches to the node it
120
+ follows (the base when no component precedes it, else that
121
+ component's own edition); a year belongs to a component only when it
122
+ follows that component's own edition;
123
+ - containment: part ⊃ annex ⊃ appendix ⊃ subnumber (the bare digit
124
+ atom, only directly after its appendix); vol ⊃ issue;
125
+ - the number may span bare segments only through the member slot; a
126
+ colon number and a volume stay distinct because the volume is
127
+ marker-tagged (`urn:iho:s:158:2024` vs `urn:iho:s:158:vol-2024` —
128
+ the #637 hazard, kept under the positional scheme);
129
+ - the legacy 2.0.x spellings (the dotted keys `part.4a`/`suppl.1`/
130
+ `ap.A`/`vol.30`/`issue.2`/`appendix.D-2`, the bare `a.b.c` edition
131
+ segment, the `y.2024` yearbook tag) decode but are never emitted.
132
+
133
+ Both decode paths build through `Builder.build` — the S-158 alias
134
+ unification (a draft-era `part-S-102` URN resolves to the
135
+ `checks_for` identity) and every other semantic validation is shared
136
+ with the text parse.
137
+
138
+ == The pubid-scheme URN (`urn:pubid:iho:`)
139
+
140
+ pubid's own lossless codec (issue #670;
141
+ `lib/pubid/iho/pubid_urn_schema.rb`). NOT governed by the IHO guidance
142
+ — the atoms carry the full typed model and always round-trip
143
+ (`Pubid.parse_urn(id.to_pubid_urn).to_hash == id.to_hash`).
144
+
145
+ urn:pubid:iho:std:100:ed-5.0.0:year-2024:part-2 IHO S-100 5.0.0 Part 2 (2024)
146
+ urn:pubid:iho:std:158:checks-102:ed-1.0.0 IHO S-158:102 1.0.0
147
+ urn:pubid:iho:std:122:ed-1.0.0:appendix-D:appsub-2 IHO S-122 1.0.0 Appendix D-2
148
+ urn:pubid:iho:pub:5:vol-2024 IHO P-5 Vol. 2024
149
+
150
+ Types: `std` (S), `pub` (P), `m` (M), `b` (B), `cl` (C), `id`.
151
+ Atoms, canonical order: `checks-` (the S-158 member, riding the
152
+ document code before the edition — issue #774), `ed-`, `year-`,
153
+ `sup-`/`suped-`/`supyear-`, `part-`/`parted-`/`party-`, `spec-`/
154
+ `specsub-`/`specvar-`, `annex-`/`anned-`/`annyear-`, `appendix-`/
155
+ `appsub-`/`apped-`/`appyear-`, `vol-`/`issue-`/`voled-`/`voly-`. Case
156
+ is preserved (`part-A`); the yearbook year is a volume (`vol-2024`, no
157
+ `year-` value). The S-158 member emits the typed `checks-<NNN>` atom —
158
+ the draft-era part-faceted emission (`part-S-102`, `parted-`) is dead:
159
+ the `from_hash` unification redirects the legacy form onto the
160
+ `checks_for` identity, so the legacy URN fails the canonical gate.
161
+
162
+ == relaton-side follow-ups (not this repo)
163
+
164
+ The official-URN namespace moved (`urn:mrn:iho:pub:...` for S/P/M) and
165
+ the S-158 member shape changed (`s158-102`, not `s:158:100` or the
166
+ part form): relaton-data-iho needs a re-crawl when this gem ships, and
167
+ the frozen testsuite corpus rows are re-frozen in the coupled corpus
168
+ round. The pubid-scheme slugs changed for S-158 identities
169
+ (`iho/std/158/checks-102/...`).
@@ -4,14 +4,62 @@ module Pubid
4
4
  module Iho
5
5
  # Generates URN strings for IHO identifiers.
6
6
  #
7
- # The URN is the documented positional segment grammar (see the
8
- # grammar header in pubid-grammar's grammars/iho.parg and the flavor
9
- # notes): containment-ordered, one semantic atom per segment, every
10
- # non-number component a marker-prefixed segment whose marker is the
11
- # lowercased human-face token (edition follows ISO's ed- precedent):
7
+ # == The adopted IHO MRN guidance (owner ruling, 2026-11-25)
12
8
  #
13
- # urn:iho:<type>:<number>[:ed-<x.y.z>][:sup-<n>][:part-<X>]
14
- # [:annex-<A>][:appendix-<B>][:<sub>][:vol-<n>][:issue-<n>]
9
+ # The series the guidance gives a publication type emit the guidance
10
+ # form (S-100WG4, "MRN Guidelines for IHO"; the guidance's own
11
+ # examples are s57 / urn:mrn:iho:pub:spec:s57:3:1:supplement3 and —
12
+ # IHO's printed S-98 metadata — urn:mrn:iho:pub:spec:s98:1.0.0):
13
+ #
14
+ # urn:mrn:iho:pub:<type>:<name>[:<edition>][:<trailing atoms>...]
15
+ #
16
+ # - <type>: spec (S series, Standards and Specifications) / per
17
+ # (P series, periodic publications) / reg (M series, Miscellaneous
18
+ # Base Regulatory Publications). The B (Bibliographic) and C
19
+ # (Circular Letter) series have no guidance type code — until IHO
20
+ # assigns one they keep the legacy positional emission below.
21
+ # - <name>: sNNN — the lowercase series letter + number. The S-158
22
+ # member joins the name segment hyphenated (the fleet extension of
23
+ # the guidance for compound publication numbers, keeping the
24
+ # edition in its canonical 4th position):
25
+ #
26
+ # S-158 1.0.0 -> urn:mrn:iho:pub:spec:s158:1.0.0
27
+ # S-158:102 1.0.0 -> urn:mrn:iho:pub:spec:s158-102:1.0.0
28
+ #
29
+ # - <edition>: the bare dotted x.y.z, NOT ed-prefixed (the S-98
30
+ # precedent). Absent for an edition-non-specific reference.
31
+ # - The trailing atoms carry the components the guidance's tail
32
+ # slots do not model: lowercase marker tokens, RFC 3986-safe,
33
+ # values case-preserved (identity law: part-A and part-a are
34
+ # distinct documents). A component's own edition rides as ed-
35
+ # right after it (the duality law); the Appendix subnumber
36
+ # hyphen-joins its appendix; the base with-year qualifier keeps
37
+ # its year- marker. The guidance's bare correction/clarification
38
+ # slots (the s57:3:1 form) are not modeled faces — never emitted.
39
+ #
40
+ # Examples (the guidance form):
41
+ # - urn:mrn:iho:pub:spec:s44:5.0.0 IHO S-44 5.0.0
42
+ # - urn:mrn:iho:pub:spec:s100:5.0.0:year-2024:part-2 IHO S-100 5.0.0 Part 2 (2024)
43
+ # - urn:mrn:iho:pub:spec:s122:1.0.0:appendix-D-2 IHO S-122 1.0.0 Appendix D-2
44
+ # - urn:mrn:iho:pub:spec:s4:4.10.0:part-B:spec-401 IHO S-4 4.10.0 B-401
45
+ # - urn:mrn:iho:pub:spec:s158-102:1.0.0 IHO S-158:102 1.0.0
46
+ # - urn:mrn:iho:pub:reg:m2:sup-1 IHO M-2 Sup 1
47
+ # - urn:mrn:iho:pub:per:p5:vol-2024 IHO P-5 Vol. 2024
48
+ #
49
+ # == The legacy positional scheme (the B/C emission; decodable for
50
+ # every series, never emitted for S/P/M)
51
+ #
52
+ # The pre-guidance positional grammar (containment-ordered, one
53
+ # semantic atom per segment, marker = the lowercased human-face
54
+ # token; ed- follows ISO's RFC 5141 precedent):
55
+ #
56
+ # urn:iho:<type>:<number>[:ed-<x.y.z>][:year-<yyyy>]
57
+ # [:sup-<n>[:ed-<x.y.z>][:year-<yyyy>]]
58
+ # [:part-<X>[:ed-<x.y.z>][:year-<yyyy>]]
59
+ # [:spec-<n>[:specsub-<n>][:specvar-<X>]]
60
+ # [:annex-<A>[...]]
61
+ # [:appendix-<B>[:<sub>][...]]
62
+ # [:vol-<n>[:issue-<n>][...]]
15
63
  # [:year-<yyyy>]
16
64
  #
17
65
  # Containment: part contains annexes, annex contains appendices, the
@@ -20,18 +68,10 @@ module Pubid
20
68
  # locator — the yearbook year IS a volume (P-5 Vol. 2024 gives
21
69
  # vol-2024), so a periodical identifier has no year segment; the
22
70
  # year- segment exists only for the standards with-year qualifier.
23
- # Both are marker-tagged so neither can collide with a colon-number
24
- # segment (the number is not escaped and may span bare segments:
25
- # "IHO S-158:100" gives "urn:iho:s:158:100").
26
71
  #
27
- # Examples:
28
- # - urn:iho:s:44:ed-5.0.0 IHO S-44 5.0.0
29
- # - urn:iho:s:100:ed-5.0.0:part-2:year-2024 IHO S-100 5.0.0 Part 2 (2024)
30
- # - urn:iho:s:122:ed-1.0.0:appendix-D:2 IHO S-122 1.0.0 Appendix D-2
31
- # - urn:iho:m:2:sup-1 IHO M-2 Sup 1
32
- # - urn:iho:p:5:vol-2024 IHO P-5 Vol. 2024
33
- # - urn:iho:p:1:vol-30:issue-2 IHO P-1 Vol. 30 (2)
34
- # - urn:iho:s:4:ed-4.10.0:part-B:spec-401 IHO S-4 4.10.0 B-401
72
+ # Examples (the legacy form):
73
+ # - urn:iho:b:4:ed-2.19.0 IHO B-4 2.19.0
74
+ # - urn:iho:c:13:ed-1.0.0 IHO C-13 1.0.0
35
75
  class UrnGenerator
36
76
  attr_reader :identifier
37
77
 
@@ -39,12 +79,39 @@ module Pubid
39
79
  @identifier = identifier
40
80
  end
41
81
 
42
- # [component, marker] pairs in the containment/canonical-face
43
- # order. A component edition/year emits right after its component
44
- # (the ed- segment attaches to the node it follows, recording the
45
- # separately-published mode). nil markers emit their component as
46
- # a BARE atom (the appendix subnumber directly after its
47
- # appendix).
82
+ # The guidance publication type per series letter. S = Standards
83
+ # and Specifications -> spec (the owner ruling names the guidance
84
+ # code explicitly); P = the periodic publications -> per; M =
85
+ # Miscellaneous (Base Regulatory Publications) -> reg. B and C
86
+ # have no guidance code (legacy emission until IHO assigns one).
87
+ MRN_TYPES = { "S" => "spec", "P" => "per", "M" => "reg" }.freeze
88
+
89
+ # The guidance-form trailing atoms in containment order — the same
90
+ # order the legacy scheme prints them. The Appendix subnumber is
91
+ # handled inline (it hyphen-joins its appendix, one compound
92
+ # segment); the checks_for member rides the name segment.
93
+ MRN_SEGMENTS = [
94
+ [:year, "year"],
95
+ [:supplement, "sup"], [:supplement_edition, "ed"],
96
+ [:supplement_year, "year"],
97
+ [:part, "part"], [:part_edition, "ed"], [:part_year, "year"],
98
+ # the S-4 spec citation: a child of its part (the citation
99
+ # letter rides the part- atom); the SECTION is NOT emitted —
100
+ # derivable from the spec's hundreds digit.
101
+ [:spec, "spec"], [:spec_sub, "specsub"], [:spec_variant, "specvar"],
102
+ [:annex, "annex"], [:annex_edition, "ed"], [:annex_year, "year"],
103
+ [:appendix, "appendix"], [:appendix_subnumber, nil],
104
+ [:appendix_edition, "ed"], [:appendix_year, "year"],
105
+ [:volume, "vol"], [:issue, "issue"], [:volume_edition, "ed"],
106
+ [:volume_year, "year"]
107
+ ].freeze
108
+
109
+ # [component, marker] pairs of the legacy positional scheme, in the
110
+ # containment/canonical-face order. A component edition/year emits
111
+ # right after its component (the ed- segment attaches to the node
112
+ # it follows, recording the separately-published mode). nil markers
113
+ # emit their component as a BARE atom (the appendix subnumber
114
+ # directly after its appendix).
48
115
  SEGMENTS = [
49
116
  [:edition, "ed"], [:year, "year"],
50
117
  [:supplement, "sup"], [:supplement_edition, "ed"],
@@ -52,8 +119,7 @@ module Pubid
52
119
  [:part, "part"], [:part_edition, "ed"], [:part_year, "year"],
53
120
  # the S-4 spec citation: a child of its part (the citation
54
121
  # letter rides the part- atom), the dotted sub and the
55
- # parenthesized variant its own children. The SECTION is NOT
56
- # emitted — derivable from the spec's hundreds digit.
122
+ # parenthesized variant its own children.
57
123
  [:spec, "spec"], [:spec_sub, "specsub"], [:spec_variant, "specvar"],
58
124
  [:annex, "annex"], [:annex_edition, "ed"], [:annex_year, "year"],
59
125
  [:appendix, "appendix"], [:appendix_subnumber, nil],
@@ -63,6 +129,57 @@ module Pubid
63
129
  ].freeze
64
130
 
65
131
  def generate
132
+ letter = identifier.class.type[:short].to_s
133
+ MRN_TYPES[letter] ? generate_mrn(MRN_TYPES[letter]) : generate_legacy
134
+ end
135
+
136
+ private
137
+
138
+ # The guidance form: type, name (sNNN / s158-NNN), the bare dotted
139
+ # edition, then the trailing atoms in containment order.
140
+ def generate_mrn(mrn_type)
141
+ parts = ["urn:mrn:iho:pub", mrn_type, mrn_name]
142
+ parts << identifier.edition if identifier.edition
143
+ parts.concat(mrn_segments)
144
+ parts.join(":")
145
+ end
146
+
147
+ # The lowercase name form (the guidance's "s57"/"s98" spelling).
148
+ # The S-158 member joins hyphenated so the edition stays in its
149
+ # canonical 4th position: s158-102.
150
+ def mrn_name
151
+ name = +"#{identifier.class.type[:short].downcase}#{identifier.number}"
152
+ name << "-#{identifier.checks_for}" if identifier.checks_for
153
+ name
154
+ end
155
+
156
+ def mrn_segments
157
+ MRN_SEGMENTS.filter_map do |component, marker|
158
+ case component
159
+ when :appendix
160
+ value = identifier.appendix
161
+ next unless value
162
+
163
+ segment = +"appendix-#{value}"
164
+ # the subnumber hyphen-joins its appendix (one compound
165
+ # segment, RFC 3986-safe)
166
+ segment << "-#{identifier.appendix_subnumber}" if
167
+ identifier.appendix_subnumber
168
+ segment
169
+ when :appendix_subnumber
170
+ next # compound-joined into its appendix segment above
171
+ else
172
+ value = identifier.public_send(component)
173
+ next unless value
174
+
175
+ "#{marker}-#{value}"
176
+ end
177
+ end
178
+ end
179
+
180
+ # The legacy positional form (B/C today; the shape every legacy
181
+ # urn:iho: URN decodes from).
182
+ def generate_legacy
66
183
  parts = ["urn", "iho"]
67
184
  parts << identifier.class.type[:short].to_s.downcase
68
185
  parts << identifier.number.to_s
@@ -70,8 +187,6 @@ module Pubid
70
187
  parts.join(":")
71
188
  end
72
189
 
73
- private
74
-
75
190
  def component_segments
76
191
  SEGMENTS.filter_map do |component, marker|
77
192
  value = identifier.public_send(component)
@@ -2,25 +2,47 @@
2
2
 
3
3
  module Pubid
4
4
  module Iho
5
- # Parses IHO URNs back into identifiers through the documented
6
- # positional segment grammar (the same grammar the generator emits;
7
- # the segment table lives in the grammar header and the flavor notes):
5
+ # Parses IHO URNs back into identifiers, both emitted schemes:
6
+ #
7
+ # == The adopted IHO MRN guidance form (S/P/M emission)
8
+ #
9
+ # urn:mrn:iho:pub:<type>:<name>[:<edition>][:<trailing atoms>...]
10
+ #
11
+ # - <type>: spec / per / reg — the guidance publication types
12
+ # (Standards and Specifications, periodic publications,
13
+ # Miscellaneous Base Regulatory Publications); each maps back to
14
+ # its series letter.
15
+ # - <name>: sNNN — the lowercase series letter + number; the S-158
16
+ # member joins hyphenated (s158-102), the fleet extension of the
17
+ # guidance for compound publication numbers.
18
+ # - <edition>: the bare dotted x.y.z right after the name (the
19
+ # guidance's canonical 4th segment; the S-98 precedent).
20
+ # - The trailing atoms are the lowercase marker segments: a
21
+ # component's own edition rides as ed- right after it (the duality
22
+ # law), the Appendix subnumber hyphen-joins its appendix
23
+ # (appendix-D-2), values case-preserved. The guidance's bare
24
+ # correction/clarification slots (the s57:3:1 form) are not modeled
25
+ # faces — a bare digit tail segment rejects as unexpected.
26
+ #
27
+ # == The legacy positional form (B/C emission; decodable for every
28
+ # series, never emitted for S/P/M)
8
29
  #
9
30
  # urn:iho:<type>:<number>[:ed-<x.y.z>][:sup-<n>][:part-<X>]
10
31
  # [:spec-<n>[:specsub-<n>][:specvar-<X>]][:annex-<A>]
11
32
  # [:appendix-<B>][:<sub>][:vol-<n>][:issue-<n>][:year-<yyyy>]
12
33
  #
13
34
  # Segment discipline (mirrors the ISO URN parser's strictness):
14
- # - the docnumber occupies every leading bare number segment up to
15
- # the first marker, so a colon number ("158:100") round-trips
16
- # without escaping;
35
+ # - the docnumber occupies the first bare number segment; a further
36
+ # bare digit segment binds checks_for — the S-158 member number as
37
+ # its own segment ("urn:iho:s:158:100"), never glued into the
38
+ # number (issue #774);
17
39
  # - every other component is a marker-prefixed segment validated
18
40
  # against its own value pattern — unknown, reordered or junk
19
41
  # segments raise {Pubid::Errors::UrnParseError}, never
20
42
  # mis-consume;
21
- # - the appendix subnumber is a bare digit atom allowed only
22
- # directly after its appendix segment (a year is always
23
- # marker-tagged, so a bare digit there can only be the subnumber);
43
+ # - the appendix subnumber is either the bare digit atom directly
44
+ # after its appendix segment (the legacy emission) or the
45
+ # hyphen-joined compound value ("appendix-D-2", the MRN emission);
24
46
  # - the issue is allowed only beside its volume and validated as
25
47
  # digits;
26
48
  # - the S-4 spec atom is a child of its part (the citation letter
@@ -35,22 +57,39 @@ module Pubid
35
57
  # appendix values stored the subnumber inside one string, "D-2",
36
58
  # which decodes into the two components).
37
59
  #
60
+ # Both paths build through Builder.build — the S-158 alias
61
+ # unification (a draft-era part-S-102 URN decodes to the checks_for
62
+ # identity) and every other semantic validation is shared with the
63
+ # text parse.
64
+ #
38
65
  # Examples:
39
- # - urn:iho:s:44:ed-5.0.0 → IHO S-44 5.0.0
40
- # - urn:iho:s:100:ed-5.0.0:part-2 → IHO S-100 5.0.0 Part 2
41
- # - urn:iho:s:122:ed-1.0.0:appendix-D:2 → IHO S-122 1.0.0 Appendix D-2
42
- # - urn:iho:p:5:vol-2024 → IHO P-5 Vol. 2024
43
- # - urn:iho:p:1:vol-30:issue-2 → IHO P-1 Vol. 30 (2)
44
- # - urn:iho:s:158:100 → IHO S-158:100
45
- # - urn:iho:s:4:ed-4.10.0:part-B:spec-401 → IHO S-4 4.10.0 B-401
66
+ # - urn:mrn:iho:pub:spec:s44:5.0.0 → IHO S-44 5.0.0
67
+ # - urn:mrn:iho:pub:spec:s158-102:1.0.0 → IHO S-158:102 1.0.0
68
+ # - urn:mrn:iho:pub:reg:m2:sup-1 → IHO M-2 Sup 1
69
+ # - urn:mrn:iho:pub:per:p1:vol-30:issue-2 → IHO P-1 Vol. 30 (2)
70
+ # - urn:iho:s:44:ed-5.0.0 → IHO S-44 5.0.0
71
+ # - urn:iho:s:158:100:ed-1.0.0 → IHO S-158:100 1.0.0
72
+ # - urn:iho:s:4:ed-4.10.0:part-B:spec-401 → IHO S-4 4.10.0 B-401
46
73
  class UrnParser < Pubid::UrnParser::Base
47
74
  TYPE_LETTERS = %w[s p m b c].freeze
48
75
 
76
+ # The guidance publication type -> series letter (the emission's
77
+ # MRN_TYPES inverted). bathy/cb have no series in this flavor; an
78
+ # unknown type rejects.
79
+ MRN_TYPE_LETTERS = { "spec" => "S", "per" => "P", "reg" => "M" }.freeze
80
+
81
+ MRN_PREFIX = "urn:mrn:iho:pub:"
82
+ # The publication name: the lowercase series letter + number, the
83
+ # S-158 member hyphen-joined (s158-102).
84
+ MRN_NAME_RE = /\A([spmbc])(\d+)(?:-(\d+))?\z/
85
+
49
86
  # Marker => attribute, with the value pattern each marker's slot
50
87
  # accepts. The patterns mirror the grammar's own production rules
51
88
  # (upper-case letters are case-preserved; "part" allows the
52
89
  # digits-then-letters compound like "4a" beside a lone letter; the
53
- # volume takes any serial locator, yearbook years included).
90
+ # volume takes any serial locator, yearbook years included;
91
+ # "appendix" allows the hyphen-joined compound "D-2" — the MRN
92
+ # emission — which splits into the appendix and its subnumber).
54
93
  MARKERS = {
55
94
  "ed" => [:edition, /\A\d+\.\d+\.\d+\z/],
56
95
  "sup" => [:supplement, /\A\d+\z/],
@@ -59,7 +98,7 @@ module Pubid
59
98
  "specsub" => [:spec_sub, /\A\d+\z/],
60
99
  "specvar" => [:spec_variant, /\A[A-Z]+\z/],
61
100
  "annex" => [:annex, /\A[A-Z]\z/],
62
- "appendix" => [:appendix, /\A(?:[A-Z]|\d+)\z/],
101
+ "appendix" => [:appendix, /\A(?:[A-Z](?:-\d+)?|\d+)\z/],
63
102
  "vol" => [:volume, /\A\d+\z/],
64
103
  "issue" => [:issue, /\A\d+\z/],
65
104
  "year" => [:year, /\A(?:19|20)\d{2}\z/],
@@ -100,11 +139,64 @@ module Pubid
100
139
  SUBNUMBER_RE = /\A\d+\z/
101
140
  # The docnumber's own charset: digits with : / - suffix runs.
102
141
  NUMBER_RE = /\A\d+(?:[:\/-]\d+)*\z/
142
+ # The further bare segments that bind the S-158 member number.
143
+ CHECKS_SEGMENT_RE = /\A\d+\z/
103
144
 
104
145
  def parse_urn(urn)
146
+ return parse_mrn_urn(urn) if urn.downcase.start_with?(MRN_PREFIX)
147
+
148
+ parse_legacy_urn(urn)
149
+ end
150
+
151
+ private
152
+
153
+ # The guidance-form decode: publication type, name (number +
154
+ # optional S-158 member), the bare dotted edition, then the shared
155
+ # marker machinery (the positional ed-/year- attachment included).
156
+ # The body is NOT case-folded: values are case-preserved
157
+ # (appendix-D-2, part-B); only the type token lowercases.
158
+ def parse_mrn_urn(urn)
159
+ segments = urn[MRN_PREFIX.length..].split(":")
160
+ type_token = segments.shift.to_s.downcase
161
+ letter = MRN_TYPE_LETTERS.fetch(type_token) do
162
+ raise Pubid::Errors::UrnParseError,
163
+ "Unknown IHO publication type #{type_token.inspect} " \
164
+ "in #{urn.inspect}"
165
+ end
166
+ attrs = mrn_name_attributes!(segments, urn)
167
+ # the bare dotted edition in the canonical 4th segment
168
+ if segments.first&.match?(LEGACY_EDITION_RE)
169
+ attrs[:edition] = segments.shift
170
+ end
171
+ ctx = { component: nil, edition_owner: nil }
172
+ consume_segments!(attrs, segments, ctx, urn)
173
+ build_identifier({ type: letter, **attrs }, urn)
174
+ end
175
+
176
+ # The name segment: sNNN, or s158-NNN with the S-158 member bound
177
+ # as its own component. The series letter maps back through the
178
+ # type token; the name carries only the number (and member).
179
+ def mrn_name_attributes!(segments, urn)
180
+ name = segments.shift.to_s
181
+ match = MRN_NAME_RE.match(name)
182
+ unless match
183
+ raise Pubid::Errors::UrnParseError,
184
+ "Unknown IHO publication name #{name.inspect} in #{urn.inspect}"
185
+ end
186
+
187
+ attrs = { number: match[2] }
188
+ # the member designator rides the S-158 anchor; another series
189
+ # rejects through the builder's anchor assert
190
+ attrs[:checks_for] = match[3] if match[3]
191
+ attrs
192
+ end
193
+
194
+ # The legacy positional decode (the pre-guidance emission shape and
195
+ # every legacy spelling it decodes).
196
+ def parse_legacy_urn(urn)
105
197
  segments = split_parts(strip_namespace(urn))
106
198
  type_token = read_type!(segments, urn)
107
- attrs = { number: consume_number!(segments, urn) }
199
+ attrs = consume_number!(segments, urn)
108
200
  # Positional context: the component the upcoming ed-/year- would
109
201
  # attach to, and the owner of the edition just consumed (a year
110
202
  # belongs to a component only when it follows that component's
@@ -114,14 +206,17 @@ module Pubid
114
206
  build_identifier({ type: type_token.upcase, **attrs }, urn)
115
207
  end
116
208
 
117
- private
118
-
119
209
  # The semantic validations the builder applies to the decoded shape
120
- # (the S-4 anchor, the citation letter) are URN validation at this
121
- # layer: a URN that asserts a citation it cannot carry is a
122
- # malformed URN, and the raw ArgumentError stays as the cause.
210
+ # (the S-4 anchor, the citation letter, the S-158 checks anchor)
211
+ # are URN validation at this layer: a URN that asserts a shape it
212
+ # cannot carry is a malformed URN, and the raw ArgumentError stays
213
+ # as the cause. The URN is the canonical shape, so the decoded
214
+ # identifier drops the parse-only spelling face — a legacy
215
+ # part-S-102 decode renders the canonical colon designator.
123
216
  def build_identifier(hash, urn)
124
- Builder.build(hash)
217
+ identifier = Builder.build(hash)
218
+ identifier.checks_for_face = nil
219
+ identifier
125
220
  rescue ArgumentError => e
126
221
  raise Pubid::Errors::UrnParseError,
127
222
  "#{e.message} in #{urn.inspect}"
@@ -141,20 +236,23 @@ module Pubid
141
236
  end
142
237
  end
143
238
 
144
- # The number occupies every leading bare number segment; the first
145
- # segment that is not number-shaped ends it (and the segment loop
146
- # below decides whether it is a legal marker).
239
+ # The first bare number segment is the docnumber; the next bare
240
+ # digit segment binds the S-158 member number (checks_for — the
241
+ # member as its own segment, never glued into the number), and
242
+ # anything else ends the number run (the segment loop below
243
+ # decides whether it is a legal marker).
147
244
  def consume_number!(segments, urn)
148
- number = []
149
- while segments.first&.match?(NUMBER_RE)
150
- number << segments.shift
151
- end
152
- if number.empty?
245
+ number = segments.shift.to_s
246
+ unless number.match?(NUMBER_RE)
153
247
  raise Pubid::Errors::UrnParseError,
154
248
  "Missing docnumber in #{urn.inspect}"
155
249
  end
156
250
 
157
- number.join(":")
251
+ attrs = { number: number }
252
+ if segments.first&.match?(CHECKS_SEGMENT_RE)
253
+ attrs[:checks_for] = segments.shift
254
+ end
255
+ attrs
158
256
  end
159
257
 
160
258
  def consume_segment!(attrs, segments, ctx, urn)
@@ -174,8 +272,9 @@ module Pubid
174
272
 
175
273
  # A marker segment: validate the value against the marker's own
176
274
  # pattern, store it, and claim the bare atom that follows an
177
- # appendix (its subnumber — the only bare atom allowed after a
178
- # marker). The ed- and year- markers are POSITIONAL: the edition
275
+ # appendix (its subnumber — the legacy emission's only bare atom
276
+ # after a marker; the MRN emission hyphen-joins the compound
277
+ # instead). The ed- and year- markers are POSITIONAL: the edition
179
278
  # attaches to the component it follows (the base when no component
180
279
  # precedes it), and a year belongs to a component only when it
181
280
  # follows that component's own edition — the separately-published
@@ -188,7 +287,16 @@ module Pubid
188
287
  return consume_positional!(attrs, key, value, ctx, urn) if
189
288
  POSITIONAL_MARKERS.include?(key)
190
289
 
191
- store!(attrs, key, value, urn)
290
+ # The hyphen-joined compound appendix value ("D-2", the MRN
291
+ # emission) splits into the appendix and its subnumber; the
292
+ # legacy emission instead carries the subnumber as the bare
293
+ # atom consumed below.
294
+ if key == :appendix && (compound = /\A([A-Z])-(\d+)\z/.match(value))
295
+ store!(attrs, :appendix, compound[1], urn)
296
+ store!(attrs, :appendix_subnumber, compound[2], urn)
297
+ else
298
+ store!(attrs, key, value, urn)
299
+ end
192
300
  ctx[:component] = key
193
301
  ctx[:edition_owner] = nil
194
302
  consume_subnumber!(attrs, key, segments, ctx, urn)
data/lib/pubid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pubid
4
- VERSION = "2.0.51"
4
+ VERSION = "2.0.52"
5
5
  end