Repository navigation
fix(text): count hash characters, not runs, in SymbolsToWordsFilter - #2519
Open
usmanmateen wants to merge 2 commits into
Open
usmanmateen wants to merge 2 commits into
usmanmateen wants to merge 2 commits into
Conversation
"##" and "###" are made only of hash symbols, like "#", but the filter scores "### ### ### ###" as 0 and keeps it, while "# one two three four five" scores 0.17 and is removed. Signed-off-by: usmanmateen <74776275+usmanmateen@users.noreply.github.com>
The symbol ratio of a word divided the number of regex_hash ("#+")
matches by the word length, so "##" scored 0.5 and "###" 0.33, and
neither counted as a symbol word. Count the "#" characters instead, so a
word is a symbol word when more than half of its characters are "#", as
the comment says. Hashtags such as "#hashtags" are unaffected.
Signed-off-by: usmanmateen <74776275+usmanmateen@users.noreply.github.com>
usmanmateen
requested review from
praateekmahajan
and removed request for
a team
October 20, 2026 07:38
Contributor
[Medium impact] This PR appears safe to merge. Summary
Reviews (1) · Last reviewed commit: "fix(text): count hash characters, not ru..." · Reviewed by Greptile |
4 tasks done
Contributor
Author
|
@praateekmahajan could you review this when you get a chance? It's a small fix to how SymbolsToWordsFilter counts hash characters. |
This branch has not been deployed
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.
Description
Closes #2517.
SymbolsToWordsFiltercomputed a word's symbol ratio aslen(regex_hash.findall(word)) / len(word), withregex_hash = re.compile("#+"). That counts runs of#, not#characters, so"##"scored 0.5 and"###"0.33, and neither counted as a symbol word. It now counts the#characters (word.count("#")), so a word is a symbol word when more than half of its characters are#, as the comment says.main"### ### ### ###""## Installation\nRun the script""# one two three four five""Use #hashtags in a sentence"Only words with two or more
#in a row score differently. Words with a single#, such as#hashtagsorC#, score as before, and so do ellipses.regex_hashis no longer used instring.py, so the import is dropped; it stays inconstants.py.The PR has two commits: the regression test, which fails on
main, and the fix.Usage
Checklist
Tests:
test_symbolswords_hash_runsfails onmainand passes with the change.pytest tests/stages/text/modules/test_filters.py tests/stages/text/modules/test_modifiers.py: 210 passed, 1 skipped (the existing MeCab skip).ruff checkandruff format --check(0.14.10) pass on the changed files.