-
Notifications
You must be signed in to change notification settings - Fork 0
/
openscripturesmorph.py
326 lines (285 loc) · 10.5 KB
/
openscripturesmorph.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/local/bin/python3
class Morph:
data = {
"languages" : {
"Hebrew" : "H",
"Aramaic" : "A",
},
"partsofspeech" : {
"art" : "T", # article
"verb" : "V", # verb
"subs" : "N", # noun
"nmpr" : "N", # proper noun
"advb" : "D", # adverb
"prep" : "R", # preposition
"conj" : "C", # conjunction
"prps" : "P", # personal pronoun
"prde" : "P", # demonstrative pronoun
"prin" : "P", # interrogative pronoun
"intj" : "T", # interjection
"nega" : "T", # negative particle
"inrg" : "T", # interrogative particle
"adjv" : "A", # adjective
# "" : "S" # Suffix (WLC)
},
"lexical_set" : {
"nmdi" : "", # distributive noun
"nmcp" : "", # copulative noun
"padv" : "", # potential adverb
"afad" : "", # anaphoric adverb
"ppre" : "", # potential preposition
"cjad" : "", # conjunctive adverb
"ordn" : "", # ordinal
"vbcp" : "", # copulative verb
"mult" : "", # noun of multitude
"focp" : "", # focus particle
"ques" : "", # interrogative particle
"gntl" : "", # gentilic
"quot" : "", # quotation verb
"card" : "", # cardinal
"none" : "", # none
},
# From ETCBC lexical set
"adjective_types" : { # WLC Values
"ordn" : "a", # adjective
"card" : "c", # cardinal number
"gntl" : "g", # gentilic
# "" : "o", # ordinal number
},
# From ETCBC lexical set
"noun_types" : { # WLC Values
# "" : "c", # common
"gntl" : "g", # gentilic
# "" : "p", # proper name
},
"pronoun_types" : { # WLC Values
"prde" : "d", # demonstrative
# "" : "f", # indefinite
"prin" : "i", # interrogative
"prps" : "p", # personal
# "" : "r", # relative
},
"participle_types" : { # WLC Values
# "" : "a", # affirmation
"art" : "d", # definite article
# "" : "e", # exhortation
"inrg" : "i", # interrogative
"intj" : "j", # interjection
# "" : "m", # demonstrative
"nega" : "n", # negative
# "" : "o", # direct object marker
# "" : "r", # relative
},
"verb_stems_H" : { # WLC Values
"qal" : "q", # qal
"nif" : "N", # niphal
"piel" : "p", # piel
"pual" : "P", # pual
"hif" : "h", # hiphil
"hof" : "H", # hophal
"hit" : "t", # hithpael
# "" : "o", # polel
# "" : "O", # polal
# "" : "r", # hithpolel
# "" : "m", # poel
# "" : "M", # poal
# "" : "k", # palel
# "" : "K", # pulal
# "" : "Q", # qal passive
# "" : "l", # pilpel
# "" : "L", # polpal
# "" : "f", # hithpalpel
# "" : "D", # nithpael
# "" : "j", # pealal
# "" : "i", # pilel
# "" : "u", # hothpaal
# "" : "c", # tiphil
# "" : "v", # hishtaphel
# "" : "w", # nithpalel
# "" : "y", # nithpoel
# "" : "z", # hithpoel
},
"verb_stems_A" : {
"afel" : "a", # af'el
"etpa" : "", # etpa'"al
"etpe" : "", # etpe'el
"haf" : "h", # haf'el
"hop" : "", # hotpa'"al
"hsht" : "", # hishtaf'al
"htpa" : "", # hitpa'"al
"htpe" : "", # hitpe'el
"nit" : "", # nitpa'"el
"pael" : "p", # pa'"el
"peal" : "q", # pe'al
"peil" : "Q", # pe'il
"shaf" : "e", # shaf'el
"tif" : "c", # tif'al
"pasq" : "", # passiveqal
# WLC Values
# "peal" : "q", # peal
# "peil" : "Q", # peil
# # "" : "u", # hithpeel
# "pael" : "p", # pael
# # "" : "P", # ithpaal
# # "" : "M", # hithpaal
# "afel" : "a", # aphel
# "haf" : "h", # haphel
# # "" : "s", # saphel
# "shaf" : "e", # shaphel
# # "" : "H", # hophal
# # "" : "i", # ithpeel
# # "" : "t", # hishtaphel
# # "" : "v", # ishtaphel
# # "" : "w", # hithaphel
# # "" : "o", # polel
# # "" : "z", # ithpoel
# # "" : "r", # hithpolel
# # "" : "f", # hithpalpel
# # "" : "b", # hephal
# "tif" : "c", # tiphel
# # "" : "m", # poel
# # "" : "l", # palpel
# # "" : "L", # ithpalpel
# # "" : "O", # ithpolel
# # "" : "G", # ittaphal
},
"verse_tenses" : {
"perf" : "p", # perfect
"impf" : "i", # imperfect
"wayq" : "w", # wayyiqtol
"impv" : "v", # imperative
"infa" : "a", # infinitive (absolute)
"infc" : "c", # infinitive (construct)
"ptca" : "r", # participle
"ptcp" : "s", # participle (passive)
# WLC Values
# "perf" : "p", # perfect (qatal)
# # "" : "q", # sequential perfect (weqatal)
# "impf" : "i", # imperfect (yiqtol)
# "wayq" : "w", # sequential imperfect (wayyiqtol)
# # "" : "h", # cohortative
# # "" : "j", # jussive
# "impv" : "v", # imperative
# "ptca" : "r", # participle active
# "ptcp" : "s", # participle passive
# "infa" : "a", # infinitive absolute
# "infc" : "c", # infinitive construct
},
"suffix" : { # WLC Values
# "" : "d", # directional he
# "" : "h", # paragogic he
# "" : "n", # paragogic nun
# "" : "p", # pronominal
},
"persons" : {
"p1" : "1",
"p2" : "2",
"p3" : "3",
},
"genders" : {
"m" : "m",
"f" : "f",
},
"numbers" : {
"sg" : "s",
"du" : "d",
"pl" : "p",
},
"states" : {
"a" : "a", # absolute
"c" : "c", # construct
# "e" : "", # emphatic
},
}
def __init__(self, words):
self.words = words
return
def output(self):
morph = ''
morph += self.data['languages'][self.words[0]['language']] # Language
for index, word in enumerate(self.words):
# This is the last word
if (index+1) == len(self.words):
if word['part_of_speech'] == 'art' and len(word['word']) == 0:
# This is an article and it's blank, so we need to modify the preposition
index = morph.find('/')
morph = morph[:index] + 'd' + morph[index:]
continue
if index > 0:
morph += '/'
partofspeech = self.data['partsofspeech'][word['part_of_speech']]
if partofspeech == 'N':
type = word['lexical_set']
if type == 'padv' or type == 'afad' or type == 'cjad':
# This is actually an adverb!
partofspeech = 'D'
morph += partofspeech
morph += self.assemble_partofspeech(partofspeech, word)
return morph
def assemble_partofspeech(self, partofspeech, word):
output = ''
try:
func = getattr(self, 'assemble_' + partofspeech)
except AttributeError:
print('function not found "%s" (%s)' % ('assemble_' + partofspeech, word))
else:
output = func(word)
return output
# Adjective
def assemble_A(self, word):
type = self.val('adjective_types', word['lexical_set'])
gender = self.val('genders', word['gender'])
number = self.val('numbers', word['number'])
state = self.val('states', word['state'])
return type + gender + number + state
# Conjunction
def assemble_C(self, word):
return ''
# Adverb
def assemble_D(self, word):
return ''
# Noun
def assemble_N(self, word):
type = self.val('noun_types', word['lexical_set'])
gender = self.val('genders', word['gender'])
number = self.val('numbers', word['number'])
state = self.val('states', word['state'])
if type == '?' and word['part_of_speech'] == 'nmpr':
# Proper noun
type = 'p'
gender = ''
number = ''
state = ''
elif type == '?':
# Common noun
type = 'c'
return type + gender + number + state
# Pronoun
def assemble_P(self, word):
type = self.val('pronoun_types', word['part_of_speech'])
person = self.val('persons', word['person'])
gender = self.val('genders', word['gender'])
number = self.val('numbers', word['number'])
return type + person + gender + number
# Preposition
def assemble_R(self, word):
return ''
# Participle
def assemble_T(self, word):
type = self.val('participle_types', word['part_of_speech'])
return type
# Verb
def assemble_V(self, word):
stem = self.val('verb_stems_' + self.data['languages'][word['language']], word['stem'])
tense = self.val('verse_tenses', word['tense'])
person = self.val('persons', word['person'])
gender = self.val('genders', word['gender'])
number = self.val('numbers', word['number'])
state = self.val('states', word['state'])
if state == '?':
state = '' # No state on this verb
return stem + tense + person + gender + number + state
def val(self, var, val):
output = ''
output += self.data[var][val] if val in self.data[var] and self.data[var][val] else '?'
return output