Exemplo n.º 1
0
            "<.*><.*><.*><.*><.*><{}><.*><.*><.*><.*><.*>".format(entity_name))
        sys.stdout = old_stdout
        surrounding_words = mystdout.getvalue()
        surrounding_words = surrounding_words.replace('\n', ' ')
        surrounding_words_list = surrounding_words.split('; ')

        # Find connotations
        connotations = []
        for phrase in surrounding_words_list:
            score = TextBlob(phrase).sentiment.polarity
            connotations.append(score)

        new_entity_object.surrounding_words = surrounding_words_list
        new_entity_object.surrounding_words_connotations = connotations
        all_entities.append(new_entity_object)

    print('\n')
    for i in all_entities:
        print(i.entity_name, i.surrounding_words,
              i.surrounding_words_connotations)
        print('\n')

        # find the hero,villain, victim
    score = {}
    for i in all_entities:
        score.update({i.entity_name: sum(i.surrounding_words_connotations)})
    hero_key = max(score.keys(), key=(lambda k: score[k]))
    villain_key = min(score, key=lambda k: score[k])
    print(score)
    print("The Hero is: ", hero_key)
    print("The Villain is: ", villain_key)