Repository navigation
fix(text-analyzer): leave punctuation-only tokens out of the top words - #738
Conversation
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
Thanks, reproduced on main: --text 'Wait... what? ... ok ... - fine - yes!' listed "" and - as the two most frequent words and printed a blank row in the report. With this branch the top words are wait, what, ok, fine, yes, and the starter eval text (The quick brown fox...) produces byte-identical JSON before and after, so the dataset and the recorded expectations (20 words, 97 characters, 3 sentences, the x5) are unaffected.
I checked a few more tokens: v2, don't, 3.14, well-known, café, €5 and CJK text are all kept, while ©, _, & and en/em dashes are dropped, which matches the intent. The new test fails on the old script and passes with the fix, ruff is clean, all commits are signed off, and the changelog entry is under Unreleased / Fixed.
One not-blocking thought inline about word_count. Otherwise good to go.
|
@chrisknvidia thanks for the thorough check! I replied to the word_count note inline. If you're happy keeping this PR scoped as is, it should be good to merge. |
rng1995
left a comment
There was a problem hiding this comment.
Thanks for your contribution, @dhananjay6561. Reviewed e41cc1943d0d; no new actionable defects found. Filtering punctuation-only entries fixes top_words while retaining numbers, inner punctuation, and stable frequency ordering. The recorded starter statistics remain compatible.
Validation: All 3 reference text-analyzer tests passed.
I read the existing word_count/average_word_length discussion and the author's reply. Keeping those established metrics unchanged is reasonable for this top_words fix; I have no additional change request.
rng1995
left a comment
There was a problem hiding this comment.
Thanks, @dhananjay6561. Rechecked 61b5b98a508e and the latest discussion. The delta from e41cc1943d0d only merges main's task-list fix (#680), its tests and changelog. Text-analyzer source, its regression tests and dependencies are unchanged; no new actionable defects found.
Retained validation: all 3 text-analyzer tests passed on e41cc1943d0d; I did not rerun them for this unrelated merge. The existing word_count/average_word_length note and your reply still support keeping this fix scoped to top_words; I have no additional change request.
Summary
The text-analyzer reference skill built its "Top words" from
text.split()tokens with a fixed set of punctuation stripped, so tokens that are only punctuation ended up in the list. An ellipsis...stripped to the empty string and was reported as the word"", and dashes (-,–,—) or&were reported as words. In text with a few of those they took places in the top 5 and pushed real words out, and the text report printed a blank row.Top words now only count tokens that contain at least one letter or digit. For
Wait... what? ... ok ... - fine - yes!the top words go from"", "-", wait, what, oktowait, what, ok, fine, yes. Word, line, character and sentence counts are unchanged, as are tokens likev2,don't,3.14andwell-known, and the starter eval text still reports 20 words, 97 characters, 3 sentences andthe×5.Fixes #736.
Verification
make lintmake testmake buildTested on macOS 26.6 arm64, Python 3.14.7, on top of upstream
d2cb1388.pytest -n 0 tests/test_reference_text_analyzer.py: 3 passed. Against the unchangedanalyze_text.pythe punctuation test fails and the other two pass.ruff check src testsandruff format --checkon the changed files: passed.python -m build: built the sdist and wheel.make testsuite; the change is limited to the standalone text-analyzer script, which nothing else imports.Release Impact
CHANGELOG.md