Repository navigation
Keep character-normalization repairs to whole symbols and check them part by part - #149
Conversation
…part by part Mappings now apply in one pass, longest first, and only where no ASCII letter or digit adjoins them, so O2 is left alone in CDKN2A and +- in Ca2+-dependent. H2O2 gets its own default mapping. Validation ignores punctuation, so a mapping that changes only punctuation is kept only when the reference has the repaired text as written. The repaired quote is checked part by part, split on ... and editorial brackets as validation splits it, through a helper shared with the ellipsis strategy. Fixes #128 Fixes #129 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @caufieldjh's task in 1m 20s —— View job PR review: whole-symbol character mappings + part-by-part checks (#128, #129)
Overall: This is a good, focused fix. The single-pass, longest-first regex removes the chained-replacement bug. Moving the part-by-part check into 1. The boundary rule now skips some common chemistry forms (behaviour change, worth deciding on)
The PR body only lists Possible refinement: the boundary rule exists to protect punctuation mappings like 2.
|
The whole-symbol rule now only guards a mapping's letter or digit edges, and treats Unicode letters and digits as neighbours too. Punctuation mappings such as +/- apply anywhere again, so 5+/-2 becomes 5±2; the literal check in attempt_repair is what keeps Ca2+-dependent intact. Pin and document the formulas the rule still skips (6CO2, pCO2, N2O). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
The option leaves out every mapping that validation's normalization cannot tell apart from the original, which includes spelled-out Greek letters and ligatures as well as punctuation. Name and document it as such, and test the Greek-letter case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
attempt_repair now normalizes the searchable texts once, both ways, and passes them to _all_parts_found, instead of renormalizing a full-text reference on each of up to three checks. The regex for a set of mappings is compiled once and cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
Cover a normalization whose fallback still fails, an ellipsis repair whose parts sit in separate SVG labels (Strategy 2 through the shared helper), and a single-letter user key inside a word. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
|
Claude finished @caufieldjh's task in 1m 8s —— View job PR review (re-review after the latest commits)
Overall: The new commits deal with every point from the previous review:
The design is sound: punctuation mappings can now match anywhere, and the literal check against the reference stops them from damaging text like 1. The PR description is out of date
2. The literal pass runs on every quote, even when it can't change anything (performance, minor)
A cheap restructure: verifiable = self.apply_character_mappings(supporting_text, skip_unverifiable=True)
normalized = self.apply_character_mappings(supporting_text)
if normalized != verifiable:
literal_searchable = [normalize_whitespace(t) for t in texts]
if not self._all_parts_found(normalized, literal_searchable, literal=True):
normalized = verifiableThis only builds 3. Docs formatting nitIn 4. Small edge cases (optional)
Test coverageCoverage is good. It covers the reproduction cases for #128 and #129, both outcomes of the punctuation-only mapping (rejected and kept), Greek letters counted as unverifiable, the single pass, SVG labels in both strategies, and the fallback that still fails. One gap: no Summary: This is ready to merge from a correctness standpoint. Please update the PR description (point 1). Points 2–4 are optional polish. I couldn't run the tests, so please confirm CI is green. |
When every mapping that applied is one validation can confirm, the literal check cannot change the result, so skip it and the extra pass over the reference it needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
An empty key compiles to a pattern that matches between every character, inserting its replacement throughout the quote. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkPDe4fb4TDFQVmQJnq
|
Claude finished @caufieldjh's task in 54s —— View job PR review (after the latest commits)
Overall: The new commits deal with every point from my last review, and the PR description is now up to date:
I found no correctness bugs and no security concerns. I think this is ready to merge once CI is green. Things I checked
Nits (optional)
Test coverageGood. The new tests cover:
I see no remaining gaps worth blocking on. |
Fixes #128 and #129. Both are in Strategy 1 (character normalization) of
SupportingTextRepairer.attempt_repair.#128: mappings rewrote parts of other symbols
apply_character_mappingsnow applies every mapping in one regex pass, longest key first. Where a key starts or ends with a letter or digit, no letter or digit (Unicode included) may sit directly next to it on that side. SoCDKN2A,N2a,HEK293N2andµO2are left alone. A key that starts and ends with punctuation, such as+/-, applies anywhere, so5 +- 2,5+/-2and+/-5all become±. Because there is only one pass, one mapping's output can't be rewritten by another. The compiled regex is cached.H2O2→H₂O₂.RepairConfignow rejects an emptycharacter_mappingskey, which would otherwise match between every character.skip_unverifiableoption. Validation's normalization ignores punctuation, spells out Greek letters and folds ligatures, so it can't confirm a mapping that changes only those, such as+-→±or a customalpha→α. When such a mapping fires, Strategy 1 keeps it only if the repaired quote is in the reference as written, ignoring only case and whitespace. Otherwise it retries without those mappings. This is what keepsCa2+-dependentandNAD+-linkedintact. The check covers the whole quote, so any other differing punctuation (a curly quote, an en dash) also drops a correct±. That is deliberate: every change in an accepted repair has been checked against the reference, so HIGH confidence still means it is safe to auto-apply.#129: quotes with
...or[brackets]never repaired_all_parts_foundsplits a quote with_split_queryand checks each part against the searchable texts, so SVG figures are still checked label by label. Strategy 1 and Strategy 2 (ellipsis) both use it now, so the two can't drift apart.attempt_repairnormalizes the reference texts once and passes them in.Tests
tests/test_repair.py: the reproduction cases from both issues and their comments. That covers ion charges, gene symbols,H2O2,5+/-2, Unicode neighbours, a single pass, a single-letter user key, an empty key being rejected, a punctuation-only mapping both rejected and kept, the default+-mapping end to end, a Greek-letter mapping, a fallback that still fails,..., brackets, both together, SVG parts in separate labels and across labels, and an ellipsis repair across SVG labels. Doctests were added for the new behaviour.docs/how-to/repair-validation-errors.md.just testpasses: 2068 tests, 288 doctests,ruff checkandmypy.Change in behaviour
Formulas joined directly to a coefficient or prefix are no longer mapped:
6CO2,2H2O2,pCO2,13CO2. The rule that protectsCDKN2AandHEK293N2also skips these.N2Oisn't mapped either: it has no mapping of its own, andN2andO2are joined to other letters inside it. Tests pin these cases and the docs list them.🤖 Generated with Claude Code