Skip to content

Detect the language of text made of multi-word dictionary entries - #1435

Open
AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:detect-language-from-phrases
Open

AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:detect-language-from-phrases

Conversation

@AdrianAtZyte

Copy link
Copy Markdown
Member

Fixes #1163

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing AdrianAtZyte:detect-language-from-phrases (30a06b5) with master (ce8c439)

Open in CodSpeed

@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (ce8c439) to head (30a06b5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1435   +/-   ##
=======================================
  Coverage   99.22%   99.23%           
=======================================
  Files         239      239           
  Lines        4256     4290   +34     
=======================================
+ Hits         4223     4257   +34     
  Misses         33       33           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AdrianAtZyte
AdrianAtZyte marked this pull request as ready for review September 23, 2026 14:27

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review (claude code-review, at 2b73aca; compared with the PR's merge-base because the branch is 56 commits behind master). Not approving as is:

  1. Scores are inflated per word. A multi-word entry now counts once per word, and every locale that has those words as separate single-word entries gets the same inflated score, while locales are ranked by that count first. detect_language('I will see you next week at noon', languages=None) returns ff on this head (nl at the merge-base; en is the right answer and scores [2,3] against ff's [3,0]), and search_dates on that text with auto-detection returns the junk match ('see', ...) plus a misdated next week. count_applicability('next week') goes from [0,0] to [2,0], and Meet me on 5 June next week ties nn and dje with en.
  2. Deduplication changed. The set of individual words replaces set(words) over whole tokens, so tokens that share a word undercount (last week and next week count week once), and scores depend on which phrases happen to share words.
  3. An existing expectation was changed. The Filipino sentence in tests/test_search.py flips from tl to fil because the inflated scores change which tied locale wins. That edit hides a behaviour change instead of showing it is intended.
  4. Tests are too narrow. They only check text that is a single multi-word entry (next week, next month). They do not cover mixed text, repeated entries, or several competing languages, so the ff result above passes the suite.

The branch also needs a rebase; #1401 changes _count_words_present_in_the_dictionary too (a guard so padded chunks don't credit parts), so this PR may overlap with it. Counting a multi-word entry once, when all of its words are present, would keep scores comparable.

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approving yet:

  • The new pattern \s+(\d+)$ (search.py, around line 49) backtracks quadratically on long runs of whitespace. Please anchor or restructure it, and add a test with a long whitespace run.
  • 114 this week now reports a number (tests/test_search.py, around line 1825).
  • Per-word scoring from my earlier review: a multi-word dictionary entry is counted once per word, which inflates scores.
  • codecov/patch and codecov/project fail on this head.

This branch has not been deployed

No deployments
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.

seach_dates not working for 'next week'

2 participants