DEV Community

loading...

Discussion on: Build a quick Summarizer with Python and NLTK

Collapse
davidisrawi profile image
David Israwi Author

Thank you very much Dhairya!

This bug could happen whenever you list of sentences contains one of length < 12. A good workaround is to remove the [:12] index completely and use the whole sentence as the sentenceValue keys. Does that make sense? So instead it would be:

sentenceValue[sentence] += wordValue[1]

Let me know if that fixes the problem!

Collapse
dhairyachandra profile image
Dhairya Chandra • Edited

I have changed it but it is still giving me some KeyError: and showing 3-4 starting lines from my text.

How to solve this error ?

Thread Thread
davidisrawi profile image
David Israwi Author

Hm sounds like you may have forgotten to remove the [:12] index from the other parts of your code where you use sentenceValue, maybe that is the issue? If not, feel free to share a snippet of your code so we can be on the same page.

Thread Thread
gauranshbhutani profile image
Gauransh Bhutani

Hi, I am still facing the same error index out of range...help me on this

Thread Thread
kavyakumar profile image
kavya-kumar

The code should be like this..
for sentence in sentences:
for wordValue in freqTable:
if wordValue in sentence.lower():
if sentence in sentenceValue:
sentenceValue[sentence] += freqTable[wordValue]
else:
sentenceValue[sentence] = freqTable[wordValue]

Forem Open with the Forem app