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)
    Content = nlp(speech)
    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
    }

