Repository navigation
test(591): pin comparator scores on Arabic and Persian text - #597
Merged
Merged
Conversation
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Report generated by Automated Security Helper (ASH) at 2026-11-19T03:11:58+00:00 |
vawsgit
approved these changes
Nov 19, 2026
vawsgit
left a comment
Contributor
There was a problem hiding this comment.
✅ LGTM!
I found no blocking problems. I measured everything below on the PR head f63ee34 with PYTHONPATH set to that checkout's src. inspect.getfile(stickler) confirmed the path.
What I verified
- Diff:
git diff origin/dev...f63ee34changes onlytests/common/comparators/test_arabic_text.py(+297).origin/devis still at9fc70de, which is the merge base. The branch is not behinddev, so the pinned scores match what will merge. - New file: 84 passed on Python 3.10 (Unicode 13), 3.12 and 3.14 (Unicode 16). It also passed with
pytest -n 4, so the tests do not depend on run order. - Full suite: after
uv sync --extra llm --extra bert --frozenanduv run coverage run -m pytest, the result was 5541 passed, 3 skipped, 1 xfailed. This matches the PR body.ruff checkandruff format --checkpass, and CI is green. - Mutation testing: I applied all 23 source changes listed in the PR body, one at a time. Each one made at least one new test fail. None behaved the same as the original code. For example:
- removing NFC from
NormalizedComparatorfailedtest_only_normalized_matches_composed_and_decomposed_hamza(I also ran that one by hand); - rejecting non-ASCII digits in
DateComparatorfailed 8 tests; - matching only ASCII and Arabic-Indic digits in the year-first check failed the Persian case.
- removing NFC from
- Scores: I called each comparator directly and reproduced every score in the PR body. Examples:
- diacritics: Levenshtein 1/2;
مُحَمَّدٌ/محمد: Levenshtein 4/9, ANLS* 0.0;- presentation forms and the lam-alef ligature: 0.0 on all five text comparators;
- CLDR short date with right-to-left marks: 0.0, and 1.0 without the marks;
- Solar Hijri
۱۴۰۳/۲/۲۵: 0.0; - phone numbers in Arabic-Indic and Persian digits: 1.0.
- Code points: I named every non-ASCII character with
unicodedata.name. Each string is the variant its test ID claims, for example U+0623 against U+0627 U+0654, U+06CC/U+06A9 against U+064A/U+0643, and U+FEE3 U+FEA4 U+FEE4 U+FEAA for the positional forms of محمد. The only invisible characters (RLM and ZWNJ) are written as escapes. - Locale and calendar claims: Babel gives
14/5/2024for ar_EG, ar_SA and ar_AE, with marks after the day and the month. 1403/2/25 in the Solar Hijri calendar is 14 May 2024. - Housekeeping: the partial scores use
pytest.approx. The file placement and name followtests/README.md. No CHANGELOG entry is needed for a tests-only change, per RELEASING.md.Part of #591is the right link, because the step that decides which results are gaps is still open.
Non-blocking (optional): test_identical_arabic_text_matches would pass for almost any comparator. It works as a baseline and needs no change.
Contributor
|
Merged, thank you for the thorough tests and for the mutation checks in the description. #591 stays open for deciding which of these results are gaps. |
2 of 4 tasks
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.
Issue Reference
Part of #591. This is the first step there, pinning today's scores. Which results are gaps is still an open question in #591, so the issue stays open.
Description of Changes
Adds
tests/common/comparators/test_arabic_text.py. It records what the text, date and phone comparators score today on Arabic and Persian text, so a later change to any of them is deliberate. Tests only: no source change and no score change.Changes Made
What the tests pin, on
devat9fc70de:Written variants. Exact and Normalized score 0.0 for seven pairs that are the same word or value written two ways:
Levenshtein, Fuzzy and ANLS* give these partial credit, pinned as fractions. For example, diacritics score 1/2 with Levenshtein. ANLS* scores 0.0 once Levenshtein falls below its 0.5 leaf threshold:
مُحَمَّدٌ/محمدis 4/9 with Levenshtein and 0.0 with ANLS*.Presentation forms. Every text comparator, Levenshtein and Fuzzy included, scores 0.0 for presentation forms against the letters they display: positional forms of
محمد, and the lam-alef ligature againstلا. Text extracted from some PDFs contains these.Unicode handling in Normalized.
،,؟) and all whitespace.Dates and phone numbers.
DateComparatormatches dates written in Arabic-Indic and Persian digits, and reads a year-first date such as٢٠٢٤-٠٣-٠٤as year, month, day.14 مايو 2024). The same date withMaymatches.١٤/٥/٢٠٢٤); without the marks, the same date matches.۱۴۰۳/۲/۲۵for 14 May 2024).PhoneComparatormatches numbers in Arabic-Indic and Persian digits, and scores 0.0 for a different number.The date tests depend on python-dateutil reading these digits, and on
DateComparator's year-first check (_YEAR_FIRST_RE) matching them through\d. The phone tests depend on phonenumberslite, and the Fuzzy scores on rapidfuzz. If a dependency bump fails one of them, the user-visible score changed.Why These Changes Are Needed
Apart from
NumericComparator(#560), nothing tested the comparators on Arabic text, so a change to their scores there would go unnoticed. If #591 settles that some of these results are gaps, the fix PR will change the matching assertions here, on purpose. The tests are in one file, rather than spread acrosstest_normalized.py,test_date.pyandtest_phone.py, so that the language-support docs in #592 can link to one place.The alef maqsura pair is
مصطفى/مصطفيrather than theعلى/عليpair in the issue, becauseعلى(the preposition) andعلي(the name) are different words.Testing
Unit tests added/updated
Integration tests added/updated
Manual testing completed
All existing tests pass
New file: 84 tests.
Full suite: CI's own commands pass on Python 3.10, 3.11, 3.12, 3.13 and 3.14. I ran
uv sync --extra llm --extra bert --frozen, thenuv run coverage run -m pytest -v -s. Each version gives 5,541 passed (84 of them new), 3 skipped and 1 xfailed.Lint:
ruff check .passes, andruff format --checkpasses on the new file.Mutation checks: I made 23 targeted source changes, one at a time, and each makes at least one new test fail.
The 23 source changes
NormalizedComparator:ExactComparator: apply NFC; remove punctuation and whitespace.LevenshteinComparator: apply NFC; remove tatweel.FuzzyComparator: apply NFC; remove combining marks.ANLSStarComparator: apply NFC; no leaf threshold; leaf threshold<becomes<=.DateComparator:مايوas May.PhoneComparator: reject non-ASCII digits; any two valid numbers match.Checklist
CHANGELOG.mdentry added under[Unreleased], or not needed because nothing user-visible changedBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.