Skip to content

Fix stray space in longest tokenizer "า" rule - #1609

Open
KittiphonKamnuan wants to merge 2 commits into
PyThaiNLP:mainfrom
KittiphonKamnuan:fix/longest-front-dep-typo
Open

KittiphonKamnuan wants to merge 2 commits into
PyThaiNLP:mainfrom
KittiphonKamnuan:fix/longest-front-dep-typo

Conversation

@KittiphonKamnuan

Copy link
Copy Markdown

What do these changes do

Fix the longest-front-dep-typo entry in the bug ledger (working-docs/ROADMAP.md): with the longest engine, an unknown "า" now joins the previous token, like "ะ" already does.

What was wrong

_FRONT_DEP_CHAR in pythainlp/tokenize/longest.py held "า " (with a trailing space). _is_dependent_char() tests a single character with in, so "า" never matched. With dictionary ["ก", "ข"], "กา" returned ["ก", "า"].

How this fixes it

  • Change "า " to "า".
  • Update the pinning test to assert the fixed behavior ("กา" → ["กา"], "กาข" → ["กา", "ข"]), and check that every entry in _FRONT_DEP_CHAR is one character long.
  • Remove the # BUG-LEDGER marker and the ledger entry; add a change log entry.

Behavior check: I compared longest.segment() output before and after on 1,158 texts (sample sentences plus dictionary words followed by a stray "า"). Every changed output is a stray "า" joining the previous token (e.g. "กาาาา": ["กา", "าาา"] → ["กาาาา"]). Text without a stray "า" is unchanged.

Your checklist for this pull request

  • Passed code styles and structures (ruff check, ruff format --check)
  • Passed code linting checks and unit test (python -m unittest tests.core: 753 tests OK, 33 skipped)

🤖 Generated with Claude Code

@wannaphong wannaphong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the bug fix! Can you send this patch to the main branch?

@coveralls

coveralls commented Nov 20, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 73.154%. remained the same — KittiphonKamnuan:fix/longest-front-dep-typo into PyThaiNLP:main

`_FRONT_DEP_CHAR` held "า " (with a trailing space), so an unknown
"า" never joined the previous token, while "ะ" did.

- Change "า " to "า" in `pythainlp/tokenize/longest.py`
- Update the pinning test to assert the fixed behavior
- Remove the `longest-front-dep-typo` entry from the bug ledger
@KittiphonKamnuan
KittiphonKamnuan force-pushed the fix/longest-front-dep-typo branch from dd9e1ae to 1fd17d0 Compare November 20, 2026 17:35
@KittiphonKamnuan
KittiphonKamnuan changed the base branch from dev to main November 20, 2026 17:35
@KittiphonKamnuan

Copy link
Copy Markdown
Author

Thanks! Rebased onto main and retargeted the PR (one commit; the change log entry now goes under a new [Unreleased] section on main). tests.core passes on main (674 tests OK). I did the same for #1610.

@KittiphonKamnuan

KittiphonKamnuan commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Thanks for approving the workflows. About the failing checks:

  • unittest (ubuntu-latest, 3.13): all 800 tests pass. This run still used dev as the base (BASE_REF: dev in the log), before I retargeted the PR to main. The diff-cover gate flagged parse/core.py, tag/named_entity.py, and transliterate/core.py, which this PR does not touch.
  • coverage/coveralls (-0.03%): this drop was real. With the fix, etcc.segment() no longer reaches the merge step in _cut_subword(). I added a direct test in c6f00a1; tests.core coverage is now one line above main.

Could you re-run the workflows now that the base is main?

The longest engine no longer leaves a lone "า", so etcc.segment() no longer reaches the merge step in _cut_subword(). Call it directly to keep it covered.
@sonarqubecloud

Copy link
Copy Markdown

@wannaphong wannaphong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@wannaphong wannaphong added the bug bugs in the library label Nov 22, 2026

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

bug bugs in the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants