Repository navigation
Keep comparison, plus-minus and minus signs through normalization - #151
Conversation
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 encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
The Generated by Claude Code |
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
Claude finished @caufieldjh's task in 2m 14s —— View job Review of PR #151: keep comparison, ± and minus signs through normalization
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 I found two places where the code doesn't fully deliver the "ASCII and Unicode spellings are equivalent" claim. 1.
|
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
|
Fixed in 777810d. I confirmed both main findings by running them:
New tests: both U+2212 spellings, Not changed, with reasons:
Generated by Claude Code |
|
Claude finished @caufieldjh's task in 1m 1s —— View job Review of PR #151 (after push
|
| 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:122says validation reads "+-,+/-and±all as the same word". That isn't true for a bare+-before a letter, and that exception is exactly whyCa2+-dependentworks. Adding "(except+-before a letter)" would keep the explanation accurate. - Scientific notation.
10^-5becomes10 neg5, while1e-5becomes1e 5(the hyphen afterereads 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.5with a space after the minus, collisions with thelt/pm/letokens, 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
|
Fixed in ff2fcd5. I confirmed it by running it: Instead of adding
The remaining judgement calls stay as they are, for the reasons in my earlier reply. Generated by Claude Code |
|
Claude finished @caufieldjh's task in 58s —— View job Review of PR #151 (after push
|
| 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.
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 catch3,-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 andmainbehaved the same way, so it isn't a regression. - Other prefixes that drop the sign, such as a straight quote mark (
"-2.5"),~-3,≈−2and/-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.≈ −2with a space keeps the sign while≈−2drops it, so those two spellings don't match each other. - The judgement calls from earlier reviews (
− 2.5with 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
|
Fixed in fba59d9. I was wrong to say in the last commit that
I've left Generated by Claude Code |
|
Claude finished @caufieldjh's task in 55s —— View job Review of PR #151 (after push
|
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
|
Addressed in bc944d9.
I left the Generated by Claude Code |
|
Claude finished @caufieldjh's task in 31s —— View job Review of PR #151 (after push
|
|
Thanks. I'm not pushing a commit just for these two:
Generated by Claude Code |
Fixes #125.
Problem
normalize_textreplaced all punctuation with spaces, including symbols that change a claim's meaning. Sop < 0.05matchedp > 0.05,decreased by -2.5 foldmatcheddecreased by 2.5 fold, and5 2 mMmatched5 ± 2 mM.Changes
In
normalize_text, before punctuation is stripped:<,>,≤,≥,⩽and⩾(and<=,>=) become the wordslt,gt,leandge.±and+/-becomepm, with either an ASCII hyphen or U+2212 as the minus, and also before a letter (+/-SD). A bare+-becomespmtoo, except before a letter, soCa2+-dependentis still read as a charge followed by a hyphen.-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. So80 °Cdoes not match−80 °C, and10^5does not match10^-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.->,=>,<->, and<-when not before a digit) are removed first, so they aren't read asgt/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 leavesCa2+-dependentalone (pinned by a test). One doctest in_all_parts_foundchanged from True to False, because normalization can now tellCa2±dependentfromCa2+-dependenton its own.Docs:
docs/concepts/how-it-works.md(normalization list) anddocs/how-to/repair-validation-errors.md(why+-→±still needs a literal check).Behaviour changes to note
±, 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 as5 +- 2quoted for a reference's5 ± 2; the repairer offers±for those.main, where the sign is still lost:–2.5)− 2.5)(-1,-2))"-2.5")-Tests
tests/test_meaning_symbols.pywas written first; 10 cases failed before the fix. It covers:≤/≥−80 °C,10^-5vs10^5, and~-2/≈−2±It also has positive cases that must keep matching:
+/−and+/-SD10%-20%,5°-10°and5"-10"Ca2+-repairFull suite: 2139 passed. Doctests, mypy and ruff are clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC