-
Notifications
You must be signed in to change notification settings - Fork 17
/
morphotag_eval_unittest.py
35 lines (28 loc) · 1.08 KB
/
morphotag_eval_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''
Created on Nov 30, 2016
@author: Yuval Pinter
'''
from __future__ import division
import unittest
from evaluate_morphotags import Evaluator
from utils import split_tagstring
from numpy.testing.utils import assert_almost_equal
class Test(unittest.TestCase):
def testEval(self):
eval1 = Evaluator(m = 'att')
eval2 = Evaluator(m = 'att_val')
eval3 = Evaluator(m = 'exact')
with open('simple_morpho_eval_test.txt', 'r') as sample_file:
for l in sample_file.readlines():
if not l.startswith('#'):
g, o = map(split_tagstring, l.split('\t'))
eval1.add_instance(g, o)
eval2.add_instance(g, o)
eval3.add_instance(g, o)
assert_almost_equal(eval1.mic_f1(), 5/9)
assert_almost_equal(eval1.mac_f1(), 13/30)
assert_almost_equal(eval2.mic_f1(), 5/9)
assert_almost_equal(eval2.mac_f1(), 29/70)
assert_almost_equal(eval3.acc(), 1/4)
if __name__ == "__main__":
unittest.main()