pubid 2.0.59 → 2.0.60

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +6 -0
  3. data/lib/pubid/bsi/CLAUDE.md +2 -0
  4. data/lib/pubid/bsi/identifiers/consolidated_identifier.rb +3 -0
  5. data/lib/pubid/bsi/pubid_urn_schema.rb +3 -0
  6. data/lib/pubid/bsi/urn.adoc +1 -1
  7. data/lib/pubid/bsi_pfs/identifiers/consolidated_identifier.rb +4 -0
  8. data/lib/pubid/bsi_pfs/pubid_urn_schema.rb +3 -0
  9. data/lib/pubid/bsi_pfs/urn.adoc +4 -1
  10. data/lib/pubid/builder/base.rb +5 -0
  11. data/lib/pubid/cen_cenelec/CLAUDE.md +2 -0
  12. data/lib/pubid/cen_cenelec/identifiers/consolidated_identifier.rb +4 -0
  13. data/lib/pubid/cen_cenelec/pubid_urn_schema.rb +3 -0
  14. data/lib/pubid/cen_cenelec/urn.adoc +1 -1
  15. data/lib/pubid/cen_pfs/identifiers/consolidated_identifier.rb +4 -0
  16. data/lib/pubid/cen_pfs/pubid_urn_schema.rb +3 -0
  17. data/lib/pubid/cen_pfs/urn.adoc +4 -1
  18. data/lib/pubid/components/relation.rb +290 -0
  19. data/lib/pubid/components.rb +1 -0
  20. data/lib/pubid/identifier.rb +66 -0
  21. data/lib/pubid/iec/CLAUDE.md +2 -0
  22. data/lib/pubid/iec/identifier.rb +3 -0
  23. data/lib/pubid/iec/identifiers/consolidated_identifier.rb +4 -0
  24. data/lib/pubid/iec/pubid_urn_schema.rb +3 -0
  25. data/lib/pubid/iec/urn.adoc +3 -1
  26. data/lib/pubid/ieee/CLAUDE.md +2 -0
  27. data/lib/pubid/ieee/builder.rb +45 -4
  28. data/lib/pubid/ieee/identifiers/adopted_standard.rb +9 -0
  29. data/lib/pubid/ieee/identifiers/base.rb +6 -0
  30. data/lib/pubid/ieee/identifiers/dual_published.rb +9 -0
  31. data/lib/pubid/ieee/identifiers/joint_development.rb +12 -0
  32. data/lib/pubid/ieee/pubid_urn_schema.rb +4 -0
  33. data/lib/pubid/ieee/urn.adoc +6 -1
  34. data/lib/pubid/iso/CLAUDE.md +2 -0
  35. data/lib/pubid/iso/identifier.rb +3 -0
  36. data/lib/pubid/iso/identifiers/amendment.rb +12 -0
  37. data/lib/pubid/iso/pubid_urn_schema.rb +2 -0
  38. data/lib/pubid/iso/urn.adoc +6 -2
  39. data/lib/pubid/pubid_urn/decoder.rb +46 -0
  40. data/lib/pubid/pubid_urn/encoder.rb +43 -0
  41. data/lib/pubid/pubid_urn/schema.rb +4 -2
  42. data/lib/pubid/version.rb +1 -1
  43. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff0084208de0c291dbe2128c9384e79e7f300b7d81b3ca4e049bdeeb0ec24810
4
- data.tar.gz: 7fd95805caa1349d7f63dd99fb1f11b8483e2751a50cdd7a5996238dcdb46d85
3
+ metadata.gz: 760fa369f873606ebd1bc90a474acce5d8201355da885f21ab41c6ab3582a530
4
+ data.tar.gz: 6b9dc3ee5597810f69d666befaa4e66b545333da43c53e61b89f435ea2cfed85
5
5
  SHA512:
6
- metadata.gz: b22dc804d98727e1a08e9febb941c62621c4827b0899866d7a3b58db5748017993142fa18fcd013576901176eccbc18fd8679810700081effb406f9afb4a387e
7
- data.tar.gz: 50e858189382427a903a7ca78ca9ed37ea75b21274dc3c97c305e1eb61e6c4a91a9a4e68768c8cdf664f74397f4f6b48a0e5ddd885ca9a3ac03bb31138d64235
6
+ metadata.gz: 6f70d4a65518a9574f64235737d30738f6294f9d94f5a0374c0d2327d0a5e9b9d40d73668e9a00250f3f8fb800214acec191c82fc30cb43ed215d83dd5749a23
7
+ data.tar.gz: 7da726f195f612861344161cd8f10e631f18be117d3ae9403fd84aa9172a2cc34e923b33522d853bf4a0f7fb2649ac8e85dff2061a9c99f9be38ae5aa92b12d8
data/README.adoc CHANGED
@@ -102,6 +102,12 @@ harmonized codes.
102
102
 
103
103
  |link:docs/URN-GENERATION-GUIDE.adoc[URN Generation Guide]
104
104
  |`#to_urn` and `#to_pubid_urn`, RFC 5141-bis.
105
+
106
+ |link:docs/sdo/PROPOSAL.md[SDO adoption: your identifiers, implemented]
107
+ |The offer to a standards body — the declarative grammar, the
108
+ multi-engine stack, the attested corpus, the co-maintenance mechanics
109
+ (pubid#807). The ranked targets are link:docs/sdo/TARGETS.md[docs/sdo/TARGETS.md];
110
+ the outreach runbook is link:docs/sdo/RELATIONSHIP-PLAN.md[docs/sdo/RELATIONSHIP-PLAN.md].
105
111
  |===
106
112
 
107
113
  === Flavor index
@@ -108,3 +108,5 @@ and `typed_stage` serialize every registry field, so each field is its own
108
108
  atom (`typeabbr-`, `stagehs-`, `tsabbr-` …; `typed_stage.abbr` is a list)
109
109
  — the NIST ruling; reducing them would change `to_hash` and need a
110
110
  re-crawl.
111
+
112
+ - **The consolidated bundle states `consolidates` (issue #806)**: `ConsolidatedIdentifier` includes `Components::Relation::ConsolidatedEdge` — one edge toward `identifiers.first` on the additive `relations` wire key; the URN schema carries the `edges-` atom.
@@ -7,6 +7,9 @@ module Pubid
7
7
  # Example: "BS 4592-0:2006+A1:2012" = [BS 4592-0:2006, Amendment 1:2012]
8
8
  class ConsolidatedIdentifier < SingleIdentifier
9
9
  include RootIdentity
10
+ # The document-graph edge (issue #806): the bundle consolidates its
11
+ # first member.
12
+ include ::Pubid::Components::Relation::ConsolidatedEdge
10
13
 
11
14
  attribute :identifiers, ::Pubid::Identifier, polymorphic: true,
12
15
  collection: true
@@ -74,6 +74,9 @@ module Pubid
74
74
  atom "bundle_type", "btype"
75
75
  atom "identifiers", "ids", kind: :ids
76
76
  atom "na_supplements", "nasup", kind: :ids
77
+ # The document graph (issue #806): the consolidated edge toward the
78
+ # first member.
79
+ atom "relations", "edges", kind: :edges
77
80
 
78
81
  type "pubid:bsi:addendum-document", "ad"
79
82
  type "pubid:bsi:adopted-european-norm", "aen", core: []
@@ -54,7 +54,7 @@ Corpus: 1499 of 1501 pass ids parse.
54
54
  | `pubid:bsi:value-added-publication` | `vap` | number | 6 | `PP 7722:2006 BOOK`
55
55
  |===
56
56
 
57
- Atoms, canonical order: `pubbody-` (`publisher.body`), `typeabbr-` (`type.abbr`), `typename-` (`type.name`), `typetypecode-` (`type.type_code`), `part-` (`part`), `year-` (`year`), `month-` (`month`, int), `ed-` (`edition`), `stageabbr-` (`stage.abbr`), `stageharmonizedstages-` (`stage.harmonized_stages`), `stagename-` (`stage.name`), `stagestagecode-` (`stage.stage_code`), `addendumnumber-` (`addendum_number`), `addendumyear-` (`addendum_year`, int), `amdsuffixform-` (`amd_suffix_form`, bool), `bundletype-` (`bundle_type`), `commonyearyear-` (`common_year.year`), `explicitpublisher-` (`explicit_publisher`, bool), `format-` (`format`), `isplural-` (`is_plural`, bool), `issuenumber-` (`issue_number`), `iteration-` (`iteration`), `methodand-` (`method_and`), `methodcode-` (`method_code`), `methodto-` (`method_to`), `prefix-` (`prefix`), `secondnumber-` (`second_number.value`), `sectionid-` (`section_id`), `separators-` (`separators`, list), `speccode-` (`spec_code.value`), `supplementnumber-` (`supplement_number`), `supplementyear-` (`supplement_year`, int), `testid-` (`test_id`), `testseries-` (`test_series`), `topic-` (`topic`), `translationlang-` (`translation_lang`), `typedstageabbr-` (`typed_stage.abbr`), `typedstage-` (`typed_stage.code`), `typedstageharmonizedstages-` (`typed_stage.harmonized_stages`), `typedstagename-` (`typed_stage.name`), `typedstagestagecode-` (`typed_stage.stage_code`), `typedstagetypecode-` (`typed_stage.type_code`).
57
+ Atoms, canonical order: `pubbody-` (`publisher.body`), `typeabbr-` (`type.abbr`), `typename-` (`type.name`), `typetypecode-` (`type.type_code`), `part-` (`part`), `year-` (`year`), `month-` (`month`, int), `ed-` (`edition`), `stageabbr-` (`stage.abbr`), `stageharmonizedstages-` (`stage.harmonized_stages`), `stagename-` (`stage.name`), `stagestagecode-` (`stage.stage_code`), `addendumnumber-` (`addendum_number`), `addendumyear-` (`addendum_year`, int), `amdsuffixform-` (`amd_suffix_form`, bool), `bundletype-` (`bundle_type`), `commonyearyear-` (`common_year.year`), `explicitpublisher-` (`explicit_publisher`, bool), `format-` (`format`), `isplural-` (`is_plural`, bool), `issuenumber-` (`issue_number`), `iteration-` (`iteration`), `methodand-` (`method_and`), `methodcode-` (`method_code`), `methodto-` (`method_to`), `prefix-` (`prefix`), `secondnumber-` (`second_number.value`), `sectionid-` (`section_id`), `separators-` (`separators`, list), `speccode-` (`spec_code.value`), `supplementnumber-` (`supplement_number`), `supplementyear-` (`supplement_year`, int), `testid-` (`test_id`), `testseries-` (`test_series`), `topic-` (`topic`), `translationlang-` (`translation_lang`), `typedstageabbr-` (`typed_stage.abbr`), `typedstage-` (`typed_stage.code`), `typedstageharmonizedstages-` (`typed_stage.harmonized_stages`), `typedstagename-` (`typed_stage.name`), `typedstagestagecode-` (`typed_stage.stage_code`), `typedstagetypecode-` (`typed_stage.type_code`), `ids-` (`identifiers`), `nasup-` (`na_supplements`), `edges-` (`relations`, issue #806 — a consolidated bundle states `edges-consolidates-((<first member>))`).
58
58
 
59
59
  Nested identifiers: `ids-(…)` (`identifiers`, ids), `nasupplements-(…)` (`na_supplements`, ids).
60
60
 
@@ -8,6 +8,10 @@ module Pubid
8
8
  attribute :identifiers, ::Pubid::BsiPfs::Identifier,
9
9
  polymorphic: true, collection: true
10
10
 
11
+ # The document-graph edge (issue #806): the bundle consolidates its
12
+ # first member.
13
+ include ::Pubid::Components::Relation::ConsolidatedEdge
14
+
11
15
  # The origin document. Members live in `identifiers`, so
12
16
  # walk the first member to its root.
13
17
  def root
@@ -24,6 +24,9 @@
24
24
  atom "typed_stage.type_code", "tstypecode"
25
25
  atom "typed_stage.harmonized_stages", "tshs", kind: :list
26
26
  atom "identifiers", "ids", kind: :ids
27
+ # The document graph (issue #806): the consolidated edge toward the
28
+ # first member.
29
+ atom "relations", "edges", kind: :edges
27
30
  type "pubid:bsi:adopted-european-norm", "aen", core: []
28
31
  type "pubid:bsi:adopted-international-standard", "ais", core: []
29
32
  type "pubid:bsi:amendment", "amd", core: ["number"]
@@ -11,7 +11,10 @@ The PFS-compiled module-composition flavor of bsi (pubid/pubid#706 §4 —
11
11
  the first module-composition proof flavor, `definitions/bsi.pfs` in
12
12
  pubid-grammar). The composed definition declares the scheme-canonical
13
13
  tags with a narrowed atom table (`pub-`, `part-`, `year-`, the adopted
14
- node and the consolidated `ids`), registered under the `bsi_pfs` flavor
14
+ node and the consolidated `ids`, followed by `edges-` (`relations`,
15
+ issue #806 — a consolidated bundle states
16
+ `edges-consolidates-((<first member>))`)), registered under the
17
+ `bsi_pfs` flavor
15
18
  key. to_pubid_urn emits and round-trips on every absorbed face: the
16
19
  plain BS face, the composed consolidated bundles and the PAS
17
20
  designation, and the adoption wrappers — the codec composes nested
@@ -78,6 +78,11 @@ module Pubid
78
78
  identifier.public_send(setter, realized) if attrs.key?(key.to_sym)
79
79
  end
80
80
  end
81
+ # The construction tail (issue #806): the loop above assigns through
82
+ # setters — the parse path for every flavor building on this shared
83
+ # loop — so the relation faces (ISO's nested `base`, the parsed
84
+ # relationships) are on the identifier only now.
85
+ identifier.derive_relations!
81
86
  end
82
87
 
83
88
  def handle_key(_identifier, _key, _value)
@@ -85,3 +85,5 @@ them; `dateyear-`/`datemonth-` after `month-`), so a GOST-nested URN
85
85
  encodes identically. The nested `type`/`typed_stage` of an EN whose stage
86
86
  is not in the registry stays unplaced — no parse makes that shape today,
87
87
  and it keeps raising "does not place" instead of a silent drop.
88
+
89
+ - **The consolidated bundle states `consolidates` (issue #806)**: `ConsolidatedIdentifier` includes `Components::Relation::ConsolidatedEdge` — one `amends`-style edge toward `identifiers.first` on the additive `relations` wire key (CEN has no `key_value` block, so the key serializes by default; the URN schema carries the `edges-` atom). Equality skips the key, so stored rows round-trip byte-identically. The nested CEN node's edge also reaches GOST/BSI adoptions that nest a consolidated EN.
@@ -17,6 +17,10 @@ module Pubid
17
17
  attribute :identifiers, Pubid::CenCenelec::Identifier,
18
18
  polymorphic: true, collection: true
19
19
 
20
+ # The document-graph edge (issue #806): the bundle consolidates its
21
+ # first member.
22
+ include ::Pubid::Components::Relation::ConsolidatedEdge
23
+
20
24
  # The origin document. Members live in `identifiers` (not `base`), so
21
25
  # walk the first member to its root.
22
26
  def root
@@ -30,6 +30,9 @@ module Pubid
30
30
  atom "stage", "stage"
31
31
  atom "adopted", "adopted", kind: :id
32
32
  atom "identifiers", "ids", kind: :ids
33
+ # The document graph (issue #806): the consolidated edge toward the
34
+ # first member.
35
+ atom "relations", "edges", kind: :edges
33
36
 
34
37
  type "pubid:cencenelec:adopted-european-norm", "aen", core: []
35
38
  type "pubid:cencenelec:amendment", "amd"
@@ -37,7 +37,7 @@ Corpus: 192 of 192 pass ids parse.
37
37
  | `pubid:cencenelec:technical-specification` | `ts` | number | 4 | `CEN/CLC/TS 17880:2022`
38
38
  |===
39
39
 
40
- Atoms, canonical order: `pub-` (`publisher`), `co-` (`copublishers`, list), `part-` (`part`), `year-` (`year`), `month-` (`month`), `v-` (`version`), `stage-` (`stage`).
40
+ Atoms, canonical order: `pub-` (`publisher`), `co-` (`copublishers`, list), `part-` (`part`), `year-` (`year`), `month-` (`month`), `v-` (`version`), `stage-` (`stage`), `adopted-` (kind `:id`), `ids-` (`identifiers`), `edges-` (`relations`, issue #806 — a consolidated bundle states `edges-consolidates-((<first member>))`).
41
41
 
42
42
  Nested identifiers: `adopted-(…)` (`adopted`, id), `ids-(…)` (`identifiers`, ids).
43
43
 
@@ -7,6 +7,10 @@ module Pubid
7
7
  attribute :identifiers, ::Pubid::CenPfs::Identifier,
8
8
  polymorphic: true, collection: true
9
9
 
10
+ # The document-graph edge (issue #806): the bundle consolidates its
11
+ # first member.
12
+ include ::Pubid::Components::Relation::ConsolidatedEdge
13
+
10
14
  # The origin document. Members live in `identifiers`, so
11
15
  # walk the first member to its root.
12
16
  def root
@@ -14,6 +14,9 @@
14
14
  atom "stage", "stage"
15
15
  atom "adopted", "adopted", kind: :id
16
16
  atom "identifiers", "ids", kind: :ids
17
+ # The document graph (issue #806): the consolidated edge toward the
18
+ # first member.
19
+ atom "relations", "edges", kind: :edges
17
20
  type "pubid:cencenelec:adopted-european-norm", "aen", core: []
18
21
  type "pubid:cencenelec:amendment", "amd", core: []
19
22
  type "pubid:cencenelec:cen-report", "cr", core: []
@@ -10,7 +10,10 @@ file is `docs/URN-SCHEMES.adoc`.
10
10
  The PFS-compiled module-composition surface of cen_cenelec
11
11
  (pubid/pubid#706 §4 — the NSB port). The composed definition models the
12
12
  published EN face and declares the scheme-canonical tag
13
- (`pubid:cencenelec:european-norm`) with the atoms of the composed model
13
+ (`pubid:cencenelec:european-norm`) with the atoms of the composed
14
+ model — `ids-` (`identifiers`) followed by `edges-` (`relations`,
15
+ issue #806 — a consolidated bundle states
16
+ `edges-consolidates-((<first member>))`)
14
17
  (`part-`, `year-`); its URN parity with the coded flavor on to_urn /
15
18
  to_mr_string is the measured boundary (the typed-stage machinery is
16
19
  blocker 2 of `definitions/cen.pfs`), while to_pubid_urn emits and
@@ -0,0 +1,290 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Pubid
6
+ module Components
7
+ # One typed edge of the document graph (issue #806).
8
+ #
9
+ # The relation faces the parsers already capture — "Supersedes X",
10
+ # "Revision of X", "Amendment to X (as amended by Y…)", the IEEE
11
+ # reaffirmation/redesignation faces, the consolidated +AMD+COR chains —
12
+ # become first-class edges on the identifier under the additive wire key
13
+ # `relations`:
14
+ #
15
+ # Pubid::Ieee.parse("IEEE Std 16-1955 (Supersedes C48-1931)").relations
16
+ # # => [#<Components::Relation type: "supersedes", targets: [C48-1931]>]
17
+ #
18
+ # The edge type is the canonical verb for the faces issue #806 names —
19
+ # `supersedes`, `amends`, `consolidates`, `revises` — and the attested
20
+ # type string of {Relationship} for every other face (the reaffirmation
21
+ # and redesignation faces among them). FACE_TYPES is the whole mapping;
22
+ # nothing outside these two sources is a valid type.
23
+ #
24
+ # A target-less edge is not a graph statement, so +targets+ is required;
25
+ # a face the parser captured without its related identifiers yields no
26
+ # edge (Derivation below, and this is what keeps an old index row that
27
+ # stores only `relationship_type` re-serializing byte-identically).
28
+ #
29
+ # == Derivation
30
+ #
31
+ # Edges are derived once, at construction, from the relation-bearing
32
+ # attributes the identifier already stores (Identifier.derive_relations);
33
+ # the wire carries them because `relations` is a declared attribute, so
34
+ # `from_hash(to_hash)` restores them verbatim. Equality skips `relations`
35
+ # (`equality_ignored`): a parsed face and a stored row that keeps only
36
+ # the face's type must stay one document to a search — the same rule as
37
+ # every spelling-only value. Assert the edges themselves, not `==`, when
38
+ # a spec needs them to round-trip.
39
+ class Relation < Lutaml::Model::Serializable
40
+ include ::Pubid::SubsetMatch
41
+
42
+ # The canonical verbs of issue #806.
43
+ SUPERSEDES = "supersedes"
44
+ AMENDS = "amends"
45
+ CONSOLIDATES = "consolidates"
46
+ REVISES = "revises"
47
+
48
+ # Attested face type => edge type. Only these three faces rename:
49
+ # "Supersedes X" already speaks the verb; "Revision of X" and
50
+ # "Amendment to X" map to `revises` and `amends`. Every other face
51
+ # (reaffirmation_of, redesignation_of, corrigendum_to, the draft
52
+ # variants …) keeps its attested {Relationship} type verbatim.
53
+ FACE_TYPES = {
54
+ ::Pubid::Components::Relationship::SUPERSEDES => SUPERSEDES,
55
+ ::Pubid::Components::Relationship::REVISION_OF => REVISES,
56
+ ::Pubid::Components::Relationship::AMENDMENT_TO => AMENDS,
57
+ }.freeze
58
+
59
+ # The edge vocabulary: the four canonical verbs plus every attested
60
+ # {Relationship} type a face can name.
61
+ VALID_TYPES =
62
+ ([CONSOLIDATES] + FACE_TYPES.values +
63
+ ::Pubid::Components::Relationship::VALID_TYPES).uniq.freeze
64
+
65
+ TYPE_NAME = /\A[a-z][a-z0-9_]*\z/
66
+
67
+ # `initialize_empty` keeps the two construction paths in agreement
68
+ # (parse derives `[]`, a wire without the key restores `[]`); lutaml
69
+ # still omits an empty collection from the serialization.
70
+ # `polymorphic` routes each element through the root dispatcher, the
71
+ # shape every pubid collection of identifiers uses (a target carries
72
+ # its own `_type`).
73
+ attribute :type, :string
74
+ attribute :targets, ::Pubid::Identifier,
75
+ collection: true, initialize_empty: true, polymorphic: true
76
+ attribute :intermediate_amendments, ::Pubid::Identifier,
77
+ collection: true, initialize_empty: true, polymorphic: true
78
+ attribute :approved_amendments_flag, :boolean
79
+
80
+ def initialize(**args)
81
+ super
82
+ validate!
83
+ end
84
+
85
+ # The face this edge derives from, as the {Relationship} type it was
86
+ # parsed from. The inverse of FACE_TYPES; the canonical verbs that no
87
+ # attested face names (`consolidates`) have no inverse.
88
+ def self.face_type(type)
89
+ FACE_TYPES.key(type) || type
90
+ end
91
+
92
+ # The edges one identifier's relation-bearing attributes state.
93
+ #
94
+ # The generic sources are the attributes every flavor shares through
95
+ # the IEEE machinery: the parsed `relationships` faces (whose targets
96
+ # ride the runtime `related_identifiers`), and the direct `supersedes`
97
+ # / `revision_of` attributes an index row written before this change
98
+ # carries. A wrapper flavor overrides Identifier.derive_relations for
99
+ # its own shape: the consolidated bundles (iec, bsi, cen_cenelec and
100
+ # their PFS aliases) state `consolidates` toward the first member, and
101
+ # the ISO amendment states `amends` toward its base.
102
+ #
103
+ # @param attrs [Hash] the constructor attributes, before assignment
104
+ # @return [Array<Components::Relation>] may be empty; never nil
105
+ def self.derive(attrs)
106
+ faces = Array(attrs[:relationships] || attrs["relationships"])
107
+ edges = faces.map { |face| from_face(face) }
108
+ edges.concat(direct_edges(attrs))
109
+ edges.uniq
110
+ end
111
+
112
+ # The edge one parsed face states, or nil when the face carries no
113
+ # target (an old row stores only `relationship_type`) or no type.
114
+ def self.from_face(face)
115
+ type = edge_type_of(face)
116
+ targets = face_targets(face, :related_identifiers)
117
+ return nil if type.nil? || targets.empty?
118
+
119
+ new(
120
+ type: type,
121
+ targets: targets,
122
+ intermediate_amendments:
123
+ face_targets(face, :intermediate_amendments),
124
+ approved_amendments_flag: approved_flag_of(face),
125
+ )
126
+ end
127
+
128
+ # The face's edge type: nil for a face that states no type.
129
+ def self.edge_type_of(face)
130
+ face_type = face_value(face, :relationship_type)
131
+ FACE_TYPES.fetch(face_type, face_type) if face_type.is_a?(String)
132
+ end
133
+
134
+ # The flag is carried only when the face states it, so `nil` — never
135
+ # `false` — is what both construction paths store (the wire omits it
136
+ # either way; the two paths must agree on the value too).
137
+ def self.approved_flag_of(face)
138
+ true if face_value(face, :approved_amendments_flag)
139
+ end
140
+
141
+ # The face's identifiers that can sit on the wire. Two kinds of
142
+ # target never do, and both are prose the IEEE parser met inside a
143
+ # face rather than a document:
144
+ #
145
+ # * a *degraded* target — the stand-in `parse_identifier_list` builds
146
+ # for related-id text that is not an identifier ("incorporating
147
+ # IEEE Std Qcd-2015"); its hash is `_type` plus the prose in
148
+ # `parenthetical_content` and nothing else;
149
+ # * an *uncastable* target — one that does not survive the exact
150
+ # wire path an edge uses, lutaml's collection cast. A comma-list
151
+ # face parses its items through the whole IEEE grammar and an item
152
+ # can come out as a shape the cast resolves onto another class
153
+ # (a mis-split dual designation among them) — the edge would not
154
+ # round-trip and the pubid URN would refuse itself. The edge states
155
+ # only documents the graph can carry; the face itself keeps
156
+ # everything on `relationships`, exactly as before this change.
157
+ def self.face_targets(face, name)
158
+ identifier_list(face_value(face, name))
159
+ .reject { |target| degraded_target?(target) || !castable?(target) }
160
+ end
161
+
162
+ def self.degraded_target?(target)
163
+ hash = target.to_hash
164
+ hash.size == 2 && hash.key?("parenthetical_content")
165
+ end
166
+
167
+ # The probe edge serializes and deserializes through lutaml exactly
168
+ # as a real edge would; the target is castable when it comes back
169
+ # as itself.
170
+ def self.castable?(target)
171
+ probe = new(type: SUPERSEDES, targets: [target])
172
+ from_hash(probe.to_hash).targets.first == target
173
+ rescue ::StandardError
174
+ false
175
+ end
176
+
177
+ # The edges the direct relation attributes state.
178
+ def self.direct_edges(attrs)
179
+ edges = []
180
+ identifier_list(attrs[:supersedes] || attrs["supersedes"])
181
+ .then { |targets| edges << named_edge(SUPERSEDES, targets) }
182
+ identifier_list(attrs[:revision_of] || attrs["revision_of"])
183
+ .then { |targets| edges << named_edge(REVISES, targets) }
184
+ edges.compact
185
+ end
186
+
187
+ # @return [Relation, nil] nil when +targets+ is empty
188
+ def self.named_edge(type, targets)
189
+ new(type: type, targets: targets) unless targets.empty?
190
+ end
191
+
192
+ # @return [Array<Pubid::Identifier>] the Identifier objects of +value+;
193
+ # a String target is parsed, a Hash is routed through from_hash, and
194
+ # anything else is dropped, because a target that is not an
195
+ # identifier cannot sit on the wire
196
+ def self.identifier_list(value)
197
+ Array(value).filter_map do |item|
198
+ case item
199
+ when ::Pubid::Identifier then item
200
+ when ::Hash then ::Pubid::Identifier.from_hash(item)
201
+ when String, ::Array then derive_targets(item)
202
+ end
203
+ end
204
+ end
205
+ private_class_method :identifier_list
206
+
207
+ # Parse a target the way the IEEE builder does (`Identifier.parse` on
208
+ # the extracted text); unparseable text yields no target. An Array is
209
+ # a list of such texts.
210
+ def self.derive_targets(value)
211
+ targets = value.is_a?(::Array) ? value : [value]
212
+ targets.filter_map do |text|
213
+ text = text.to_s.strip
214
+ next if text.empty?
215
+
216
+ ::Pubid::Identifier.parse(text)
217
+ rescue Pubid::Errors::Error, ::Parslet::ParseFailed
218
+ nil
219
+ end
220
+ end
221
+ private_class_method :derive_targets
222
+
223
+ # Read one face field whether the face arrived as a Relationship
224
+ # object (the parse path) or a Hash (a hand-built constructor call).
225
+ def self.face_value(face, name)
226
+ return face.public_send(name) if face.respond_to?(name)
227
+
228
+ face[name.to_s] || face[name.to_sym] if face.is_a?(::Hash)
229
+ end
230
+ private_class_method :face_value
231
+
232
+ def to_s
233
+ rendered = "#{type} #{targets.join(', ')}"
234
+ rendered += " as amended by #{intermediate_amendments.join(', ')}" if
235
+ intermediate_amendments&.any?
236
+ rendered += " and its approved amendments" if approved_amendments_flag
237
+ rendered
238
+ end
239
+
240
+ def render(context: nil)
241
+ to_s
242
+ end
243
+
244
+ # The edge every consolidated bundle states (issue #806): the chain
245
+ # `BASE+A1+A2` folds its amendments into the first member, so the
246
+ # bundle consolidates that document. Included by the consolidated
247
+ # identifiers of iec, bsi, cen_cenelec and their PFS aliases — the
248
+ # five classes that store their members in `identifiers`.
249
+ module ConsolidatedEdge
250
+ def derive_relations
251
+ member = Array(identifiers).first
252
+ return [] unless member
253
+
254
+ [Relation.new(type: Relation::CONSOLIDATES, targets: [member])]
255
+ end
256
+ end
257
+
258
+ private
259
+
260
+ # lutaml constructs a wire element empty and assigns its attributes
261
+ # afterwards, so the fully-empty state is an under-construction edge,
262
+ # not a defect — only a state with values is validated.
263
+ def validate!
264
+ return if under_construction?
265
+
266
+ validate_type!
267
+ return if Array(targets).any?
268
+
269
+ raise ArgumentError,
270
+ "a relation edge needs targets: #{type} states none"
271
+ end
272
+
273
+ # The lutaml deserialization intermediate: no value set on any
274
+ # attribute.
275
+ def under_construction?
276
+ type.nil? && Array(targets).empty? && intermediate_amendments.empty? &&
277
+ approved_amendments_flag.nil?
278
+ end
279
+
280
+ def validate_type!
281
+ return if type.is_a?(String) && TYPE_NAME.match?(type) &&
282
+ VALID_TYPES.include?(type)
283
+
284
+ raise ArgumentError,
285
+ "Invalid relation type: #{type.inspect}. " \
286
+ "Valid types: #{VALID_TYPES.join(', ')}"
287
+ end
288
+ end
289
+ end
290
+ end
@@ -10,6 +10,7 @@ module Pubid
10
10
  autoload :Language, "pubid/components/language"
11
11
  autoload :Locality, "pubid/components/locality"
12
12
  autoload :Publisher, "pubid/components/publisher"
13
+ autoload :Relation, "pubid/components/relation"
13
14
  autoload :Relationship, "pubid/components/relationship"
14
15
  autoload :Stage, "pubid/components/stage"
15
16
  autoload :Supplement, "pubid/components/supplement"
@@ -532,6 +532,19 @@ module Pubid
532
532
  attribute :stage, Components::Stage
533
533
  attribute :locality, Components::Locality
534
534
  attribute :typed_stage, Components::TypedStage
535
+ # The document graph (issue #806): the typed relation edges the
536
+ # identifier's own faces state — "Supersedes X", "Revision of X",
537
+ # "Amendment to X (as amended by …)", the consolidated +AMD+COR chains.
538
+ # Derived once at construction ({Identifier.derive_relations}), carried
539
+ # on the wire additively: an identifier without relation faces
540
+ # serializes exactly as before, the empty collection lutaml omits.
541
+ # Equality skips it (`equality_ignored`): a parsed face and a stored row
542
+ # that keeps only the face's type must stay one document to a search —
543
+ # the derivation of the one cannot survive the other's wire. Assert the
544
+ # edges themselves, not `==`, when a spec needs them to round-trip.
545
+ attribute :relations, Components::Relation, collection: true,
546
+ initialize_empty: true
547
+ equality_ignored :relations
535
548
  # "All parts" is a class, not a flag: see {Pubid::AllParts}. These two
536
549
  # readers keep a caller that read the old attribute working.
537
550
  # rubocop:disable Naming/PredicateMethod
@@ -776,6 +789,59 @@ module Pubid
776
789
  attrs = self.class.normalize_init_attributes(attrs)
777
790
  attrs[:_type] ||= self.class.polymorphic_name
778
791
  super
792
+ derive_relations!
793
+ end
794
+
795
+ # Fill `relations` once, from the relation-bearing attributes already
796
+ # assigned on this identifier. The construction tail — the base
797
+ # `initialize`, the IEEE and NIST overrides at the end of their
798
+ # hand-assignment loop, and the shared builder loop after
799
+ # `assign_attributes` — so a parsed face and a manually built
800
+ # identifier derive alike. Edges the caller stated explicitly win:
801
+ # `new(relations: [...])` is never overwritten. `from_hash` restores
802
+ # `relations` from the wire through the same assignment path and never
803
+ # passes through here with attributes, so a stored row is never
804
+ # re-derived — an index row that predates the graph key round-trips
805
+ # byte-identically.
806
+ def derive_relations!
807
+ return if relations&.any?
808
+
809
+ edges = derive_relations
810
+ self.relations = edges unless edges.empty?
811
+ end
812
+
813
+ # The relation edges (issue #806, {Components::Relation}) this
814
+ # identifier's own relation-bearing attributes state. The generic
815
+ # derivation reads only the attributes this class declares, so every
816
+ # flavor without the IEEE machinery answers `[]`: the parsed
817
+ # `relationships` faces (whose targets ride the runtime
818
+ # `related_identifiers`), and the direct `supersedes` / `revision_of`
819
+ # attributes an index row written before this change carries. A flavor
820
+ # whose relation face lives elsewhere overrides this — the consolidated
821
+ # bundles state `consolidates` toward their first member
822
+ # ({Components::Relation::ConsolidatedEdge}), the ISO amendment states
823
+ # `amends` toward its base.
824
+ #
825
+ # @return [Array<Components::Relation>] may be empty; never nil
826
+ def derive_relations
827
+ edges = []
828
+ if self.class.attributes.key?(:relationships)
829
+ Array(relationships).each do |face|
830
+ edges << Components::Relation.from_face(face)
831
+ end
832
+ end
833
+ edges.concat(Components::Relation.direct_edges(
834
+ supersedes: attribute_when_declared(:supersedes),
835
+ revision_of: attribute_when_declared(:revision_of),
836
+ ))
837
+ edges.compact.uniq
838
+ end
839
+
840
+ # The attribute value when the class declares the attribute, else nil —
841
+ # the generic derivation runs on flavors that declare none of the
842
+ # relation attributes.
843
+ def attribute_when_declared(name)
844
+ self.class.attributes.key?(name) ? public_send(name) : nil
779
845
  end
780
846
 
781
847
  # Pure function of the class name; relaton resolves it per registry
@@ -69,3 +69,5 @@ WorkingDocument URNs per document instead of the shared type-only
69
69
  `cispr-`. All landed URNs are unchanged.
70
70
 
71
71
  - **The official-URN stage slot follows the correspondence table's CD code (issue #787 — the pubid-ts#187 parity round closed).** The TS mirror's pubid#727-era finding ("URN stage-slot gaps, stage-30.20/50.00/dcor/dish", pubid-ts PR #186 verification notes → issue pubid-ts#187) listed four official-`urn:iec:std:` stage slots where the two engines minted different URNs. The issue text (#787) inverted the direction for three of the four. Measured verdict, side by side: **`dcor`/`dish` and `50.00` were TS-side gaps, already closed mirror-side** — the mirror's `stageToken` now follows the gem ("no stage-code fallback … leaves the slot empty (#187)", `pubid-ts/src/flavors/iec/index.ts`), and the corpus ATTESTS the empty slot for the draft-supplement identities (`tests/iec/corrigendum.yaml`: `urn:iec:std:iec:60038-1::::::cor:1:` for the CDCOR row; `tests/iec/interpretation_sheet.yaml`: `…::::::ish:1:` for DISH) — the slot reads the ROOT document (`stage_or_type_slot(doc)`), so a supplement-layer stage never reaches it, and IEC's table names no DCOR row at all. **`30.20` was the one gem-side gap**: the IS/TR/TS committee-draft rows led their harmonized lists with 30.00 — a code in NO row of `data/iec/stage-codes.md` — while the table's CD row is `30.20 | CD | Draft circulated as CD | IS, TR, TS` and the mirror (before its #187 alignment) emitted exactly that. The fix is a LEAD REORDER, not a #733 row split: `harmonized_stages` on the `:cd`/`:cd_tr`/`:cd_ts` rows now lead 30.20 with the rest of the 30.xx ladder behind them, so the folded range honor form is unchanged (no reclassification in `stage_codes_ssot_spec.rb`), no `code:` moves (a split would have colliding `:cd` codes and broken `stage_from_kv`'s first-match resolution for the folded faces), no `to_hash`/pubid-URN movement, and `locate_stage_by_harmonized_code` (membership-based, the #570 rule) is unaffected. `IEC CD 60038` → `urn:iec:std:iec:60038::stage-30.20::`, and the reverse lookup `(is, 30.20)` resolves the `:cd` row so `parse_urn` round-trips exactly. **No attested row moves**: the relaton-data-iec corpus carries no `stage-*` value in any slot (S7 holds only `tr`/`ts`/`pas`/`guide`/`srd`), the testsuite ledgers' only stage-bearing rows are the work-programme `stage-00.00`/`stage-10.20` ones, and no gem fixture carries a CD-family face — the only pins that moved are the synthetic shapes in `spec/pubid/iec/urn_stage_edition_spec.rb` (CD, CD TR, and their `parse_urn` round trips), which now also pin the attested empty slot for the DCOR/DISH/FDAM faces. Mirror-side residue: `pubid-ts/src/flavors/iec/model.ts` hand-copies the leads (`TS("cd", …, "30.00")`, `cd_tr`, `cd_ts`) and needs the same three-value flip to restore byte parity. (hand-off: iec-urn-stage-slots.)
72
+
73
+ - **The consolidated bundle states `consolidates` (issue #806)**: `ConsolidatedIdentifier` includes `Components::Relation::ConsolidatedEdge`, so the chain derives one edge toward its first member on the additive `relations` wire key (derived at the shared builder tail — IEC builds through `Builder::Base#assign_attributes`). The top-class `key_value` block maps `relations`, the URN schema carries the `edges-` atom, and equality skips the key, so a stored row without it round-trips byte-identically.
@@ -189,6 +189,9 @@ module Pubid
189
189
  map "stage", with: { to: :stage_to_kv, from: :stage_from_kv }
190
190
  # A Boolean attribute whose `false` default ::Pubid::Identifier#to_hash
191
191
  # already drops, so a plain map suffices (the GB spelling).
192
+ # The document graph (issue #806): the consolidated edge toward the
193
+ # first member.
194
+ map "relations", to: :relations
192
195
  end
193
196
 
194
197
  # --- publisher: primary only when non-default; copublishers as a list ---
@@ -10,6 +10,10 @@ module Pubid
10
10
  class ConsolidatedIdentifier < Identifier
11
11
  attribute :identifiers, Identifier, polymorphic: true, collection: true
12
12
 
13
+ # The document-graph edge (issue #806): the bundle consolidates its
14
+ # first member.
15
+ include ::Pubid::Components::Relation::ConsolidatedEdge
16
+
13
17
  # Common fields are delegated to identifiers.first, so suppress the
14
18
  # inherited common maps and serialize the wrapped identifiers (base
15
19
  # document + supplements) instead. Route each nested hash back through
@@ -51,6 +51,9 @@ module Pubid
51
51
  atom "cispr_identifier", "cispr", kind: :id
52
52
  atom "languages.*.code", "lang"
53
53
  atom "identifiers", "ids", kind: :ids
54
+ # The document graph (issue #806): the consolidated edge toward the
55
+ # first member.
56
+ atom "relations", "edges", kind: :edges
54
57
 
55
58
  facet "languages.*.original_code", "langsrc"
56
59
 
@@ -48,7 +48,9 @@ Corpus: 12331 of 12331 pass ids parse.
48
48
  | `pubid:iec:working-document` | `wd` | number | 2350 | `1/2457/FDIS`
49
49
  |===
50
50
 
51
- Atoms, canonical order: `pub-` (`publisher`), `co-` (`copublishers`, list), `part-` (`part`), `subpart-` (`subpart`), `year-` (`year`), `month-` (`month`), `ed-` (`edition`), `lang-` (`languages.*.code`, list), `database-` (`database`, bool), `fragmentnumber-` (`fragment_number`), `sheetnumber-` (`sheet_number`), `sheetyear-` (`sheet_year`), `undated-` (`undated`, bool), `vap-` (`vap`, list), `tc-` (`technical_committee`), `wdlang-` (`wd_language`), `wdstage-` (`wd_stage`), `wpstage-` (`wp_stage`), `wptype-` (`wp_type`).
51
+ Atoms, canonical order: `pub-` (`publisher`), `co-` (`copublishers`, list), `part-` (`part`), `subpart-` (`subpart`), `year-` (`year`), `month-` (`month`), `ed-` (`edition`), `lang-` (`languages.*.code`, list), `database-` (`database`, bool), `fragmentnumber-` (`fragment_number`), `sheetnumber-` (`sheet_number`), `sheetyear-` (`sheet_year`), `undated-` (`undated`, bool), `vap-` (`vap`, list), `tc-` (`technical_committee`), `wdlang-` (`wd_language`), `wdstage-` (`wd_stage`), `wpstage-` (`wp_stage`), `wptype-` (`wp_type`), `edges-`
52
+ (`relations`, issue #806 — a consolidated bundle states
53
+ `edges-consolidates-((<first member>))`; the `ids-` atom precedes it).
52
54
 
53
55
  Nested identifiers: `ids-(…)` (`identifiers`, ids), `cispr-(…)` (`cispr_identifier`, id).
54
56
 
@@ -105,3 +105,5 @@ The lesson BSI paid for: a wrapper's hand-written `#number` delegation makes the
105
105
  - **A dotted draft with a relaton dash date rendered its tail twice (relaton/relaton-data-ieee#10).** `IEEE P1547/D-6.7.2-2017-05` rendered `IEEE P1547/D6.7.2-2017-05.7.2`, and relaton stored that string as the primary docidentifier, which pubid then could not parse — 20 documents missing from the index. The bound tree carries one draft element per version segment (`"-6"`, `".7.2"`) plus the date element. `Builder#build_single_identifier` writes the joined version plus `-YYYY[-MM]` onto the first element (`host`); it left `".7.2"` on the second, so the version was joined a second time. Three branches embed a date this way — the dash month, the dash year beside a base year (`IEEE Std 1547-2011/D-6.7.2-2017`), and the numeric month (`IEEE P1547/D-6.7.2, 05 2017`, which also used only the host's own `"-6"` and rendered `D6-2017-05.7.2`). All three now take `joined_draft_version(drafts)` and call `drop_joined_draft_segments`, which deletes `:draft_version` from every other element. The IEEE pass fixtures hold no such input (0 `to_s`/`to_hash` changes over 9,105 inputs). The release coupling this fix had (the canonical `IEEE P1547/D6.7.2-2017-05` re-parsed draft-less) is closed by the grammar captures below. The crawler-junk rows of the issue stay with relaton (hand-off `relaton__relaton__ieee-issue10-renderer-junk`).
106
106
 
107
107
  - **The relaton-data-ieee#10 grammar captures (pubid-grammar `f7b2842`, artifact checksum `sha256:c4fa66bd…fa11`).** Three captures, three different amounts of gem work. **(1) Dotted-triple draft** — `draft_version_composite` now holds `"6.7.2"`; no builder change. 23 IEEE corpus drafts that rendered with the draft dropped (`IEEE P1547/D6.7.2, May 2017` → `IEEE P1547`) or cut to one segment (`IEEE Unapproved P754/D1`) now keep it. Two of the 23 were pinned lossy by specs: `catalogue_alias_spec.rb`'s "fabricated D1 for a date-only Draft Std" really was a triple draft the grammar had dropped. **(2) Corrigendum month `cor_month`** — the grammar captures it in the nested `corrigendum:` hash and at top level for `corrigendum_identifier`; the builder reads it at all three corrigendum sites plus `rename_supplement_keys`, onto the `month` that `Corrigendum` already inherits (so `exclude(:year)`, the pubid URN atom `month` and the official URN's `month_day_component` needed no change). The renderer prints `-MM` after the corrigendum year, and `mr_supplement_suffix` writes `cor.1.2019-05` so two monthly corrigenda do not share a slug. Before, `IEEE Std 802.3-2018/Cor 1-2019-05` parsed and silently dropped `05`. **(3) Bare-IEEE colon year** — the grammar rule `ieee_colon_year_identifier` was unreachable: `Parser.normalize_input`'s "add missing Std" rewrite turned `IEEE 8802-1AE:2013` into `IEEE Std 8802-1AE:2013`, which the grammar rejects by design. The rewrite now skips a number followed by `:YYYY`. The rendered face is the canonical dash form, `IEEE Std 8802-1AE-2013/Amd 1-2015` (a ruling: no spelling flag, same as `IEEE Std 24748-3:2012` → `-2012`). A colon year with a corrigendum (`IEEE 8802-1AE:2013/Cor 1-2014`) still fails. Locked by `dotted_draft_dash_date_spec.rb`, `corrigendum_month_spec.rb`, `colon_year_spec.rb`.
108
+
109
+ - **The document graph (issue #806)**: the parsed relationship faces become typed edges on the additive `relations` wire key — `Components::Relation` (type + targets + the face's `intermediate_amendments`/`approved_amendments_flag`), derived once at the construction tail (`Identifier#derive_relations!`; IEEE's hand-rolled `initialize` calls it after its assignment loop). Face types: `supersedes`/`revision_of`/`amendment_to` map to the canonical verbs `supersedes`/`revises`/`amends`; every other attested type (reaffirmation_of, redesignation_of, the draft variants) rides verbatim. Two repairs the edges forced: **(1)** the "and its approved amendments" / "including all approved amendments" tail of a face used to degrade into a junk parenthetical target (`IEEE Std (its approved amendments)`) — `Builder#parse_related_identifiers` now cuts the tail into the `approved_amendments_flag` the Relationship already modeled (`to_s` and `to_hash` are unchanged: the narrative was never rendered and only `relationship_type` serialized); **(2)** the derivation filters two kinds of target that cannot sit on the wire — the degraded parenthetical stand-ins of comma-list faces, and targets whose shape lutaml's collection cast resolves onto another class — so the edge states only restorable documents and the face keeps everything on `relationships`, exactly as before. Equality skips `relations` (`equality_ignored`), so a parsed face and a stored row that keeps only the face type stay one document to a search; the URN carries the edges as the `edges-` atom (`:edges` kind — `edges-<type>-(<targets>)[-(<intermediates>)][-approved]`, bracket-nested one level deeper than the other nested atoms).
@@ -2386,11 +2386,13 @@ extract_optional(parsed, attributes, :rev_sep) unless attributes[:revision] =~ /
2386
2386
  # Main relationship
2387
2387
  if parsed_hash[:relationship_type]
2388
2388
  rel_type = extract_relationship_type(parsed_hash[:relationship_type])
2389
- related = parse_identifier_list(parsed_hash[:related_ids])
2389
+ related, tail_flag = parse_related_identifiers(
2390
+ parsed_hash[:related_ids],
2391
+ )
2390
2392
 
2391
2393
  # Handle "as amended by" clause
2392
2394
  amendments = nil
2393
- approved_flag = false
2395
+ approved_flag = tail_flag
2394
2396
 
2395
2397
  if parsed_hash[:amendments]
2396
2398
  # Check if it's the "and its approved amendments" flag
@@ -2416,11 +2418,13 @@ extract_optional(parsed, attributes, :rev_sep) unless attributes[:revision] =~ /
2416
2418
 
2417
2419
  additional.each do |rel_data|
2418
2420
  rel_type = extract_relationship_type(rel_data[:relationship_type])
2419
- related = parse_identifier_list(rel_data[:related_ids])
2421
+ related, tail_flag = parse_related_identifiers(
2422
+ rel_data[:related_ids],
2423
+ )
2420
2424
 
2421
2425
  # Handle "as amended by" clause for additional relationships
2422
2426
  amendments = nil
2423
- approved_flag = false
2427
+ approved_flag = tail_flag
2424
2428
 
2425
2429
  if rel_data[:amendments]
2426
2430
  if rel_data[:amendments].is_a?(Hash) && rel_data[:amendments][:approved_amendments]
@@ -2455,6 +2459,43 @@ extract_optional(parsed, attributes, :rev_sep) unless attributes[:revision] =~ /
2455
2459
  # Parse a list of identifier strings into identifier objects
2456
2460
  # @param list_data [Hash, Array, nil] the parsed identifier list data
2457
2461
  # @return [Array<Identifier>] array of parsed identifier objects
2462
+ # The approved-amendments tail of a relationship face — "Amendment to
2463
+ # IEEE Std 802.3-2018 and its approved amendments", "Revision of
2464
+ # IEEE Std 802.3-2002 including all approved amendments". The grammar
2465
+ # hands the clause back inside the related-ids list, where it cannot
2466
+ # parse as an identifier and used to degrade into a junk target
2467
+ # ("IEEE Std (its approved amendments)"). Cut it from the id text and
2468
+ # set the flag {Components::Relationship} already models instead.
2469
+ APPROVED_AMENDMENTS_TAIL =
2470
+ /\A\s*(?<id>.*?)\s*(?:and\s+its|including\s+all|its)\s+
2471
+ approved\s+amendments\s*\z/x.freeze
2472
+
2473
+ # @return [Array(Array<Identifier>, Boolean)] the parsed targets and
2474
+ # whether the list carried the approved-amendments tail
2475
+ def parse_related_identifiers(list_data)
2476
+ approved_flag = false
2477
+ targets = extract_identifier_strings(list_data).filter_map do |id_str|
2478
+ match = APPROVED_AMENDMENTS_TAIL.match(id_str)
2479
+ if match
2480
+ approved_flag = true
2481
+ id = match[:id]
2482
+ id = nil if id.nil? || id.strip.empty?
2483
+ else
2484
+ id = id_str
2485
+ end
2486
+ next unless id
2487
+
2488
+ begin
2489
+ Identifier.parse(id)
2490
+ rescue Pubid::Errors::ParseError
2491
+ # If parsing fails, create minimal identifier with just the
2492
+ # string. This maintains graceful degradation.
2493
+ Identifier.new(parenthetical_content: id)
2494
+ end
2495
+ end
2496
+ [targets, approved_flag]
2497
+ end
2498
+
2458
2499
  def parse_identifier_list(list_data)
2459
2500
  return [] unless list_data
2460
2501
 
@@ -75,6 +75,15 @@ module Pubid
75
75
  hash.delete("publisher") if hash.is_a?(::Hash)
76
76
  hash
77
77
  end
78
+
79
+ # Nested-safe twin of the delete above (issue #806): lutaml
80
+ # serializes an identifier inside another one's collection — a
81
+ # relations edge target — through its own transform, which
82
+ # bypasses the to_hash override. The canonicalizer's class hook is
83
+ # called for nested models too.
84
+ def self.compact_hash(_model, hash)
85
+ hash.delete("publisher") if hash.is_a?(::Hash)
86
+ end
78
87
  end
79
88
  end
80
89
  end
@@ -154,8 +154,14 @@ module Pubid
154
154
  elsif extra.include?(key) && respond_to?(setter)
155
155
  public_send(setter, value)
156
156
  end
157
+
157
158
  end
158
159
 
160
+ # The construction tail (issue #806): derive the graph edges from
161
+ # the faces this loop just assigned — the relationships carry their
162
+ # parsed targets as runtime state (`related_identifiers`), which is
163
+ # what the derivation reads.
164
+ derive_relations!
159
165
  end
160
166
 
161
167
  # Override accessors to return component objects.
@@ -43,6 +43,15 @@ module Pubid
43
43
  hash
44
44
  end
45
45
 
46
+ # The same delete, nested-safe (issue #806): lutaml serializes an
47
+ # identifier inside another one's collection — a relations edge
48
+ # target — through its own transform, which bypasses the to_hash
49
+ # override above. The canonicalizer's class hook is called for
50
+ # nested models too, so the derived key drops on every path.
51
+ def self.compact_hash(_model, hash)
52
+ hash.delete("publisher") if hash.is_a?(::Hash)
53
+ end
54
+
46
55
  # A dual-published document is one document under two designations, and
47
56
  # this wrapper carries neither number itself — so `root.number`, the key
48
57
  # relaton-index sorts and bsearches on, was "". Walk to the first
@@ -310,6 +310,18 @@ module Pubid
310
310
  end
311
311
  hash
312
312
  end
313
+
314
+ # Nested-safe twin of the deletes above (issue #806): lutaml
315
+ # serializes an identifier inside another one's collection — a
316
+ # relations edge target — through its own transform, which
317
+ # bypasses the to_hash override. The canonicalizer's class hook is
318
+ # called for nested models too.
319
+ def self.compact_hash(_model, hash)
320
+ return unless hash.is_a?(::Hash)
321
+
322
+ hash.delete("publisher")
323
+ hash.delete("copublisher")
324
+ end
313
325
  end
314
326
  end
315
327
  end
@@ -87,6 +87,10 @@ module Pubid
87
87
  atom "note", "note"
88
88
  atom "parenthetical_content", "paren"
89
89
  atom "relationships.*.relationship_type", "rel"
90
+ # The document graph (issue #806): the typed edges — supersedes,
91
+ # revises, amends and the attested reaffirmation/redesignation faces
92
+ # — each carrying its parsed targets.
93
+ atom "relations", "edges", kind: :edges
90
94
  # Identifiers an IEEE id nests.
91
95
  atom "ieee_identifier", "ieeeid", kind: :id
92
96
  atom "iec_identifier", "iecid", kind: :id
@@ -58,7 +58,12 @@ Core: `number` (the bare digits, the relaton index key: `C37.09` is `37` with
58
58
  `draftstatus`, `ts*` for a `typed_stage` that does not collapse to `stage`),
59
59
  `lang`, `loc`, the IEEE flags (`project`, `redline`, `interp`, …), the
60
60
  free-text designations (`nick`, `note`, `paren`, `rel` …), then the nested
61
- identifiers. Facets: `sep`, `seps`, `revsep`, `yearsep`, `datesep`,
61
+ identifiers, then `edges-` (`relations`, the document graph of
62
+ issue #806: one `edges-<type>-(<targets>)` segment per edge — the type
63
+ word is the canonical verb (`supersedes`, `amends`, `revises`) or the
64
+ attested face type (`reaffirmation_of`, `redesignation_of`, …) — with
65
+ the face clauses `-(<intermediate amendments>)` and `-approved`
66
+ appended in that order). Facets: `sep`, `seps`, `revsep`, `yearsep`, `datesep`,
62
67
  `format`, `langsrc`.
63
68
 
64
69
  ----
@@ -253,3 +253,5 @@
253
253
  (`identifiers/full/iso-pubid-tc-documents.txt` →
254
254
  `pass/tc_document.txt`, 7 faces) and the testsuite exports them as
255
255
  `tests/iso/tc_document.yaml` rows.
256
+
257
+ - **The amendment states its `amends` edge (issue #806)**: `Identifiers::Amendment#derive_relations` turns the `base` attribute into a `Components::Relation` edge (`amends` → base) on the additive `relations` wire key — the ISO amendment reference made first-class. Corrigenda state no edge (no attested verb). The wire key needs the `map "relations"` in the top-class `key_value` block (ISO enumerates its maps), the `edges-` atom in the URN schema, and equality skips `relations`, so stored rows and parsed faces stay one document to a search.
@@ -145,6 +145,9 @@ module Pubid
145
145
  # unique typed-stage `code` under "stage" and recompute the rest on
146
146
  # load. _type already pins the document type.
147
147
  map "stage", with: { to: :stage_to_kv, from: :stage_from_kv }
148
+ # The document graph (issue #806): the amendment edge toward its
149
+ # base. Polymorphic nested identifiers, omitted when empty.
150
+ map "relations", to: :relations
148
151
  end
149
152
 
150
153
  # Serialize typed_stage as just its unique code (e.g. "is", "dis",
@@ -126,6 +126,18 @@ module Pubid
126
126
  { key: :amd,
127
127
  web: :amendment, title: "Amendment", short: "AMD" }
128
128
  end
129
+
130
+ # The document-graph edge (issue #806): the amendment's `base` IS
131
+ # the amendment reference, stated as an `amends` edge toward the
132
+ # document it amends. The corrigendum states none — issue #806's
133
+ # canonical verbs cover the amendment faces.
134
+ def derive_relations
135
+ return [] unless base
136
+
137
+ [::Pubid::Components::Relation.new(
138
+ type: ::Pubid::Components::Relation::AMENDS, targets: [base],
139
+ )]
140
+ end
129
141
  end
130
142
  end
131
143
  end
@@ -26,6 +26,8 @@ module Pubid
26
26
  atom "supplement_version", "v"
27
27
  atom "languages.*.code", "lang"
28
28
  atom "locality.value", "loc"
29
+ # The document graph (issue #806): the amendment edge toward its base.
30
+ atom "relations", "edges", kind: :edges
29
31
 
30
32
  facet "languages.*.original_code", "langsrc"
31
33
  facet "edition.original_text", "edsrc"
@@ -43,7 +43,11 @@ path-safe, and give no collision.
43
43
  Core: `number`. Atoms, canonical order: `pub-`, `co-` (list), `part-`,
44
44
  `subpart-`, `year-`, `month-`, `day-`, `undated-` (bool), `ed-`
45
45
  (`edition.number`), `stage-`, `iter-` (`stage_iteration`), `v-`
46
- (`supplement_version`), `lang-` (`languages.*.code`, list), `loc-`;
46
+ (`supplement_version`), `lang-` (`languages.*.code`, list), `loc-`,
47
+ `edges-` (`relations`, the document graph of issue #806: one
48
+ `edges-<type>-(<targets>)` segment per edge, with the face clauses
49
+ `-(<intermediate amendments>)` and `-approved` appended in that order;
50
+ an ISO amendment states `amends` toward its base);
47
51
  `tcdoc` adds `tctype-`, `tc-`, `sctype-`, `sc-`, `wgtype-`, `wg-`; `dir`
48
52
  adds `subgroup-`; `all` adds `ids-(…)`; `bundle` adds `sups-(…)`. Facets:
49
53
  `langsrc` (`languages.*.original_code`), `edsrc` (`edition.original_text`).
@@ -53,6 +57,6 @@ ISO 9001 urn:pubid:iso:is:9001
53
57
  ISO/IEC/IEEE 8802-3:2021 urn:pubid:iso:is:8802:co-IEC,IEEE:part-3:year-2021
54
58
  ISO/DIS 9001 urn:pubid:iso:is:9001:stage-dis
55
59
  ISO 9001:2015(E) urn:pubid:iso:is:9001:year-2015:lang-en:f:0.langsrc-E
56
- ISO 9001:2015/Amd 1:2016/Cor 1:2017 urn:pubid:iso:is:9001:year-2015:amd:1:year-2016:cor:1:year-2017
60
+ ISO 9001:2015/Amd 1:2016/Cor 1:2017 urn:pubid:iso:is:9001:year-2015:amd:1:year-2016:edges-amends-((iso:is:9001:year-2015)):cor:1:year-2017
57
61
  ISO 9001 (all parts) urn:pubid:iso:all:ids-(iso:is:9001)
58
62
  ----
@@ -102,10 +102,56 @@ module Pubid
102
102
  when :int then integer(raw)
103
103
  when :id then nested(raw)
104
104
  when :ids then PubidUrn.split_top(raw, ",").map { |item| nested(item) }
105
+ when :edges then decode_edges(raw)
105
106
  else slot_value(raw, atom)
106
107
  end
107
108
  end
108
109
 
110
+ # The document graph (issue #806): the inverse of
111
+ # Encoder#edge_list — one "<type>-(<targets>)[-<clauses>]" segment
112
+ # per edge, joined by a top-level comma.
113
+ def decode_edges(raw)
114
+ PubidUrn.split_top(raw, ",").map { |item| decode_edge(item) }
115
+ end
116
+
117
+ def decode_edge(item)
118
+ parts = PubidUrn.split_top(item, "-")
119
+ type = parts.shift
120
+ unless /\A[a-z][a-z0-9_]*\z/.match?(type)
121
+ fail!("bad relation type #{type.inspect}")
122
+ end
123
+
124
+ edge = { "type" => type,
125
+ "targets" => identifier_group(parts.shift) }
126
+ intermediates = []
127
+ until parts.empty?
128
+ part = parts.shift
129
+ if part == "approved"
130
+ edge["approved_amendments_flag"] = true
131
+ elsif part.start_with?("(")
132
+ intermediates.concat(identifier_group(part))
133
+ else
134
+ fail!("bad relation clause #{part.inspect}")
135
+ end
136
+ end
137
+ edge["intermediate_amendments"] = intermediates unless
138
+ intermediates.empty?
139
+ edge
140
+ end
141
+
142
+ # One bracketed, comma-joined list of nested identifiers.
143
+ def identifier_group(raw)
144
+ nested_list(raw)
145
+ end
146
+
147
+ def nested_list(raw)
148
+ unless raw.is_a?(String) && raw.start_with?("(") && raw.end_with?(")")
149
+ fail!("nested identifier list #{raw.inspect} needs brackets")
150
+ end
151
+
152
+ PubidUrn.split_top(raw[1..-2], ",").map { |item| nested(item) }
153
+ end
154
+
109
155
  # The value of a :string, :bool or list atom, or of a facet.
110
156
  def slot_value(raw, slot)
111
157
  return scalar(raw, slot) unless slot.list?
@@ -115,10 +115,53 @@ module Pubid
115
115
  when :int then typed(value, Integer, atom, schema).to_s
116
116
  when :id then nested(typed(value, Hash, atom, schema))
117
117
  when :ids then nested_list(typed(value, Array, atom, schema))
118
+ when :edges then edge_list(typed(value, Array, atom, schema), atom,
119
+ schema)
118
120
  else slot_value(value, atom, schema)
119
121
  end
120
122
  end
121
123
 
124
+ # The document graph (issue #806): one segment per edge, joined by a
125
+ # top-level comma. An edge is "<type>-(<targets>)" — the type word
126
+ # ("supersedes"), then the nested identifier list — extended in a
127
+ # fixed order by the optional face clauses an "as amended by …" face
128
+ # carries: "-(<intermediate amendments>)", then "-approved". "-"
129
+ # separates and not ":", because a top-level ":" would end the atom
130
+ # token; everything bracketed is paren-protected from the splitters.
131
+ # The relation type words never carry a "-" (Components::Relation
132
+ # validates that), so the type reads unambiguously before the first
133
+ # bracketed group.
134
+ def edge_list(edges, atom, schema)
135
+ edges.map do |edge|
136
+ edge_value(typed(edge, Hash, atom, schema), atom, schema)
137
+ end.join(",")
138
+ end
139
+
140
+ def edge_value(edge, atom, schema)
141
+ type = edge["type"]
142
+ unless type.is_a?(String) &&
143
+ ::Pubid::Components::Relation::TYPE_NAME.match?(type)
144
+ raise Errors::InvalidInputError,
145
+ "#{schema.type} #{atom.path}: #{type.inspect} is not a " \
146
+ "relation type"
147
+ end
148
+
149
+ targets = edge["targets"]
150
+ unless targets.is_a?(Array) && targets.any?
151
+ raise Errors::InvalidInputError,
152
+ "#{schema.type} #{atom.path}: the #{type} edge states no " \
153
+ "targets"
154
+ end
155
+
156
+ parts = ["#{type}-(#{nested_list(targets)})"]
157
+ intermediates = edge["intermediate_amendments"]
158
+ if intermediates.is_a?(Array) && intermediates.any?
159
+ parts << "(#{nested_list(intermediates)})"
160
+ end
161
+ parts << "approved" if edge["approved_amendments_flag"]
162
+ parts.join("-")
163
+ end
164
+
122
165
  # The value of a :string, :bool or list atom, or of a facet.
123
166
  def slot_value(value, slot, schema)
124
167
  return scalar(value, slot, schema) unless slot.list?
@@ -8,7 +8,9 @@ module Pubid
8
8
  # +path+ is a dotted key path into the node's +to_hash+; "*" walks the
9
9
  # elements of an Array ("languages.*.code"). +kind+ is one of
10
10
  # :string, :list (of Strings), :bool, :bools (a list of booleans), :int,
11
- # :id (a nested identifier hash) or :ids (an Array of them). A path with
11
+ # :id (a nested identifier hash), :ids (an Array of them) or :edges (the
12
+ # document graph of issue #806: an Array of
13
+ # {"type" =>, "targets" => [, …]} relation edges). A path with
12
14
  # "*" is always a list: :list, or :bools when its elements are booleans.
13
15
  Atom = Struct.new(:path, :prefix, :kind) do
14
16
  def parts
@@ -86,7 +88,7 @@ module Pubid
86
88
  # has the shape PubidUrn::STRUCTURE reads as structure.
87
89
  class FlavorSchema
88
90
  NAME = /\A[a-z][a-z0-9]*\z/
89
- KINDS = %i[string list bool bools int id ids].freeze
91
+ KINDS = %i[string list bool bools int id ids edges].freeze
90
92
  FACET_KINDS = %i[string list bool bools].freeze
91
93
  CORE_KINDS = %i[string int].freeze
92
94
  # "f" opens the facet group; "type" is the type-metadata 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.59"
4
+ VERSION = "2.0.60"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.59
4
+ version: 2.0.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-28 00:00:00.000000000 Z
11
+ date: 2026-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -512,6 +512,7 @@ files:
512
512
  - lib/pubid/components/language.rb
513
513
  - lib/pubid/components/locality.rb
514
514
  - lib/pubid/components/publisher.rb
515
+ - lib/pubid/components/relation.rb
515
516
  - lib/pubid/components/relationship.rb
516
517
  - lib/pubid/components/stage.rb
517
518
  - lib/pubid/components/supplement.rb