blob: 96f25be77eeb0d0f20efc30cca17b5518263b912 [file] [log] [blame]
dazae94ab182020-09-01 16:41:30 +02001from CoNLL_Annotation import *
2from collections import Counter
3import pandas as pd
4
5
6def eval_lemma(sys, gld):
7 match, err, symbol = 0, 0, []
8 mistakes = []
9 for i, gld_tok in enumerate(gld.tokens):
10 if gld_tok.lemma == sys.tokens[i].lemma:
11 match += 1
12 elif not sys.tokens[i].lemma.isalnum(): # This was added because Turku does not lemmatize symbols (it only copies them) => ERR ((',', '--', ','), 43642)
13 symbol.append(sys.tokens[i].lemma)
14 if sys.tokens[i].word == sys.tokens[i].lemma:
15 match += 1
16 else:
17 err += 1
18 else:
19 err += 1
20 mistakes.append((gld_tok.word, gld_tok.lemma, sys.tokens[i].lemma))
21 return match, err, symbol, mistakes
22
23
24
25if __name__ == "__main__":
26
27 # Read the Original TiGeR Annotations
28 gld_filename = "/home/daza/datasets/TIGER_conll/tiger_release_aug07.corrected.16012013.conll09"
29 gld_generator = read_conll_generator(gld_filename, token_class=CoNLL09_Token)
30
31 # Read the Annotations Generated by the Automatic Parser [Turku]
32 sys_filename = "/home/daza/datasets/TIGER_conll/tiger_turku_parsed.conllu"
33 sys_generator = read_conll_generator(sys_filename, token_class=CoNLLUP_Token)
34
35 lemma_all_match, lemma_all_err, lemma_all_mistakes = 0, 0, []
36 lemma_all_symbols = []
37
38 for i, (s,g) in enumerate(zip(sys_generator, gld_generator)):
39 assert len(s.tokens) == len(g.tokens), "Token Mismatch!"
40 lemma_match, lemma_err, lemma_sym, mistakes = eval_lemma(s,g)
41 lemma_all_match += lemma_match
42 lemma_all_err += lemma_err
43 lemma_all_mistakes += mistakes
44 lemma_all_symbols += lemma_sym
45
46 print(f"Lemma Matches = {lemma_all_match} || Errors = {lemma_all_err} || Symbol Chars = {len(lemma_all_symbols)}")
47 print(f"Lemma Accuracy = {lemma_all_match*100/(lemma_all_match + lemma_all_err)}%")
48 lemma_miss_df = pd.DataFrame(lemma_all_mistakes, columns =['Gold_Word', 'Gold_Lemma', 'Sys_Lemma']).value_counts()
49 lemma_miss_df.to_csv(path_or_buf="LemmaErrors.tsv", sep="\t")
50
51#
52# the_count = Counter(lemma_all_mistakes).most_common(100)
53# for x in the_count:
54# print(x)
55
56