text
Importre
Fromnltk.tokeni
zeimportsent_tokeni
#Textparagraph
ze
Text=“So,keepworking.Keepstrivi
vesummarization
ng.Nevergiveup.Falldownseventimes,getupeight.Ease
isagreaterthreattoprogressthanhardshi
p.Easeisagreaterthreattoprogressthanhardshi
p.
So,keepmoving,keepgrowing,keeplearni
ng.Seeyouatwork.”
#Removespecialcharactersanddigits
Text=re.sub(‘
[^A-Za-z]
+’,‘‘
,text)
#Tokenizethesentences
Sentences=sent_tokeni
ze(text)
#Calculatethescoreofeachsentencebasedonthenumberofwords
#Thesentenceswithmorewordswillhaveahigherscore
Scores={}
Forsentenceinsentences:
Words=sentence.split()
Score=len(words)
Scores[sentence]=score
#Sortthesentencesbasedontheirscores
Sorted_sentences=sorted(scores.
items(),key=l
ambdax:x[1],reverse=True)
#Extractthetop2sentenceswiththehighestscoresasthesummary
Summary_sentences=[sentence[0]forsentencei
nsorted_sentences[:
2]]
Summary=““.join(summary_sentences)
#Printthesummary
Print(summary)