1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
13 #------------------------------------
14 # import des modules wx
15 #------------------------------------
17 #------------------------------------
18 # import des fichiers du projet
19 #------------------------------------
20 from functions import DoConf, read_chd, ReadProfileAsDico
21 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath
22 from layout import SimiLayout
23 from textsimi import *
24 from analyse_merge import AnalyseMerge
27 class MergeClusterGraph :
29 def __init__(self, ira, corpus, parametres) :
32 self.parametres = parametres
33 self.pathout = PathOut(parametres['ira'])
34 self.pathout.basefiles(ChdTxtPathOut)
35 self.corpus.make_ucecl_from_R(self.pathout['uce'])
36 self.encoding = self.parametres['encoding']
37 self.clnb = parametres['clnb']
38 dictprofile = ReadProfileAsDico(self.pathout['PROFILE_OUT'], True, self.encoding)
39 self.dograph(dictprofile)
41 def dograph(self, dictprofile) :
43 #OUTCH!!First cluster removed !!
44 #print 'ELMINATION CLUSTER 1'
45 for i in range(0, self.clnb):
46 self.pathout = PathOut(self.parametres['ira'])
47 simiparam = DoConf(self.ira.ConfigPath['simitxt']).getoptions()
48 simiparam['coeff'] = 3
49 simiparam['cexfromchi'] = True
50 profclasse = dictprofile[repr(i+1)]
51 line1 = profclasse.pop(0)
52 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
54 self.lenact = profclasse.index(['*****', '*', '*', '*', '*', '*', '', ''])
55 profclasse.pop(self.lenact)
58 self.lenact = profclasse.index(['*', '*', '*', '*', '*', '*', '', ''])
59 profclasse.pop(self.lenact)
61 self.lenact = len(profclasse)
63 self.lensup = profclasse.index(['*', '*', '*', '*', '*', '*', '', ''])
64 self.lensup = self.lensup - self.lenact
65 profclasse.pop(self.lensup)
67 self.lensup = len(profclasse) - self.lenact
68 self.lenet = len(profclasse) - (self.lenact + self.lensup)
69 # print self.lenact, self.lensup, self.lenet
70 for l, line in enumerate(classen) :
72 dictdata = dict(list(zip([l for l in range(0,len(classen))], classen)))
74 self.la = [dictdata[l][6] for l in range(0, self.lenact)]
75 self.lchi = [dictdata[l][4] for l in range(0, self.lenact)]
76 self.lfreq = [dictdata[l][1] for l in range(0, self.lenact)]
81 print('cluster : ', i)
82 simi = SimiFromCluster(self.ira, self.corpus, self.la, self.lfreq,
83 self.lchi, i, parametres = simiparam, limit=100)
84 tomerge.append(simi.parametres['ira'])
86 newparam = {'type': 'merge', 'fileout' : '/tmp/test.txt'}
87 newparam['graphs'] = tomerge
88 AnalyseMerge(self.ira, newparam, dlg=None)