Repository navigation
Fix section numbers being paired with the wrong section body - #45
Merged
Merged
Conversation
parseUslmToIr reads each section's number from the non-ordered parse and its heading/content/notes from the order-preserving parse, pairing the two by list index. The non-ordered walk visits a container's hierarchy children (subchapter, part, ...) before its direct <section> children, while the ordered walk follows document order, so any chapter that mixes the two shifted every following section onto its neighbour's number. Stamp each <section> start tag with its document position before parsing and pair the two views by that marker instead of by index. On release point 119-73 this took heading/number mismatches from 26-45% of sections (titles 7, 12, 19, 25, 42, 50) to zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the generated
us-codecorpus, many sections carry the wrong number. The statute text is real, but the## § Nheading andsection-Nanchor belong to a neighbouring section. Examples atannual/2025:Cause
parseUslmToIr(src/transforms/uslm-to-ir.ts) parses the XML twice:num, identifier, and metadata.The two section lists were paired by index. However,
collectSectionNodesRecursivevisits a node'ssubtitle/part/chapter/subchapterchildren before its direct<section>children, because the non-ordered tree groups children by tag.collectOrderedSectionNodesRecursivefollows document order. So in any chapter that has sections before (or between) its subchapters or parts, every following section is shifted by one or more positions.Fix
Before parsing, each
<sectionstart tag is stamped with its document position (data-us-code-tools-section-seq). The two views are then paired by that marker instead of by list index. Output is sorted downstream, so iteration order is unchanged. A test also asserts that the marker does not leak into the IR.Verification
I compared each parsed
(identifier, heading)with the<num>/<heading>pair taken straight from the raw XML at OLRC release point 119-73:* A handful of residual differences are checker artifacts: bracketed xref text in headings, and a form inside a note. They are not pairing errors.
Spot checks now match official headings. For example, 42 § 12132 is "Discrimination", 50 § 3003 is "Definitions", 12 § 5491 is "Establishment of the Bureau of Consumer Financial Protection", and 12 § 1701q is "Supportive housing for the elderly".
tests/unit/transforms/section-pairing.test.ts. It fails onmainand passes with this change.mainin my environment becausezipisn't installed; this change adds no new failures.Follow-up
The
us-codecorpus needs to be regenerated (re-transform and backfill) to pick up the fix. Every vintage produced so far is affected.🤖 Generated with Claude Code