Commit 2130f133 authored by Rathnayake R.M.Y.A.B's avatar Rathnayake R.M.Y.A.B

Upload Keyword extracting class

parent 385e99a4
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
import string
nlp = spacy.load('en_core_web_sm')
#def keywordExrtraction(topic, speech):
#Topic = nlp(topic)
text2 = open("Essay.txt", encoding="utf-8").read()
lower_case2 = text2.lower()
cleaned_text2 = lower_case2.translate(str.maketrans('', '', string.punctuation))
Content = nlp(cleaned_text2)
stopwords = list(STOP_WORDS)
punctuation = string.punctuation + '\n'
word_frequencies = {}
for word in Content:
if word.text.lower() not in stopwords:
if word.text.lower() not in punctuation:
if word.text not in word_frequencies.keys():
word_frequencies[word.text] = 1
else:
word_frequencies[word.text] += 1
topicWords = []
#for words in Topic:
#topicWords.append(words.text)
# print(topicWords)
keyWords = []
print("Extracted Key Words:")
for word in word_frequencies.keys():
if word_frequencies[word] >= 3:
keyWords.append(word)
print(word)
# return {
# "message": keyWords,
# "score": 50/100
# }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment