-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_checker.py
170 lines (149 loc) · 6.74 KB
/
test_checker.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import unittest
from gd_tools.acainn import Morphology
from checker import Checker
import numpy as np
class Test(unittest.TestCase):
def setUp(self):
self.c = Checker()
self.l = Morphology()
def tearDown(self):
self.c = None
self.l = None
def check(self, goodtokens, badtokens, code):
goodresult = self.c._check(goodtokens)
goodlist = [list(filter(None, t.split(','))) for t in goodresult.code.tolist()]
flat_good = [item for sublist in goodlist for item in sublist]
badresult = self.c._check(badtokens)
badlist = [list(filter(None, t.split(','))) for t in badresult.code.tolist()]
flat_bad = [item for sublist in badlist for item in sublist]
self.assertFalse(code in flat_good)
self.assertTrue(code in flat_bad)
# this is for cases where we have a list of single tokens
def check_every(self, goodtokens, badtokens, code):
goodresult = [''.join(t.split(',')) for t in self.c._check(goodtokens).code.tolist()]
for i,result_code in enumerate(goodresult):
self.assertNotEqual(result_code, code, msg = goodtokens[i])
badresult = [''.join(t.split(',')) for t in self.c._check(badtokens).code.tolist()]
for i,result_code in enumerate(badresult):
self.assertEqual(result_code, code, msg = badtokens[i])
def test_lenition(self):
self.assertTrue(self.l.lenited("stad"))
goodtokens = [("ma","Cs"), ("thomhaiseas","V-f--r")]
badtokens = [("ma","Cs"), ("tomhaiseas","V-f--r")]
self.check(goodtokens, badtokens, "45iealpha")
goodtokens = [("a", "Q-r"), ("chòrdas","V-f--r")]
badtokens = [("a", "Q-r"), ("còrdas","V-f--r")]
self.check(goodtokens, badtokens, "45iealpha")
goodtokens = [("do", "Q--s"), ("chòrd","V-s")]
badtokens = [("do", "Q--s"), ("còrd","V-s")]
self.check(goodtokens, badtokens, "45iebeta")
goodtokens = [("an", "Tdsf"), ("dithis", "Ncsfn"), ("bheag", "Aq-sfn")]
badtokens = [("an", "Tdsf"), ("dithis", "Ncsfn"), ("beag", "Aq-smn")]
self.check(goodtokens, badtokens, "144ii")
goodtokens = [("dithis", "Ncsfn"), ("bhalach", "Ncsmg")]
badtokens = [("dithis", "Ncsfn"), ("balach", "Ncsmn")]
self.check(goodtokens, badtokens, "144iii")
goodtokens = [("Thug","V-s"), ("stad","V-s"), ("Bhiodh","V-h"), ("ruigeadh","V-h")]
badtokens = [("Tug","V-s"), ("faodadh", "V-h"), ("dèanadh","V-h")]
self.check_every(goodtokens, badtokens, "44iiia")
def test_speciallenition(self):
goodtokens = [("cha", "Qn"), ("ghabh", "V-f--d")]
badtokens = [("cha", "Qn"), ("gabh", "V-f--d")]
self.check(goodtokens, badtokens, "45iegamma")
def test_flenition(self):
goodtokens = [("An","Qq"), ("fhàs","V-f--d")]
badtokens = [("Am","Qq"), ("fàs","V-f--d")]
self.check(goodtokens, badtokens, "45iia")
# the test for this is not f-lenition but d-lenition. More complicated.
#goodtokens = [("Chan","Qn"), ("fhuirich","V-s--d")]
#badtokens = [("Cha","Qn"), ("do","Q--s"), ("dh'", "Uo"), ("fhuirich", "V-s--d")]
def test_nolenition(self):
goodtokens = [("tug","V-s--d"), ("stad","V-s--d"), ("biodh","V-h--d"), ("ruigeadh","V-h--d")]
badtokens = [("thug","V-s--d"), ("fhaodadh", "V-h--d"), ("dhèanadh","V-h--d")]
self.check_every(goodtokens, badtokens, "44iiia-")
def test_genitivenames(self):
good_f = [("Brìde","Nn-fg")]
bad_f = [("Bhrìde","Nn-fg")]
self.check(good_f, bad_f, "45iabeta-")
self.assertFalse("LENITE" in [t[2] for t in self.c._check ([("Aonghais","Nn-mg")])])
good_m = [("Dhòmhnaill","Nn-mg")]
bad_m = [("Dòmhnaill","Nn-mg")]
self.check(good_m, bad_m, "45iabeta")
def test_singilte(self):
good_iomadh = [("'S", "Wp-i"), ("iomadh","Ar"), ("rud","Ncsmn")]
bad_iomadh = [("'S", "Wp-i"), ("iomadh","Ar"), ("rudan","Ncpmn")]
self.check(good_iomadh, bad_iomadh, "173")
def test_barrachd(self):
good_tokens = [("barrachd", "Ncsfn"), ("fiosrachaidh", "Ncsmg")]
bad_tokens = [("barrachd", "Ncsfn"), ("fiosrachadh", "Ncsmn")]
self.check(good_tokens, bad_tokens, "170")
good_tokens = [("tuilleadh", "Ncsfn"), ("fiosrachaidh", "Ncsmg")]
bad_tokens = [("tuilleadh", "Ncsfn"), ("fiosrachadh", "Ncsmn")]
self.check(good_tokens, bad_tokens, "176")
def test_Ar(self):
badtokens = [("deagh", "Ar"), ("foghlam", "Ncsmn")]
goodtokens = [("deagh", "Ar"), ("fhoghlam", "Ncsmn")]
self.check(goodtokens, badtokens, "LENITE")
def test_hyphens(self):
text = '''Sann,Wp-i-x
ris,Sp
a',Tdsm
ghinealach,Ncsmd
againne,Pr1p--e
an diugh,Rt
a,Q-r
tha,V-p
e,Pp3sm
an,Sp
urra,Ncsmd
a,Ug
dhearbhadh,Nv
có,Uq
de'n,Spa-s
dithis,Ncsfn
a,Q-r
tha,V-p
ceàrr,Ap
:,Fi
's,Wp-i
neònach,Ap
mur,Cs
e,Pp3sm
seo,Pd
an,Tdsm
cothrom,Ncsmn
mu dheireadh,Aq
a,Q-r
gheibh,V-f
sinn,Pp1p
.,Fe'''
pairs = text.splitlines()
tokens = [(pair.split(',')[0],pair.split(',')[1]) for pair in pairs]
checked = [list(filter(None, t.split(','))) for t in self.c._check(tokens).code.tolist()]
self.assertEqual(checked[5], ['GOC-HYPHEN'])
def test_basic(self):
good_iomadh = [("'S", "Wp-i"), ("iomadh","Ar"), ("rud","Ncsmn")]
result = self.c._make_df(good_iomadh)
self.assertEqual(3, len(result))
def test_mo(self):
good = [("dhùin","V-s"),("mi","Pp1s"),("mo","Dp1s"),("shùilean","Ncpfn"),("san","Spa-s"),("deireadh","Ncsmd")]
result = self.c._check(good)
bad = [("dhùin","V-s"),("mi","Pp1s"),("mo","Dp1s"),("sùilean","Ncpfn"),("san","Spa-s"),("deireadh","Ncsmd")]
r2 = self.c._check(bad)
def test_feats(self):
good_iomadh = [("'S", "Wp-i"), ("iomadh","Ar"), ("rud","Ncsmn")]
result = self.c._feats(self.c._make_df(good_iomadh))
self.assertEqual(np.dtype(bool), np.dtype(result._lenited))
br = [("barrachd", "Ncsmn"), ("fiosrachaidh", "Ncsmg")]
r2 = self.c._feats(self.c._make_df(br))
self.assertEqual(np.dtype(bool), np.dtype(r2._genitive))
self.assertListEqual([False, True], r2._genitive.tolist())
self.assertListEqual([False, True], r2._genitivesing.tolist())
self.assertListEqual([True, True], r2._sing.tolist())
def test_checkerDfs(self):
self.assertEqual(np.dtype(object), np.dtype(self.c.lenitesp_1._p_1))
good_iomadh = [("'S", "Wp-i"), ("iomadh","Ar"), ("rud","Ncsmn")]
result = self.c._feats(self.c._make_df(good_iomadh))
merged = result.merge(self.c.lenitesp_1, on = ("_p_1","_lenited"), how="left")
if __name__ == '__main__':
unittest.main()