-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
travis_test.py
257 lines (215 loc) · 10.4 KB
/
travis_test.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#encoding: utf-8
import unittest
from uralicNLP import uralicApi
if not uralicApi.is_language_installed("fin"):
uralicApi.download("fin",show_progress=False)
from syntaxmaker.syntax_maker import *
import codecs
import copy
class TestFSTS(unittest.TestCase):
def setUp(self):
vp = create_verb_pharse("uneksia")
subject = create_phrase("NP", "rantaleijona", {u"PERS": "3", u"NUM": "PL"})
dobject = create_phrase("NP", "aalto", {u"PERS": "3", u"NUM": "PL"})
dobject.components["attribute"] = create_phrase("AP", "korkea")
dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin")
vp.components["subject"] = subject
vp.components["dir_object"] = dobject
self.vp = vp
def test_sentence(self):
vp = copy.deepcopy(self.vp)
self.assertEqual(str(vp) , "rantaleijonat uneksivat erittäin korkeista aalloista")
def test_sentence_pass(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_passive(vp)
self.assertEqual(str(vp) , "uneksitaan erittäin korkeista aalloista")
def test_sentence_neg(self):
vp = copy.deepcopy(self.vp)
negate_verb_pharse(vp)
self.assertEqual(str(vp) , "rantaleijonat eivät uneksi erittäin korkeista aalloista")
def test_prefect(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
self.assertEqual(str(vp) , "rantaleijonat ovat uneksineet erittäin korkeista aalloista")
def test_prefect_pass(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
turn_vp_into_passive(vp)
self.assertEqual(str(vp) , "on uneksittu erittäin korkeista aalloista")
def test_prefect_pass_cond(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
turn_vp_into_passive(vp)
set_vp_mood_and_tense(vp, mood="COND")
self.assertEqual(str(vp) , "olisi uneksittu erittäin korkeista aalloista")
def test_prefect_pass_pot(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
turn_vp_into_passive(vp)
set_vp_mood_and_tense(vp, mood="POTN")
self.assertEqual(str(vp) , "lie uneksittu erittäin korkeista aalloista")
def test_pot(self):
vp = copy.deepcopy(self.vp)
set_vp_mood_and_tense(vp, mood="POTN")
self.assertEqual(str(vp) , "rantaleijonat uneksinevat erittäin korkeista aalloista")
def test_total_plural(self):
vp = create_verb_pharse("antaa")
subject = create_phrase("NP", "hevonen", {"NUM": "PL"})
dobject = create_phrase("NP", "lahja", {"NUM": "PL"})
dobject.components["attribute"] = create_phrase("AP", "hyvä")
dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin")
indobject = create_phrase("NP", "lehmä")
vp.components["subject"] = subject
vp.components["dir_object"] = dobject
vp.components["indir_object"] = indobject
self.assertEqual(str(vp) , "hevoset antavat erittäin hyviä lahjoja lehmälle")
def test_total_plural_neg(self):
vp = create_verb_pharse("antaa")
subject = create_phrase("NP", "hevonen", {"NUM": "PL"})
dobject = create_phrase("NP", "lahja", {"NUM": "PL"})
dobject.components["attribute"] = create_phrase("AP", "hyvä")
dobject.components["attribute"].components["attribute"] = create_phrase("AdvP", "erittäin")
indobject = create_phrase("NP", "lehmä")
vp.components["subject"] = subject
vp.components["dir_object"] = dobject
vp.components["indir_object"] = indobject
negate_verb_pharse(vp)
self.assertEqual(str(vp) , "hevoset eivät anna erittäin hyviä lahjoja lehmälle")
def test_adj(self):
ap = create_adjective_phrase("kaunis", degree="Comp")
self.assertEqual(str(ap), "kauniimpi")
def test_cond(self):
vp = copy.deepcopy(self.vp)
set_vp_mood_and_tense(vp, mood="COND")
self.assertEqual(str(vp) , "rantaleijonat uneksisivat erittäin korkeista aalloista")
def test_imp(self):
vp = copy.deepcopy(self.vp)
set_vp_mood_and_tense(vp, mood="IMPRT")
self.assertEqual(str(vp) , "rantaleijonat uneksikoot erittäin korkeista aalloista")
def test_quest(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_question(vp)
self.assertEqual(str(vp) , "uneksivatko rantaleijonat erittäin korkeista aalloista")
def test_rela(self):
np1 = create_phrase("NP", "mies")
relp = create_verb_pharse("katsoa")
ppp = create_phrase("NP", "orava")
relpp = create_verb_pharse("vaania")
relpp.components["subject"] = create_phrase("NP", "kissa")
add_relative_clause_to_np(ppp, relpp)
relp.components["subject"] = ppp
add_relative_clause_to_np(np1,relp)
vep = create_verb_pharse("juosta")
vep.components["subject"] = np1
np2 = create_phrase("NP", "silta")
pp = create_adposition_phrase("alla", np2)
add_advlp_to_vp(vep, pp)
self.assertEqual(str(vep) , "mies, jota orava, jota kissa vaanii, katsoo, juoksee sillan alla")
def test_copula_pl(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"NUM": "PL"})
predicative = create_phrase("NP", "eläin")
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koirat ovat eläimiä")
def test_copula_sg(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koira on eläin")
def test_adpos(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
adp = create_adposition_phrase("ilman", predicative)
vp.components["subject"] = subject
add_advlp_to_vp(vp, adp)
self.assertEqual(str(vp) , "koira on ilman eläintä")
def test_place_name(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "Venäjä")
vp.components["subject"] = subject
add_advlp_to_vp(vp, predicative, place_type="in")
self.assertEqual(str(vp) , "koira on Venäjällä")
def test_possessive_name(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "Lontoo")
add_possessive_to_np(predicative, "1", "SG")
vp.components["subject"] = subject
add_advlp_to_vp(vp, predicative, place_type="in")
self.assertEqual(str(vp) , "koira on minun Lontoossani")
def test_pp_acc(self):
vp = create_verb_pharse("nähdä")
add_np_subject_to_vp(vp, create_noun_phrase("hattu"))
add_np_object_to_vp(vp, create_personal_pronoun_phrase("1", "SG"))
self.assertEqual(str(vp) , "hattu näkee minut")
def test_neg(self):
vp = create_verb_pharse("nähdä")
add_np_subject_to_vp(vp, create_personal_pronoun_phrase("1", "SG"))
add_np_object_to_vp(vp, create_personal_pronoun_phrase("2", "SG"))
negate_verb_pharse(vp)
turn_vp_into_question(vp)
self.assertEqual(str(vp) , "enkö minä näe sinua")
def test_prefect_last_pass(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
turn_vp_into_passive(vp)
set_vp_mood_and_tense(vp, tense="PAST")
self.assertEqual(str(vp) , "oli uneksittu erittäin korkeista aalloista")
def test_prefect_last_pass_neg(self):
vp = copy.deepcopy(self.vp)
turn_vp_into_prefect(vp)
turn_vp_into_passive(vp)
set_vp_mood_and_tense(vp, tense="PAST")
negate_verb_pharse(vp)
self.assertEqual(str(vp) , "ei oltu uneksittu erittäin korkeista aalloista")
def test_sentence_can(self):
vp = copy.deepcopy(self.vp)
add_auxiliary_verb_to_vp(vp, "voida")
self.assertEqual(str(vp) , "rantaleijonat voivat uneksia erittäin korkeista aalloista")
def test_sentence_stay(self):
vp = copy.deepcopy(self.vp)
add_auxiliary_verb_to_vp(vp, "jäädä")
self.assertEqual(str(vp) , "rantaleijonat jäävät uneksimaan erittäin korkeista aalloista")
def test_adj_comp(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
adj = create_adjective_phrase("hieno", degree="Comp")
predicative.components["attribute"] = adj
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koira on hienompi eläin")
def test_adj_superl(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
adj = create_adjective_phrase("hieno", degree="Superl")
predicative.components["attribute"] = adj
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koira on hienoin eläin")
def test_adv_superl(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
adj = create_adverb_phrase("yleinen", degree="Superl")
predicative.components["attribute"] = adj
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koira on yleisimmin eläin")
def test_adv_comp(self):
vp = create_copula_phrase()
subject = create_phrase("NP", "koira", {u"PERS": "3", u"NUM": "SG"})
predicative = create_phrase("NP", "eläin")
adj = create_adverb_phrase("yleinen", degree="Comp")
predicative.components["attribute"] = adj
vp.components["subject"] = subject
vp.components["predicative"] = predicative
self.assertEqual(str(vp) , "koira on yleisemmin eläin")
if __name__ == '__main__':
unittest.main()