-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutilities.py
84 lines (65 loc) · 3.24 KB
/
utilities.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
#==============================================================================================
# The Jabalín morphological generator for Arabic verbs
#
# Copyright (c) 2012 Susana López Hervás, Alicia González Martínez, Antonio Moreno Sandoval
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#==============================================================================================
###################################################################
# MODULE UTILITIES
###################################################################
import re
import sys
# This function inverts a string
def invertir(var):
return var[::-1]
# This function returns 'true' if the line passed as a parameter begins with the word 'ENTRY'
# or if it's an empty line, else return 'false'
def delete_line(line):
if re.match("ENTRY(.+)", line):
return (True)
if re.match("^\n", line):
return(True)
return(False)
# This function gets a code and returns a dictionary with its decodification
# or empty dictionary if something worked wrong
# i.e. {'Vocalization': {'Perf V2': '0', 'Imperf V2': '0', 'Imperf V1': '0'},
# 'Internal derivation': {'lengthening': '1', 'addition': '0'},
# 'Template': 'H',
# 'External derivation': '0'}
def parse_code_verbs(code):
if len(code)!=7:
print("error CODE: " + code)
return ()
dict_parse={}
dict_parse["Internal derivation"]={'lengthening': code[0], 'addition': code[1]}
dict_parse["Template"]=code[2]
dict_parse["External derivation"]=code[3]
dict_parse["Vocalization"]={'Perf V2': code[4], 'Imperf V1': code[5], 'Imperf V2': code[6]}
return(dict_parse)
def printFile_forms(lema, root, code, dict_forms, n_file):
k_forms = dict_forms.keys()
for k in k_forms:
print(dict_forms[k] + '\t'+ k + '\t' + str(lema) + '\t'+\
str(root)+'\t'+ str(code), file=n_file)
def printFile_forms_from_dictForms(lema, root, code, d_forms, n_file):
printFile_forms(lema, root, code, d_forms['VP']['Active'], n_file)
printFile_forms(lema, root, code, d_forms['VP']['Pasive'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Active']['Indicative'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Active']['Subjunctive'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Active']['Yusive'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Pasive']['Indicative'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Pasive']['Subjunctive'], n_file)
printFile_forms(lema, root, code, d_forms['VI']['Pasive']['Yusive'], n_file)
printFile_forms(lema, root, code, d_forms['VIAM'], n_file)