diff --git a/src/eval_mcf.py b/src/eval_mcf.py index 0cdf9cae1256664a40c4a8f2ac319f9737b7c9fd..22c26336921ed089ae601b8fd1b8e3f240aef557 100644 --- a/src/eval_mcf.py +++ b/src/eval_mcf.py @@ -13,6 +13,12 @@ refMcdFileName = sys.argv[3] hypMcdFileName = sys.argv[4] lang = sys.argv[5] +if len(sys.argv) == 7: + verbose = True +else: + verbose = False + + #print('reading mcd from file :', refMcdFileName) refMcd = Mcd(refMcdFileName) @@ -44,6 +50,10 @@ hypWordBuffer.readAllMcfFile() govCorrect = 0 labelCorrect = 0 +hypTotal = {} +refTotal = {} +refInterHypTotal = {} + hypSize = hypWordBuffer.getLength() for index in range(hypSize): refWord = refWordBuffer.getWord(index) @@ -52,16 +62,40 @@ for index in range(hypSize): hypGov = hypWord.getFeat("GOV") refLabel = refWord.getFeat("LABEL") hypLabel = hypWord.getFeat("LABEL") + + if hypLabel in hypTotal : + hypTotal[hypLabel] += 1 + else: + hypTotal[hypLabel] = 1 + + if refLabel in refTotal : + refTotal[refLabel] += 1 + else: + refTotal[refLabel] = 1 if refGov == hypGov : govCorrect += 1 if refLabel == hypLabel : labelCorrect += 1 - -LAS = labelCorrect / hypSize -UAS = govCorrect / hypSize - -print(lang, LAS, UAS) - + if refLabel in refInterHypTotal : + refInterHypTotal[refLabel] += 1 + else: + refInterHypTotal[refLabel] = 1 + +LAS = 100 * labelCorrect / hypSize +UAS = 100 * govCorrect / hypSize + +print("%s\t%.2f\t%.2f" % (lang, LAS, UAS)) + + +if verbose : + print("------------------------------") + print("label\tprec\trec\tfscore") + print("------------------------------") + for label in refInterHypTotal: + precision = refInterHypTotal[label] / hypTotal[label] + recall = refInterHypTotal[label] / refTotal[label] + fscore = 2 * precision * recall / (precision + recall) + print("%s\t%.2f\t%.2f\t%.2f" % (label, precision, recall, fscore) ) # print("REF GOV = ", refGov, "HYP GOV = ", hypGov, "REF LABEL = ", refLabel, "HYP LABEL = ", hypLabel)