import spacy
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation

nlp = spacy.load("en_core_web_sm")

stopwords = list(STOP_WORDS)
punctuation = punctuation + '\n'


def synonymsFunc(topic, speech):
    Topic = nlp(topic)
    Content = nlp(speech)

    Total_similarity = 0

    for token1 in Content:
        if token1.text.lower() not in stopwords:
            if token1.text.lower() not in punctuation:
                for token2 in Topic:
                    print((token1.text, token2.text), "similarity", token1.similarity(token2))
                    Total_similarity = Total_similarity + token1.similarity(token2)


    print(len(Content))
    print(f'Total score for the similarity: {Total_similarity}')
    average_similarity = (Total_similarity/len(Content))*100
    print(f'Average score for the similarity between topic and content: {average_similarity}%')
    return {
        "message": str(f'Average score for the similarity between topic and content: {average_similarity}%'),
        "score": 50/100
    }
