diff --git a/BasicPythonScripts/Text Summarizer/readme.md b/BasicPythonScripts/Text Summarizer/readme.md new file mode 100644 index 000000000..19ad3d9fb --- /dev/null +++ b/BasicPythonScripts/Text Summarizer/readme.md @@ -0,0 +1,16 @@ +# TEXT SUMMARIZER + +Text Summarizer is a basic console based summarizer which takes user input for text and gives the output + + + +# Screenshots + +### CODE SCREENSHOT + + +<BR> + + +### OUTPUT SCREENSHOT + \ No newline at end of file diff --git a/BasicPythonScripts/Text Summarizer/requirements.txt b/BasicPythonScripts/Text Summarizer/requirements.txt new file mode 100644 index 000000000..6fa2de444 --- /dev/null +++ b/BasicPythonScripts/Text Summarizer/requirements.txt @@ -0,0 +1 @@ +nltk \ No newline at end of file diff --git a/BasicPythonScripts/Text Summarizer/summarizer.py b/BasicPythonScripts/Text Summarizer/summarizer.py new file mode 100644 index 000000000..5be8120d7 --- /dev/null +++ b/BasicPythonScripts/Text Summarizer/summarizer.py @@ -0,0 +1,48 @@ +import nltk +nltk.download('stopwords') +nltk.download('punkt') +from nltk.corpus import stopwords +from nltk.tokenize import word_tokenize, sent_tokenize + +print("Enter Text") +text = input() +stopWords = set(stopwords.words("english")) +words = word_tokenize(text) + +freqTable = dict() +for word in words: + word = word.lower() + if word in stopWords: + continue + if word in freqTable: + freqTable[word] += 1 + else: + freqTable[word] = 1 +sentences = sent_tokenize(text) +sentenceValue = dict() + +for sentence in sentences: + for word, freq in freqTable.items(): + if word in sentence.lower(): + if sentence in sentenceValue: + sentenceValue[sentence] += freq + else: + sentenceValue[sentence] = freq + + +sumValues = 0 +for sentence in sentenceValue: + sumValues += sentenceValue[sentence] + + +average = int(sumValues / len(sentenceValue)) + +summary = '' +for sentence in sentences: + if (sentence in sentenceValue) and (sentenceValue[sentence] > (1.2 * average)): + summary += " " + sentence +print(summary) + + + +