fix: correct nl.toknize -> nl.tokenize typo in TopicSegmentationChunking.extract_keywords - #2218
Open
STiFLeR7 wants to merge 1 commit into
Open
Conversation
…ing.extract_keywords extract_keywords() called the non-existent nl.toknize.word_tokenize instead of nl.tokenize.word_tokenize, raising AttributeError on every invocation. This is the same typo class reported and fixed in issue unclecode#59 (2024), but that fix only patched the constructor's nl.toknize.TextTilingTokenizer() call and missed this second, separate occurrence in extract_keywords(), which has been broken ever since. Adds a unit test that reproduces the AttributeError against the unfixed code (verified red) and passes after the fix (verified green).
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.
Root cause
TopicSegmentationChunking.extract_keywords()calls the non-existentnl.toknize.word_tokenizeinstead ofnl.tokenize.word_tokenize, raisingAttributeError: module 'nltk' has no attribute 'toknize'on every invocation.This is the same typo class reported in #59 (2024) — but that report/fix only covered the constructor's
nl.toknize.TextTilingTokenizer()call (fixed in f5a4e80). It missed this second, separate occurrence of the identical typo inextract_keywords(), which has been broken ever since and crashes bothextract_keywords()andchunk_with_topics().Found via direct source review, not an existing issue.
Fix
One-line fix:
nl.toknize.word_tokenize->nl.tokenize.word_tokenize(crawl4ai/chunking_strategy.py:122).Test evidence
Added
tests/unit/test_chunking_strategy_unit.py. Verified red-before-green:AttributeError: module 'nltk' has no attribute 'toknize'Full
tests/unit/suite: 49 passed.ruff checkclean on both changed files.