Skip to content

fix: correct nl.toknize -> nl.tokenize typo in TopicSegmentationChunking.extract_keywords - #2218

Open
STiFLeR7 wants to merge 1 commit into
unclecode:developfrom
STiFLeR7:fix/topic-chunking-extract-keywords-toknize-typo
Open

fix: correct nl.toknize -> nl.tokenize typo in TopicSegmentationChunking.extract_keywords#2218
STiFLeR7 wants to merge 1 commit into
unclecode:developfrom
STiFLeR7:fix/topic-chunking-extract-keywords-toknize-typo

Conversation

@STiFLeR7

Copy link
Copy Markdown

Root cause

TopicSegmentationChunking.extract_keywords() calls the non-existent nl.toknize.word_tokenize instead of nl.tokenize.word_tokenize, raising AttributeError: 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 in extract_keywords(), which has been broken ever since and crashes both extract_keywords() and chunk_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:

  • Before the fix: test fails with AttributeError: module 'nltk' has no attribute 'toknize'
  • After the fix: test passes

Full tests/unit/ suite: 49 passed. ruff check clean on both changed files.

…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).
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