optimisation fichier long
Bonjour, avant d'expliquer mon pb,
je vous montre un exemple :
j'ai un fichier
<motA>1##2##3##4</motA>
<motB>1##4##8</motB>
<motC>5##8##10</motC>
<motD>35##32##10</motD>
<motE>52##81##102</motE>
je dois comparer
<motA> avec <motB>
<motA> avec <motC>
<motA> avec <motD>
<motB> avec <motC>
<motB> avec <motD>
<motC> avec <motD>
donc
Code:
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
|
f = openFile("mat1.log")
lp = f.readlines()
fg = openFile("mat1.log")
d = fg.readlines()
n=1
chaine=[]
countList={}
for i in lp:
listeA = re.findall('<.*?>(.*?)</.*?>',i)
element = re.findall('<(.*?)>',i)
chaine.append("<" + element[0] + ">")
for j in d[n:]:
listeB = re.findall('<.*?>(.*?)</.*?>',j) #recupère la liste entre les balises
elementj = re.findall('<(.*?)>',j)#récupère l'élement de la balise
diceValue = dice(creerListe(listeA[0]),creerListe(listeB[0]))
#creerListe qui transforme la chaine 5##8##10 en une liste de 3 élements
if diceValue > 0.0 and diceValue < 1.0:
countList[elementj[0]]=diceValue
lcountlist = countList.items()
lcountlist.sort(key=operator.itemgetter(1),reverse=True)
lcountlist = lcountlist[:m]
for alllist in range(len(lcountlist)):
if alllist != len(lcountlist) - 1:
chaine.append(lcountlist[alllist][0]+"##")
else:
chaine.append(lcountlist[alllist][0])
chaine.append("</" + element[0] + ">\n")
n+=1
cp+=1
f1 = open("matricecooccurrenceTest.log","w")
f1.writelines(chaine)
f1.writelines(chaineAutre)
f.close()
f1.close()
fg.close() |
le code est trop long je trouve.
c'est un très gros fichier,je sais pas si mon algo est optimale, mais là, j'ai lancé le fichier pendant 16h
et il n'a meme pas traité 50000 mots.
il y a au total 150000 mots (lignes) à traiter.