-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.py
99 lines (89 loc) · 3.01 KB
/
go.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
import csv
import re
def isInitialVowel(s):
return (len(s)>0 and s[0].lower() in 'aeiouáéíóúàèìòù')
def isLenitableS(s):
return len(s)>1 and s[0] in 'sS' and (s[1].lower() in 'lnr' or isInitialVowel(s[1]))
def isLenitable(s):
return isLenitableS(s) or (len(s)>0 and s[0].lower() in 'bcdfgmpt')
def addWord(d,w,flags=None):
if w not in d:
d[w] = set()
if flags:
for f in flags:
d[w].add(f)
def addWords(checker, gocOnly, tostrip):
with open('vspellcheckerexport.csv', newline='', encoding="utf8") as csvfile:
freader = csv.reader(csvfile, delimiter=',', quotechar='"')
next(freader, None) # skip header row
for row in freader:
bristeacha = row[2]
aicme = row[4]
roinn = row[5]
wordlist = row[1] if gocOnly else row[3]
wordInRow = 0
for w in wordlist.split(', '):
if ' ' in w or roinn=='NULL' or aicme=='':
for x in w.split():
addWord(checker,x.rstrip('!.,;)'))
elif w=='':
pass
elif w in tostrip:
pass
else:
w = w.rstrip('.') # add abbreviations without .
addWord(checker,w)
if roinn=='noun' and aicme!='rio.':
if aicme=='boir.' or aicme=='fir.':
addWord(checker,w,'K')
if re.match('^ainm',aicme) and (isInitialVowel(w) or w[0].lower()=='f'):
addWord(checker,w,'E')
elif isInitialVowel(w):
addWord(checker,w,'DEHKN')
if aicme=='fir.':
addWord(checker,w,'T')
elif isLenitableS(w): # masc and fem?
addWord(checker,w,'T')
elif w[0].lower()=='f':
addWord(checker,w,'DE')
elif roinn=='verb':
if w[-3:]=='inn':
addWord(checker,w+'-sa')
elif w[-5:]=='amaid':
addWord(checker,w+'-ne')
elif roinn=='adjective':
if wordInRow==0 and isInitialVowel(w):
addWord(checker,w,'GK')
else:
addWord(checker,w,'K')
wordInRow += 1
csvfile.close()
def writeDict(checker, filename):
output = open(filename, 'w', encoding="utf8")
output.write(str(len(goc.keys()))+'\n')
for w in sorted(goc):
flaglist = list(goc[w])
flaglist.sort()
flags = ''.join(flaglist)
if flags:
output.write(w+'/'+flags+'\n')
else:
output.write(w+'\n')
output.close()
striplist=set()
with open('striplist.txt', newline='', encoding="utf8") as stripfile:
for line in stripfile:
striplist.add(line.rstrip('\n'))
goc = dict()
with open('propernouns.txt', newline='', encoding="utf8") as prop:
for line in prop:
if '.' not in line and '/' not in line:
addWord(goc,line.rstrip('\n'))
with open('semigaelic.txt', newline='', encoding="utf8") as prop:
for line in prop:
if '.' not in line and '/' not in line:
addWord(goc,line.rstrip('\n'))
addWords(goc, True, striplist)
writeDict(goc, 'gd_GB.dic')
addWords(goc, False, striplist)
writeDict(goc, 'gd_GB_2.dic')