import argparse, sys
parser = argparse.ArgumentParser(description='Calculate accuracy measure.')

parser.add_argument("test_file", help="file with machine sentiment labels")
parser.add_argument("gold_file", help="file with gold sentiment labels")
if len(sys.argv)==1:
    print("Usage: sent-eval.py test_file gold_file")
    sys.exit(1)
args = parser.parse_args()
#print args.test_file, args.gold_file

correct = 0
incorrect = 0

line_nr = 0
with open(args.test_file,'r') as f_test, open(args.gold_file,'r') as f_gold:
    for line_test, line_gold in zip(f_test, f_gold):

        test_toks, gold_toks  = line_test.split(), line_gold.split()
        if len(test_toks) != len(gold_toks):
            print("Error: unequal number of tokens in line %d" % line_nr )
            sys.exit()
        for nr in range(len(test_toks)):
            if test_toks[nr]==gold_toks[nr]: correct += 1
            else: incorrect += 1
        line_nr += 1

# this is equivalent to tp+tn / tp+tn+fp+fn:
accuracy = correct / float(correct +  incorrect)
print("overall accuracy: %.3f" % accuracy)