Commit 8f01c0b2 authored by Sylvain Coulange's avatar Sylvain Coulange 🌼
Browse files

optimisation checkWord test

parent 4cabfbfd
......@@ -83,7 +83,7 @@ def getLenDic(lang):
##### MISE EN MÉMOIRE DES DICTIONNAIRES (seulement les transcriptions+regions)
def makeWord2trans(alemDic):
query = alemDic.find()#.limit(10000)
query = alemDic.find().limit(10000)
word2trans = {}
cpt = 0
for q in query:
......@@ -200,6 +200,31 @@ with open(pinyin2zhuyinFile) as inFile:
pinyin2zhuyin = json.load(inFile)
########################################
######## CREATION DICTIONNAIRES ########
#### PHONO2ORTHOS (pour checkword) #####
########################################
def makePhono2orthos(dico):
phono2orthos = {}
for w,x in dico.items():
for xt in x['t']:
tt = xt['tt']
if tt not in phono2orthos.keys():
phono2orthos[tt] = []
if w not in phono2orthos[tt]:
phono2orthos[tt].append(w)
return phono2orthos
print("Génération des dictionnaires phono2orthos pour checkword()...")
print("phono2orthosFr...")
phono2orthosFr = makePhono2orthos(word2transFr)
print("phono2orthosEn...")
phono2orthosEn = makePhono2orthos(word2transEn)
print("phono2orthosZh...")
phono2orthosZh = makePhono2orthos(word2transZh)
print("OK.")
########################################
######### LISTE DES FONCTIONS ##########
########################################
......@@ -430,11 +455,14 @@ def checkIfWordExists(w,t,lang='fr'):
# Pour le Phonographe, renvoie objet : 'w':True si mot existe, 't':True si transcription existe, 'wt':True si ce mot avec cette trans existe
if lang == "fr":
dico = word2transFr
phono2ortho = phono2orthosFr
elif lang == "en":
w = w.replace('’',"'")
dico = word2transEn
phono2ortho = phono2orthosEn
elif lang == "zh":
dico = word2transZh
phono2ortho = phono2orthosZh
w = w.lower()
res= {
......@@ -443,32 +471,40 @@ def checkIfWordExists(w,t,lang='fr'):
'wt':False
}
if len(w)>0 and len(t)>0:
for mot,transs in dico.items():
if mot == w:
res['w']=True;
for trans in transs['t']:
if trans['tt'] == t:
res['wt']=True
res['t']=True
break
for trans in transs['t']:
if trans['tt'] == t:
res['t']=True
if res['w']: break
if len(w)>0 and w in dico.keys():
res['w'] = True
if len(t)>0 and t in phono2ortho.keys():
res['t'] = True
if len(w)>0 and w in t:
res['wt'] = True
# if len(w)>0 and len(t)>0:
# for mot,transs in dico.items():
# if mot == w:
# res['w']=True;
# for trans in transs['t']:
# if trans['tt'] == t:
# res['wt']=True
# res['t']=True
# break
# for trans in transs['t']:
# if trans['tt'] == t:
# res['t']=True
# if res['w']: break
if len(w)==0 and len(t)>0:
for mot,transs in dico.items():
for trans in transs['t']:
if trans['tt'] == t:
res['t']=True
break
if len(w)>0 and len(t)==0:
for mot,transs in dico.items():
if mot == w:
res['w']=True;
break
# if len(w)==0 and len(t)>0:
# for mot,transs in dico.items():
# for trans in transs['t']:
# if trans['tt'] == t:
# res['t']=True
# break
# if len(w)>0 and len(t)==0:
# for mot,transs in dico.items():
# if mot == w:
# res['w']=True;
# break
return res
......@@ -477,39 +513,65 @@ def modifEntry(user,mot,infos,lang):
if lang == "fr":
word2trans = word2transFr
dico = dicoFr
phono2ortho = phono2orthosFr
if lang == "en":
word2trans = word2transEn
dico = dicoEn
phono2ortho = phono2orthosEn
if lang == "zh":
word2trans = word2transZh
dico = dicoZh
phono2ortho = phono2orthosZh
oldInfos = dico.find_one({'w':mot})
dico.update({"w":mot}, {"$set": infos})
word2trans[mot]['t'] = []
newTranss = []
for x in infos['t']:
word2trans[mot]['t'].append({'tt':x['tt'].replace('.',''), 'tr':x['tr']})
# mise à jour de phono2ortho (1)
# ajout de phono si n'existe pas encore
if x['tt'].replace('.','') not in phono2ortho.keys():
phono2ortho[x['tt'].replace('.','')] = [ mot ]
# liste des transs pour identification des transs potentiellement supprimées
newTranss.append(x['tt'])
# mise à jour de phono2ortho (2)
# suppression du mot pour la phono correspondante si phono modifiée ou supprimée
for x in oldInfos['t']:
if x['tt'].replace('.','') not in newTranss:
# dans ce cas x['tt'] a été supprimée (ou modifiée), il faut donc la supprimer de phono2ortho
if x['tt'].replace('.','') in phono2ortho.keys() and mot in phono2ortho[x['tt'].replace('.','')]:
phono2ortho[x['tt'].replace('.','')].remove(mot)
if len(phono2ortho[x['tt'].replace('.','')])==0:
phono2ortho.pop(x['tt'].replace('.',''), None)
newlog = writeLog(Type="MODIF", user=user, mot=mot, oldMot=oldInfos, newMot=infos, lang=lang)
print("Modification du dictionnaire par",user,": lang =",lang,"; mot =",mot,"; oldMot =",oldInfos,"; newMot =",infos)
print("Newlog:",newlog)
return {"msg":"Modification effectuée avec succès !", "newlog":newlog}
def addEntry(user,mot,trans,lang):
if lang == "fr":
word2trans = word2transFr
dico = dicoFr
trans = trans.replace('g','ɡ')
trans = trans.replace('r','ʁ')
phono2ortho = phono2orthosFr
if lang == "en":
word2trans = word2transEn
dico = dicoEn
trans = trans.replace('g','ɡ')
phono2ortho = phono2orthosEn
if lang == "zh":
word2trans = word2transZh
dico = dicoZh
phono2ortho = phono2orthosZh
mot = mot.lower()
mot = mot.strip()
......@@ -518,6 +580,7 @@ def addEntry(user,mot,trans,lang):
for ind,i in enumerate(transList):
transList[ind] = i.strip()
# update du dictionnaire en mémoire
if mot not in word2trans.keys():
newMot = {'t': []}
for t in transList:
......@@ -532,6 +595,14 @@ def addEntry(user,mot,trans,lang):
if len(newMot['t'])>0:
word2trans[mot] = newMot
dico.insert_one({ 'w':mot, 't':newMot['t']})
# Ajout de la phono dans phono2ortho
for i in transList:
if i not in phono2ortho.keys():
phono2ortho[i] = [ mot ]
elif mot not in phono2ortho[i]:
phono2ortho[i].append(mot)
newlog = writeLog(Type="ADD", user=user, mot=mot, oldMot="", newMot=transList, lang=lang)
return {"msg":"Ajout effectué avec succès ! Merci pour votre participation !", "newlog":newlog}
else:
......@@ -543,17 +614,28 @@ def delEntry(user,mot,lang):
if lang == "fr":
word2trans = word2transFr
dico = dicoFr
phono2ortho = phono2orthosFr
if lang == "en":
word2trans = word2transEn
dico = dicoEn
phono2ortho = phono2orthosEn
if lang == "zh":
word2trans = word2transZh
dico = dicoZh
phono2ortho = phono2orthosZh
if mot in word2trans.keys():
# Suppression de la phono dans phono2ortho
for x in word2trans[mot]['t']:
if x['tt'].replace('.','') in phono2ortho.keys() and mot in phono2ortho[x['tt'].replace('.','')]:
phono2ortho[x['tt'].replace('.','')].remove(mot)
if len(phono2ortho[x['tt'].replace('.','')])==0:
phono2ortho.pop(x['tt'].replace('.',''), None)
oldmot = word2trans[mot]
word2trans.pop(mot)
dico.delete_one({'w':mot})
newlog = writeLog(Type="DEL", user=user, mot=mot, oldMot=oldmot, newMot="",lang=lang)
print("Modification du dictionnaire par",user,": suppression de mot =",mot)
......
/* CSS ALeM-APP v4 */
/* https://alem.hypotheses.org/ */
/* Last update: 2022/10/04 */
/* Last update: 2022/11/06 */
:root {
--bicolor1: #ff0000;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment