import spacy
import textacy

scoreForConclusion = 60/100

nlp = spacy.load("en_core_web_sm")

#Count the total number of characters in the speech


def conclisions(speech):
    totalCharacterCount = len(speech)
    conclusionCharacterCount = (85/100)*totalCharacterCount
    conclusion = (speech[int(conclusionCharacterCount):int(totalCharacterCount)])
    # print(">>>Conclusion<<<")
    # print(conclusion)
    return {
        "message": conclusion,
        "score": scoreForConclusion
    }


def comments(speech):
    conclusion = conclisions(speech)["message"]
    final_words = []

    with open('content analyzing/bestPracticesForConclusion.txt', 'r') as file:
        for line in file:
            clear_line = line.replace("\n", '').replace(",", '').replace("'", '').strip()
            word, emotion = clear_line.split(':')

            if word in conclusion:
                final_words.append(word)

    return {
        "message": final_words,
        "score": scoreForConclusion
    }


def questions(speech):
    retVal = []
    doc = nlp(conclisions(speech)["message"])

    patterns = [[{"POS": "ADV"}, {"POS": "AUX"}, {"POS": "PRON"}], [{"POS": "ADV"}, {"POS": "AUX"}, {"POS": "NOUN"}]]

    verb_phrases = textacy.extract.token_matches(doc, patterns)

    for verb_phrases in verb_phrases:
        print("You used questions forms in your conclusion. It is a good practice for a conclusion.")
        print(f"Identified questions : {verb_phrases}")
        retVal.append(f"Identified questions : {verb_phrases}")
    return {
        "message": retVal,
        "score": scoreForConclusion
    }

