-
Notifications
You must be signed in to change notification settings - Fork 0
/
glossary.py
187 lines (167 loc) · 4.47 KB
/
glossary.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
from pprint import pprint
import re
esperanto_uppercase = 'ABCĈDEFGĜHĤIJĴKLMNOPRSŜTUŬVZ'
esperanto_lowercase = 'abcĉdefgĝhĥijĵklmnoprsŝtuŭvz'
esperanto_letters = esperanto_uppercase + esperanto_lowercase
# string.ascii_letters
# string.ascii_lowercase
# string.ascii_uppercase¶
# v.
# v.tr
# v.ntr
# n.
# adj.
# adv.
# int.
# prep.
# corr. | table-word
glossary = []
class Entry:
english = ""
esperanto = ""
comment = ""
phrase = False
noun = False
verb = False
adverb = False
ajective = False
def __str__(self):
return self.english + ", " + self.esperanto + ": " + self.comment[:20]
def is_table_word(g):
s = g.esperanto
if g.comment.startswith('corr.'):
return(True)
else:
return(False)
def is_conjunction(g):
s = g.esperanto
if g.comment.startswith('conj.'):
return(True)
else:
return(False)
def is_noun(g):
s = g.esperanto
if s.endswith('o'):
return("noun")
elif s.endswith('ojn'):
return("noun_plural_accusative")
elif s.endswith('oj'):
return("noun_plural")
elif s.endswith('on'):
return("noun_accusative")
elif g.comment.startswith('n.'):
return(True)
else:
return(False)
def is_adjective(g):
s = g.esperanto
if s.endswith('a'):
return("adjective")
elif s.endswith('ajn'):
return("adjective_plural_accusative")
elif s.endswith('aj'):
return("adjective_plural")
elif s.endswith('an'):
return("adjective_accusative")
elif g.comment.startswith('adj.'):
return(True)
else:
return(False)
def is_adverb(g):
s = g.esperanto
if s.endswith('e'):
return("adverb")
elif s.endswith('en'):
return("adverb_accusative")
elif g.comment.startswith('adv.'):
return(True)
else:
return(False)
def is_verb(g):
s = g.esperanto
if s.endswith('i'):
return("verb_infinitive")
if s.endswith('as'):
return("verb_present")
if s.endswith('is'):
return("verb_past")
if s.endswith('os'):
return("verb_future")
if s.endswith('u'):
return("verb_imperative")
if s.endswith('us'):
return("verb_conditional")
elif g.comment.startswith('v.'):
return(True)
else:
return(False)
def is_interjection(g):
s = g.esperanto
if g.comment.startswith('int.'):
return(True)
else:
return(False)
def is_preposition(g):
s = g.esperanto
if g.comment.startswith('prep.'):
return(True)
else:
return(False)
def is_multword(g):
s = g.esperanto
if ' ' in s:
return(True)
else:
return(False)
pattern_line = re.compile("^.+\t.+\t.+")
dup_check = ""
with open("raw.txt") as raw:
lines = raw.readlines()
for line in lines:
if "&&" in line:
continue
if not pattern_line.match(line):
print("Misformed: " + line)
if len(line.strip()) > 0:
entry = Entry()
try:
entry.english, entry.esperanto, entry.comment = line.split('\t')
except:
print("Misformed: " + line)
if "&" + entry.english + "&" + entry.esperanto + "&" in dup_check:
print("Duplicate: ", entry)
dup_check = dup_check + "&" + entry.english + "&" + entry.esperanto + "&"
glossary = glossary + [entry]
num_table_words, num_conjunctions, num_nouns, num_adjectives, num_adverbs, num_verbs, num_interjections, num_prepositions, num_multiword = 0,0,0,0,0,0,0,0,0
for g in glossary:
if is_table_word(g):
num_table_words += 1
elif is_conjunction(g):
num_conjunctions += 1
elif is_noun(g):
num_nouns += 1
elif is_adjective(g):
num_adjectives += 1
elif is_adverb(g):
num_adverbs += 1
elif is_verb(g):
num_verbs += 1
elif is_interjection(g):
num_interjections += 1
elif is_preposition(g):
num_prepositions += 1
elif is_multword(g):
num_multiword += 1
else:
# print(g)
pass
print(len(glossary) -
num_table_words -
num_conjunctions -
num_nouns -
num_adjectives -
num_adverbs -
num_verbs -
num_interjections -
num_prepositions -
num_multiword)