Skip to content

fix autocorrect and sentence_tokenize stopping after 32 matches#84

Open
CodingSelim wants to merge 1 commit into
linuxscout:masterfrom
CodingSelim:fix-resub-count-truncation
Open

fix autocorrect and sentence_tokenize stopping after 32 matches#84
CodingSelim wants to merge 1 commit into
linuxscout:masterfrom
CodingSelim:fix-resub-count-truncation

Conversation

@CodingSelim

Copy link
Copy Markdown

noticed autocorrect and sentence_tokenize quietly give up partway through longer text. both call re.sub with re.UNICODE as the 4th positional arg, but that slot is count, not flags. re.UNICODE happens to be 32 so each sub just stops after 32 replacements.

so autocorrect leaves any real-length text under-corrected past the 32nd match, and sentence_tokenize only inserts 32 split markers and hands back the whole tail as one unsplit sentence.

quick repro:

import pyarabic.araby as ar
text = " ".join(["سابقاً"] * 40)
ar.autocorrect(text).count("ساب"+"قاً")   # 8 left uncorrected, should be 0
len(ar.sentence_tokenize(" ".join(["جملة رقم."] * 40)))  # 33, should be 40

fix is just moving it to flags=re.UNICODE so the count goes back to unbounded. added a case to each of the existing tests with more than 32 matches, they fail before and pass after. full test_araby suite is green.

both were passing re.UNICODE as the 4th positional arg to re.sub, which is
count not flags. re.UNICODE is 32 so every substitution silently stopped
after 32 replacements. so autocorrect left long text under-corrected past
the 32nd match and sentence_tokenize returned the tail as one unsplit blob.
moved it to flags= so the count is unbounded again, added tests with >32
matches that fail before and pass after.
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.

1 participant