Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Summarizer #1025

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BasicPythonScripts/Text Summarizer/readme.md
Original file line number Diff line number Diff line change
@@ -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
![Code Screenshot](https://media.discordapp.net/attachments/829696850700402740/895145748528762950/unknown.png)

<BR>


### OUTPUT SCREENSHOT
![App Screenshot](https://media.discordapp.net/attachments/829696850700402740/895143956655001620/unknown.png)
1 change: 1 addition & 0 deletions BasicPythonScripts/Text Summarizer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nltk
48 changes: 48 additions & 0 deletions BasicPythonScripts/Text Summarizer/summarizer.py
Original file line number Diff line number Diff line change
@@ -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)