Open
Conversation
The _get_all_content_words_in_doc method was processing words in a different order (stem -> filter -> normalize) compared to _get_content_words_in_sentence (normalize -> filter -> stem). This mismatch meant some words would appear in the per-sentence word lists but not in the document frequency table, causing a KeyError during summarization. Aligned both methods to use the same processing order: normalize -> filter stop words -> stem. Also fixed _get_all_words_in_doc to return raw words instead of pre-stemmed words, since stemming is now handled consistently in _get_all_content_words_in_doc. Fixes miso-belica#176
miso-belica
requested changes
Feb 22, 2026
Owner
miso-belica
left a comment
There was a problem hiding this comment.
Hello, thank you for the fix. In order to accept it, please add a test reproducing the issue with the original code - red/green TDD approach. You are mentioning that there are 2 cases when this may happen so please add 2 tests - 1 for each.
Also, please add this into the CHANGELOG.md file.
Thank you for your help 🙂
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.
Fixes #176.
The
SumBasicSummarizercrashes with aKeyErrorwhen processing certain texts because the word processing pipeline is inconsistent between two methods._get_content_words_in_sentenceprocesses words in this order: normalize → filter stop words → stemBut
_get_all_content_words_in_doc(via_get_all_words_in_doc) does it differently: stem → filter stop words → normalizeThis means a word can end up in the per-sentence word list but be missing from the document frequency table (or vice versa), which causes the
KeyErrorwhen looking up the word frequency.The fix aligns
_get_all_content_words_in_docto follow the same processing order as_get_content_words_in_sentence: normalize → filter stop words → stem._get_all_words_in_docnow returns raw (unstemmed) words so the caller can apply the pipeline consistently.All existing sum_basic tests pass.