Skip to content

Keep comparison, plus-minus and minus signs through normalization - #151

Merged
caufieldjh merged 5 commits into
mainfrom
ccr-65a5480d-pb91sk
Oct 28, 2026
Merged

caufieldjh merged 5 commits into
mainfrom
ccr-65a5480d-pb91sk

Conversation

@caufieldjh

@caufieldjh caufieldjh commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #125.

Problem

normalize_text replaced all punctuation with spaces, including symbols that change a claim's meaning. So p < 0.05 matched p > 0.05, decreased by -2.5 fold matched decreased by 2.5 fold, and 5 2 mM matched 5 ± 2 mM.

Changes

In normalize_text, before punctuation is stripped:

  • <, >, ≤, ≥, ⩽ and ⩾ (and <=, >=) become the words lt, gt, le and ge.
  • ± and +/- become pm, with either an ASCII hyphen or U+2212 as the minus, and also before a letter (+/-SD). A bare +- becomes pm too, except before a letter, so Ca2+-dependent is still read as a charge followed by a hyphen.
  • A - or − before a digit is read as a minus sign only in these positions: at the start of the text, after whitespace, after an opening bracket or a curly opening quote (“ ‘ «), or after =, :, ~, ≈ or an exponent's ^. The sign stays attached to the number: −80 °C → neg80 c, 10^-5 → 10 neg5. So 80 °C does not match −80 °C, and 10^5 does not match 10^-5. Everywhere else the dash is a hyphen or range dash, as before: IL-6, COVID-19, 3-5, pH 7.4-8.0, 3'-5', 10%-20%, 5°-10°, 5"-10". Straight quotes are excluded because they double as primes and inch marks.
  • Arrows (->, =>, <->, and <- when not before a digit) are removed first, so they aren't read as gt/lt.

ASCII and Unicode spellings of each symbol are equivalent. Normalized text is cached only in memory, so no on-disk cache needs invalidating.

Repair interaction: the default +- → ± and +/- → ± mappings still normalize to the same word on both sides. So the repairer still confirms them against the reference as written, and still leaves Ca2+-dependent alone (pinned by a test). One doctest in _all_parts_found changed from True to False, because normalization can now tell Ca2±dependent from Ca2+-dependent on its own.

Docs: docs/concepts/how-it-works.md (normalization list) and docs/how-to/repair-validation-errors.md (why +- → ± still needs a literal check).

Behaviour changes to note

  • A quote now fails if it drops a ±, a comparison or a sign that the reference has, or adds one it doesn't. That is the point of the change. It also catches honest transcriptions such as 5 +- 2 quoted for a reference's 5 ± 2; the repairer offers ± for those.
  • These are unchanged from main, where the sign is still lost:
    • an en dash used as a minus (–2.5)
    • a minus followed by a space (− 2.5)
    • a sign after a comma ((-1,-2))
    • a sign after a straight quote ("-2.5")
    • look-alike dashes such as fullwidth -

Tests

tests/test_meaning_symbols.py was written first; 10 cases failed before the fix. It covers:

  • every case from the issue
  • ≤/≥
  • −80 °C, 10^-5 vs 10^5, and ~-2/≈−2
  • curly-quoted negatives
  • a sign dropped from the start of a quote, and a dropped ±

It also has positive cases that must keep matching:

  • ASCII/Unicode equivalence, including +/− and +/-SD
  • hyphens in gene names and ranges, including 10%-20%, 5°-10° and 5"-10"
  • primes and arrows
  • the Ca2+- repair
  • a title comparison

Full suite: 2139 passed. Doctests, mypy and ruff are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC

normalize_text replaced all punctuation with spaces, so "p < 0.05"
matched "p > 0.05" and "-2.5 fold" matched "2.5 fold". Meaning-bearing
symbols now become words before punctuation is stripped: < > <= >= ≤ ≥
become lt gt le ge, ± and +/- become pm, and a minus sign before a
number stays on it as neg. ASCII and Unicode spellings are equivalent.
Arrows stay punctuation, and a hyphen after a word, digit or prime
(IL-6, 3-5, 3'-5') is still a hyphen, as is "+-" before a letter
(Ca2+-dependent).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC
@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

Copy link
Copy Markdown
Contributor Author

The claude-review check failed for a reason unrelated to this PR's code. In the job log, the review session exits after 311 ms with is_error: true, 1 turn, and total_cost_usd: 0, before it reads any file. So the session couldn't start; it isn't a review finding. I can't re-run it from here (403), so a maintainer will need to re-run the job, or it will run again on the next push. The test jobs are unaffected.


Generated by Claude Code

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 2m 14s —— View job


Review of PR #151: keep comparison, ± and minus signs through normalization

  • Read the diff and the normalize_text call sites (supporting-text search, title checks, repairer)
  • Traced the new regexes against edge cases
  • Run tests: I couldn't. Running uv run pytest and uv run python in this job needs approval, so the edge cases below come from reading the regexes, not from running them.
  • Post review

Overall this is a clean, well-scoped fix. Turning the symbols into whole-word tokens before punctuation is stripped is a good choice. It keeps the change inside normalize_text, and the existing whole-word matching then handles everything else. Gluing neg onto the number (neg2.5) is a good detail, because it stops 80 °C from matching −80 °C. The tests cover both sides: changes in meaning must fail, and different spellings of the same meaning must still match. The comments explain why, not just what.

I found two places where the code doesn't fully deliver the "ASCII and Unicode spellings are equivalent" claim.

1. +/− with a Unicode minus is not read as pm

supporting_text_validator.py:822

text = re.sub(r"±|\+/?-(?![^\W\d_])", " pm ", text)

\+/?- only accepts the ASCII hyphen. Text taken from PDFs often has 5 +/− 2 or 5 +− 2 with U+2212. That gets stripped to 5 2, while 5 ± 2 becomes 5 pm 2. So a correct quote of 5 ± 2 fails against a reference written 5 +/− 2, which is the same class of bug the PR fixes. Suggested fix: \+/?[-−], plus a parametrized case in test_same_meaning_in_other_spellings_matches.

Fix this →

2. The "before a letter" exception also applies to +/-, not only +-

In the same regex, the lookahead (?![^\W\d_]) covers both +- and +/-. The PR body and the docstring say only +- has this exception. As a result:

  • mean +/-SD → mean sd
  • mean ±SD → mean pm sd

So the two spellings don't match. ±SD / +/-SEM with no space is fairly common. The Ca2+-dependent case only needs the exception for bare +-, so I'd split the alternatives:

text = re.sub(r"±|\+/[-−]|\+[-−](?![^\W\d_])", " pm ", text)

A test such as ("mean ± SD", "mean +/-SD") would pin it.

Fix this →

Lower priority / worth considering

  • A minus followed by a space. [-−](?=\d) needs the digit to come right after the sign. So by − 2.5 fold (spacing from PDF extraction) becomes by 2.5 fold, and a quote of by −2.5 fold (by neg2.5 fold) fails against it. Before this PR both matched. The ASCII hyphen has to stay strict because of 3 - 5. U+2212 is almost never a hyphen, though, so −\s?(?=\d) → neg could be safe for that character alone. This is a judgement call, but it may deserve a test.
  • Token collisions. lt, gt, le, ge and pm are also real words or abbreviations: LT (lymphotoxin), PM (afternoon, particulate matter), French le. A false match would need the rest of the quote to line up as well, so the risk is small. Odd tokens (e.g. symlt, sympm) would remove it at no cost. This only matters if someone reads normalized text in debug output.
  • =< and =>. p =< 0.05 becomes p lt 0.05 rather than le, and p => 0.05 is removed as an arrow, so neither matches ≤/≥. These spellings are rare; I'm only noting them so the behaviour is a deliberate choice.
  • A side benefit worth noting: genotype notation Apoe+/- now becomes apoe pm, while Apoe-/- becomes apoe, so heterozygous and knockout quotes no longer match each other. +/+ and -/- still look the same after normalization. That could be a follow-up.
  • Formatting nits. The changed paragraph in docs/how-to/repair-validation-errors.md has one very long unwrapped line ("…such as +- → ± or a custom alpha → α. Such a mapping…"), and the updated docstring line ending "…The same normalization applies to reference content and queries" is longer than the surrounding lines. Re-wrapping both would match the rest of the file.

Performance / security

  • Each call does 6 extra re.sub passes over the text. Normalized reference content is cached in memory and these are linear-time regexes with no risk of catastrophic backtracking, so the cost is negligible.
  • No security concerns. The references come from HTML/XML that BeautifulSoup has already turned into text, so raw tags like <i> don't produce stray lt/gt tokens.

Test coverage

Good. Every case from the issue is covered, along with some useful counter-cases (3'-5', pH 7.4-8.0, arrows, the Ca2+- repair). I'd add:

  • +/− and +− with U+2212 (item 1)
  • +/-SD vs ±SD (item 2)
  • a sign inside brackets or after = ((-2.5), x=-5), which the lookbehind is meant to treat as negative numbers
  • a title-validation case, because _validate_title also calls normalize_text, so titles containing </± now behave differently

Review follow-up. The plus-minus pattern accepted only an ASCII hyphen,
so "5 +/− 2" and "5 +− 2" lost the sign while "5 ± 2" kept it. Its
before-a-letter exception, meant for bare "+-" (Ca2+-dependent), also
caught "+/-", so "mean +/-SD" and "mean ±SD" normalized differently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC

Copy link
Copy Markdown
Contributor Author

Fixed in 777810d. I confirmed both main findings by running them: 5 +/− 2 → 5 2, and mean +/-SD → mean sd.

  1. +/− / +− with U+2212: the pattern now accepts both kinds of minus.
  2. The before-a-letter exception: it now applies only to bare +- (±|\+/[-−]|\+[-−](?[^\W\d_])). So +/-SD becomes pm sd, and Ca2+-dependent is still left alone.

New tests: both U+2212 spellings, mean +/-SD and ±SEM written without a space, (−2.5), x=-5, and a title comparison. Full suite: 2131 passed. I also re-wrapped the docstring and the docs paragraph.

Not changed, with reasons:

  • − 2.5 (minus followed by a space): reading a spaced U+2212 as a sign would make 5 − 2 (a spaced subtraction) normalize differently from 5 - 2. That trades one mismatch for another, so I've left it.
  • Token collisions (lt, pm, …): a false match needs the whole rest of the quote to line up too. The plain tokens also keep the normalized text readable in debug output.
  • =< / =>: rare enough that I'd rather not guess. => is far more often an arrow.
  • Genotypes +/+ vs -/-: a good follow-up, but outside normalize_text strips <, >, ± and minus signs, so reversed comparisons and signs pass #125.

Generated by Claude Code

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 1m 1s —— View job


Review of PR #151 (after push 777810d)

  • Read the new commit and the full diff against origin/main
  • Checked that the earlier review items were addressed
  • Traced the regexes against more edge cases
  • Run tests: I couldn't. This job needs approval to run uv run pytest and uv run python, so everything below comes from reading the regexes.

Earlier findings

Both main items are fixed in supporting_text_validator.py:824:

text = re.sub(r"±|\+/[-−]|\+[-−](?![^\W\d_])", " pm ", text)
  • +/− and +− with U+2212 now become pm. Tests at tests/test_meaning_symbols.py:53-54 cover them.
  • The "before a letter" exception now applies only to bare +-. So +/-SD becomes pm sd, and Ca2+-dependent (and Ca2+−dependent) is still left alone. Tests at :55-56 cover this.
  • The suggested extra tests were added too: brackets ((−2.5)), x=-5, and a title case.

New finding: a % before a range hyphen now reads as a minus sign

supporting_text_validator.py:828

text = re.sub(r"(?<![\w.,'′’)\]])[-−](?=\d)", " neg", text)

The lookbehind lists the characters after which - counts as a hyphen. % isn't in that list, so ranges written with percent signs change meaning:

text normalized
10%-20% 10 neg20
10-20% 10 20
10%–20% (en dash) 10 20

So a quote of reduced by 10-20% now fails against a reference that says reduced by 10%-20%. Before this PR it matched, and the reference has no negative number in it. Percent ranges are common in abstracts, so this will happen in practice. ° has the same problem (5°-10°), though that spelling is rarer.

Suggested fix: add % and ° to the lookbehind, i.e. (?<![\w.,'′’)\]%°]), and add ("reduced by 10-20%", "reduced by 10%-20% overall") to test_hyphens_and_arrows_are_not_signs_or_comparisons.

Fix this →%5B-%E2%88%92%5D(%3F%3D%5Cd)%60%20treats%20the%20hyphen%20in%20%2210%25-20%25%22%20as%20a%20minus%20(%2210%20neg20%22)%2C%20so%20%2210-20%25%22%20no%20longer%20matches%20it.%20Add%20%25%20and%20%C2%B0%20to%20the%20lookbehind%20and%20add%20a%20test%20(%22reduced%20by%2010-20%25%22%2C%20%22reduced%20by%2010%25-20%25%20overall%22)%20to%20test_hyphens_and_arrows_are_not_signs_or_comparisons%20in%20tests%2Ftest_meaning_symbols.py.&repo=linkml/linkml-reference-validator)

Minor

  • Doc wording. docs/how-to/repair-validation-errors.md:122 says validation reads "+-, +/- and ± all as the same word". That isn't true for a bare +- before a letter, and that exception is exactly why Ca2+-dependent works. Adding "(except +- before a letter)" would keep the explanation accurate.
  • Scientific notation. 10^-5 becomes 10 neg5, while 1e-5 becomes 1e 5 (the hyphen after e reads as a word hyphen). Each spelling still matches itself, so this is only an inconsistency between the two. I'm noting it so the behaviour is a deliberate choice.
  • Still open from the last review, all judgement calls and none blocking: − 2.5 with a space after the minus, collisions with the lt/pm/le tokens, and =</=>.

Performance / security

No change from the last review. The extra re.sub passes are linear and can't backtrack catastrophically, and nothing here raises security concerns.

Summary

The follow-up commit fixes both earlier issues cleanly and adds the requested tests. One regression remains: a hyphen after % (and °) is read as a minus sign, so percent ranges like 10%-20% no longer match 10-20%. It's a one-character change to the lookbehind plus a test. Otherwise this looks good to merge.

Review follow-up. The minus-sign rule listed the characters after which
a dash is a hyphen, and missed % and °, so "10%-20%" normalized to
"10 neg20" and no longer matched "10-20%". It now lists where a sign
can appear instead: the start, after whitespace, an opening bracket,
"=" or ":". Every other dash is a hyphen or range, which also makes
"10^-5" and "1e-5" normalize alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC

Copy link
Copy Markdown
Contributor Author

Fixed in ff2fcd5. I confirmed it by running it: 10%-20% → 10 neg20, and 5°-10° → 5 neg10.

Instead of adding % and ° to the lookbehind, I inverted the rule. The old regex listed every character after which a dash is a hyphen, and that list will always miss some. Now a dash is a minus sign only at the start, after whitespace, after an opening bracket, or after = or :. Every other dash is a hyphen or a range. This covers %, °, units and anything else, and it also settles the scientific-notation point: 10^-5 and 1e-5 now both normalize to … 5.

  • Doc wording: fixed. It now says "+- (except before a letter)".
  • New tests: 10%-20% vs 10-20%, 5°-10° vs 5-10°, and x=-5, [-3] → x neg5 neg3.
  • Results: full suite 2133 passed; doctests, mypy and ruff are clean.

The remaining judgement calls stay as they are, for the reasons in my earlier reply.


Generated by Claude Code

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 58s —— View job


Review of PR #151 (after push ff2fcd5)

  • Read the new commit and the full source diff against origin/main
  • Checked the fix for the earlier %/° finding
  • Traced the new minus-sign regex against more edge cases
  • Run tests: I couldn't. uv run python / uv run pytest need approval in this job, so the results below come from reading the regexes, not from running them.

Earlier findings

  • 10%-20% read as a minus: fixed. The regex now lists the places where a sign can appear, rather than where it can't (supporting_text_validator.py:829):
    text = re.sub(r"(?:^|(?<=[\s(\[{=:]))[-−](?=\d)", "neg", text)
    This is a better design than the previous blocklist. Any character nobody thought of now defaults to "hyphen", which keeps the old behaviour, so it can't add a meaning change. The 10%-20% and 5°-10° tests pin it.
  • Doc wording about +- before a letter: fixed in repair-validation-errors.md.
  • Replacing with "neg" and no leading space is correct, because the matched sign always follows whitespace, an opening bracket, = or :, and later passes turn those into spaces. I also checked p<-0.05. The arrow regex skips <- before a digit, < becomes lt, and the - then follows a space, so the result is p lt neg0.05. Good.

New finding (minor): 10^-5 now matches 10^5 again

The commit message says the change "makes 10^-5 and 1e-5 normalize alike". They do both lose the sign, but that has a side effect. ^ isn't in the allow-list, so:

text at 777810d at ff2fcd5
10^-5 M 10 neg5 m 10 5 m
10^5 M 10 5 m 10 5 m

So a quote of 10^5 M passes against a reference that says 10^-5 M. That's ten orders of magnitude, and it's the same kind of error #125 is about. It isn't a regression against main, which already confused the two, but the previous commit on this branch got it right. 1e-5 vs 1e5 is still safe because 1e 5 and 1e5 are different tokens.

Suggested fix: add ^ to the allow-list ([\s(\[{=:^]), plus a negative case ("10^5 M", "a dose of 10^-5 M") in the "meaning changes must fail" test. ×10-5 is ambiguous, so leaving that as a hyphen is reasonable.

[Fix this →](https://claude.ai/code?q=In%20src%2Flinkml_reference_validator%2Fvalidation%2Fsupporting_text_validator.py%20(branch%20ccr-65a5480d-pb91sk)%2C%20the%20minus-sign%20regex%20%60(%3F%3A%5E%7C(%3F%3C%3D%5B%5Cs(%5C%5B%7B%3D%3A%5D))%5B-%E2%88%92%5D(%3F%3D%5Cd)%60%20does%20not%20treat%20a%20dash%20after%20%22%5E%22%20as%20a%20sign%2C%20so%20%2210%5E-5%20M%22%20and%20%2210%5E5%20M%22%20both%20normalize%20to%20%2210%205%20m%22.%20Add%20%5E%20to%20the%20lookbehind%20character%20class%20and%20add%20a%20failing-match%20test%20(%2210%5E5%20M%22%20quoted%20against%20%22a%20dose%20of%2010%5E-5%20M%22)%20in%20tests%2Ftest_meaning_symbols.py%3B%20update%20the%20comment%20and%20commit%20message%20claim%20about%201e-5.&repo=linkml/linkml-reference-validator)

Lower priority

  • Signs after a comma with no space. In (-1,-2) or [-3,-5], only the first number keeps its sign: neg1 2. Coordinate and interval lists are often written without spaces. Adding , to the allow-list would also catch 3,-5, though, and that's more often a range in a list. So I'd leave this as is unless a real example comes up. Both the previous blocklist and main behaved the same way, so it isn't a regression.
  • Other prefixes that drop the sign, such as a straight quote mark ("-2.5"), ~-3, ≈−2 and /-2. They're all rare, and the cost is only the pre-PR behaviour (the sign is lost), not a false mismatch. Still worth knowing about. ≈ −2 with a space keeps the sign while ≈−2 drops it, so those two spellings don't match each other.
  • The judgement calls from earlier reviews (− 2.5 with a space, token collisions, =</=>, genotypes) were all answered in the author's reply. I agree with the reasoning there.

Code quality / performance / security

  • The comment above the regex explains why, and the examples (IL-6, 3-5, 3'-5', 10%-20%, 5°-10°) match the tests.
  • The regex is linear and can't backtrack catastrophically. Its performance cost is the same as in the last review, which is negligible.
  • No security concerns.

Test coverage

The new cases (10%-20%, 5°-10°, x=-5, [-3]) cover the allow-list. The only gap I'd add is the 10^-5 vs 10^5 case above.

Summary

The latest commit fixes the percent/degree range regression, and the allow-list is a sounder design than the blocklist it replaces. The one thing I'd still change is putting ^ in the allow-list, so scientific notation such as 10^-5 keeps its sign. Otherwise this looks good to merge.

Review follow-up. Allowing a sign only after a fixed list of characters
dropped the minus in "10^-5", so "10^5 M" matched "10^-5 M" again, which
the previous commit had right. The previous commit message's claim that
"10^-5" and "1e-5" now normalize alike was the bug, not a feature.
"^", "~", "≈" and an opening quote can now precede a sign.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC

Copy link
Copy Markdown
Contributor Author

Fixed in fba59d9. I was wrong to say in the last commit that 10^-5 and 1e-5 now normalize alike. That was the bug, not a feature: 10^5 M passed against 10^-5 M.

  • A minus sign can now also follow ^, ~, ≈, " or “.
  • New must-fail cases: 10^5 M vs 10^-5 M, 2 fold vs ~-2 fold, and ≈ 2 vs ≈−2.
  • Full suite: 2136 passed. Doctests, mypy and ruff are clean.

I've left , out of the list, as you suggested. In 3,-5 the dash is more often a range, and leaving it out gives the same result as main.


Generated by Claude Code

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 55s —— View job


Review of PR #151 (after push fba59d9)

  • Read the new commit and the source diff against origin/main
  • Traced the new allow-list against edge cases
  • Run tests: I couldn't. uv run python and uv run pytest need approval in this job, so the results below come from reading the regexes, not from running them.
  • Post review

Earlier finding: 10^-5 vs 10^5

Fixed. The regex is at supporting_text_validator.py:830:

text = re.sub(r'(?:^|(?<=[\s(\[{=:~≈^"“]))[-−](?=\d)', "neg", text)
  • ^ sits after the first position in the character class, so it is a literal caret and not a negation. 10^-5 M → 10^neg5 m → 10 neg5 m, and 10^5 M → 10 5 m, so the two no longer match. The new test ("10^5 M", "a dose of 10^-5 M") covers this.
  • ~-2 → neg2 and ≈−2 → neg2 are covered by tests. This also fixes the earlier point that ≈ −2 and ≈−2 didn't match each other.
  • The commit message corrects the wrong 1e-5 claim from the previous commit. 1e-5 → 1e 5 and 1e5 → 1e5 are different tokens, so that pair is still safe.
  • The straight apostrophe ' is correctly left out of the allow-list, so 3'-5' keeps working.

Minor, none blocking

  • The opening-quote list is incomplete. " and “ are in the class, but ‘ (U+2018) and « are not. So ‘-2.5’ still loses its sign. That is only the behaviour on main, not a false mismatch, so add them only if you want the set to be complete. Leave the straight ' out because of primes.
  • " doubles as an inch or arcsecond mark. In 5"-10", the second dash follows ", so it reads as a sign: 5 neg10. Meanwhile 5-10" → 5 10. This is the same class of problem as the earlier 10%-20% case, but in scientific abstracts it is much rarer than a quoted negative number, so I think the trade-off is fine. It might be worth one line in the comment.
  • Docs. docs/concepts/how-it-works.md says "A hyphen after a word or digit (IL-6, 3-5) is still punctuation", which is still accurate. If you want readers to know about 10^-5, it's the one case where a sign follows a non-space character. Optional.
  • The judgement calls from earlier rounds (− 2.5 with a space, lt/pm token collisions, =</=>, (-1,-2), genotypes) were all answered in earlier replies. I still agree with that reasoning.

Code quality / performance / security

  • The comment above the regex now lists every allowed prefix and gives a reason (10^-5 is not 10^5), and the examples match the tests.
  • The pattern is a single lookbehind over a character class, so it's linear and can't backtrack catastrophically. There is no performance change from earlier rounds and no security concerns.

Test coverage

The three new negative cases (^, ~, ≈) cover each new entry in the allow-list. Nothing in the tests checks the opening-quote entries. You could add a case such as ("2.5", 'a value of "-2.5"') to the "meaning changes must fail" test, so " and “ don't get dropped from the class later without anyone noticing.

Summary

This commit fixes the 10^-5 regression and extends the allow-list sensibly. The open items are minor (single opening quotes, the inch-mark edge case, a test for the quote entries). From reading the code, this looks good to merge once CI passes.

Review follow-up. A straight " also marks inches and arcseconds, so
allowing a sign after it read the range 5"-10" as "5 neg10", which no
longer matched 5-10". Curly opening quotes (“ ‘ «) are never units, so
they keep the sign; a straight-quoted "-2.5" loses it, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC

Copy link
Copy Markdown
Contributor Author

Addressed in bc944d9.

  • Inch mark: I treated this as a regression rather than a trade-off. The previous commit introduced it, and 5"-10" matched 5-10" on main. I removed the straight " from the allow-list. A straight-quoted "-2.5" now loses its sign, which is what main does, so that case can't produce a false mismatch.
  • Opening quotes: the list now has “, ‘ and «. These are never used for units.
  • Tests: new must-fail cases “-2.5” and ‘−2.5’, and a must-match case 5"-10" vs 5-10".
  • Results: full suite 2139 passed. Doctests, mypy and ruff are clean.

I left the how-it-works.md wording alone. It's still accurate, and the code comment lists the ^ case.


Generated by Claude Code

@claude

claude Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @caufieldjh's task in 31s —— View job


Review of PR #151 (after push bc944d9)

  • Read the new commit and the source diff against origin/main
  • Checked the fix for the inch-mark (5"-10") and opening-quote points from the last review
  • Traced the updated allow-list against edge cases
  • Run tests: I couldn't. uv run pytest needs approval in this job, so what follows comes from reading the code, not from running it.

Earlier findings: all addressed

The regex is now at supporting_text_validator.py:830:

text = re.sub(r"(?:^|(?<=[\s(\[{=:~≈^“‘«]))[-−](?=\d)", "neg", text)
  • Inch/arcsecond marks: the straight " has been removed from the allow-list, so 5"-10" → 5 10 again, which matches 5-10". The new positive case ('a 5-10" tilt', 'a 5"-10" tilt') pins it. This is a better choice than my suggestion of documenting the trade-off. A straight-quoted "-2.5" just loses its sign, which is what main already does, so the change can't create a false mismatch.
  • More opening quotes: ‘ (U+2018) and « have been added. The straight ' and ’ (U+2019) are still left out, so 3'-5' and 3’-5’ stay ranges.
  • Tests for the quote entries: “-2.5” and ‘−2.5’ are now must-fail cases. This also covers both minus characters across the two quote styles.
  • The comment above the regex now explains why straight quotes are left out. Its examples match the tests.

Remaining notes (minor, none blocking)

  • « isn't covered by a test. “ and ‘ are, so this is only for completeness. A one-line case such as ("2.5", "«-2.5»") would stop it being dropped from the class later without anyone noticing.
  • normalize_text deliberately skips NFKC (:773), so look-alikes such as the fullwidth hyphen - or ﹣ before a digit still read as hyphens. They're rare in scientific text and match main's behaviour. I'm noting it only so it's on record.
  • The judgement calls from earlier rounds (− 2.5 with a space, lt/pm token collisions, =</=>, (-1,-2), genotypes) were all answered in earlier replies. I still agree with that reasoning.

Code quality / performance / security

  • The change only edits one character class and its comment, with no new logic. The docstring, doctests and docs/concepts/how-it-works.md are all still accurate.
  • The regex is a single lookbehind over a character class: linear time, with no risk of catastrophic backtracking. Performance is unchanged and there are no security concerns.

Summary

This commit fixes the last open item cleanly, and the reasoning in the commit message holds up: curly opening quotes are never units, but straight quotes can be. From reading the code I see nothing left that blocks merging, once CI passes.

Copy link
Copy Markdown
Contributor Author

Thanks. I'm not pushing a commit just for these two:


Generated by Claude Code

@caufieldjh
caufieldjh merged commit 2324933 into main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normalize_text strips <, >, ± and minus signs, so reversed comparisons and signs pass

2 participants