forked from aitalvivem/AitalvivemBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (52 loc) · 1.87 KB
/
main.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
#-*-coding:utf-8-*
import csv
import pywikibot
import functionsmain.APIfunction
# I set the path of the .csv file with the lexicographical data and get the file
fname = # PATH
file = open(fname, 'rt', encoding='utf-8')
# I take the files datas using csv.reader and store it in 'lecteur'
try:
lecteur = csv.reader(file, delimiter=";")
for row in lecteur:
lg = { 'libLg': row[0], 'codeLg': row[1], 'dial': row[7] }
form = row[2]
catGram = row[3]
lemme = row[4]
catGramL = row[5]
catLex = row[6]
# I get the id of the lexeme (if the lexeme don't exists, i create it) and then i get the data of the lexeme
idLex = functionsmain.APIfunction.chercheLex(lemme, lg, catLex, catGram)
infoLex = functionsmain.APIfunction.getLex(idLex)
# I get the grammaticals category of the form
catGramW = functionsmain.APIfunction.detailCat(catGram)
formExists = False
formeMatch = []
# I check if the form already exists
for formes in infoLex['formes']:
if form == formes['representation']:
formExists = True
formeMatch += [formes]
if formExists == True:
memeCat = False
for forme in formeMatch:
if catGramW == forme['catGram']:
memeCat = True
formeMatch = forme
break
# if the form exists with the same grammatical category I check the dialect, if the dialecte don't exists I add it to the form
if memeCat == True:
if lg['dial'] != '':
idDial = lg['dial']
if idDial not in formeMatch['dialectes']:
functionsmain.APIfunction.setDial(formeMatch['idForm'], lg)
else:
# else I create a new form
functionsmain.APIfunction.createForm(idLex, form, catGram, lg)
# else I create a new form
else:
if form != lemme:
functionsmain.APIfunction.createForm(idLex, form, catGram, lg)
finally:
# close the file
file.close()