コード例 #1
0
    return classification


if __name__ == "__main__":
    if len(sys.argv) < 3:
        print(sys.argv[0] + " <lexicon_filepath> " + "<narrative_filepath>")
        quit()

    lexicon_filepath = sys.argv[1]
    narrative_filepath = sys.argv[2]

    # Lexicon is a dict indexed by words of the english dictionary.
    # Each value is a list of tuples [(nrc_emotion, association)]
    lexicon = parse_nrc_lexicon(lexicon_filepath)

    # Narrative is a dict indexed by sentence id.
    # Each value is a tuple (sentence, rpg_emotion)
    narrative = rpg_ec.parse_narrative_data(narrative_filepath)

    # Classify a narrative according to rpg_emotions:
    classification = classify_narrative(narrative, lexicon, 20)

    # Calculate confusion matrix
    confusion_matrix = rpg_ec.rpg_create_confusion_matrix(
        narrative, classification)

    rpg_ec.rpg_print_confusion_matrix(confusion_matrix)
    print(rpg_ec.calculate_accuracy(confusion_matrix))

    rpg_ec.rpg_print_classification(classification, "classification.txt")
コード例 #2
0
                        atualTrans = 3
                    else:
                        linhas[linha - 1]['emotion'] = 'agitated'
                        linhas[linha - 1]['prob'] = prob
                        atual = 'agitated'
                        atualTrans = 4

                    cont = cont + 1

                    inicio = inicio + 1

            for x in range(0, len(linhas)):
                str1 = ' '.join(linhas[x]['arranjo'])
                classification[x + 1] = (str1, str(linhas[x]['emotion']))

            narrative = rpg_ec.parse_narrative_data('datasets/ep' +
                                                    str(episodio) + '.txt')

            confusion_matrix = rpg_ec.rpg_create_confusion_matrix(
                narrative, classification)

            resultado = rpg_ec.calculate_accuracy(confusion_matrix)
            ##                resultEp1Accura.append(resultado)
            ##                limiarArray.append(limiar)
            ##                janelaArray.append(janela)

            DifTransicao = 0

            def calculateDifference(transition, episodio, TransEps):
                DifTrans = 0
                if transition >= TransEps[episodio - 1]:
                    DifTrans = transition - TransEps[episodio - 1]