...
authorPierre Ratinaud <ratinaud@univ-tlse2.fr>
Fri, 18 Jul 2014 23:28:46 +0000 (01:28 +0200)
committerPierre Ratinaud <ratinaud@univ-tlse2.fr>
Fri, 18 Jul 2014 23:28:46 +0000 (01:28 +0200)
textstat.py
tools.py
tree.py

index ee0e4ef..f8f3735 100644 (file)
@@ -36,10 +36,7 @@ class Stat(AnalyseText) :
         if self.dlg :
             if not 'dlg' in dir(self) :
                 self.dlg = progressbar(self, 7)
         if self.dlg :
             if not 'dlg' in dir(self) :
                 self.dlg = progressbar(self, 7)
-        #if not self.lem :
-        #    formes = self.corpus.formes
-        #else :
-        #    self.corpus.make_lems()
+
         formes = self.corpus.lems
         tot = [[forme, formes[forme].freq, formes[forme].gram] for forme in formes if formes[forme].freq > 1]
         tot = sortedby(tot, 2,1)
         formes = self.corpus.lems
         tot = [[forme, formes[forme].freq, formes[forme].gram] for forme in formes if formes[forme].freq > 1]
         tot = sortedby(tot, 2,1)
@@ -53,11 +50,7 @@ class Stat(AnalyseText) :
         supp = [[forme, formes[forme].freq, formes[forme].gram] for forme in formes if formes[forme].act == 2]        
         supp = sortedby(supp, 2, 1)
 
         supp = [[forme, formes[forme].freq, formes[forme].gram] for forme in formes if formes[forme].act == 2]        
         supp = sortedby(supp, 2, 1)
 
-        #print self.corpus.gethapaxbyuci()
-
         supp = [[i, val] for i, val in enumerate(supp)]
         supp = [[i, val] for i, val in enumerate(supp)]
-        #self.corpus.pathout = self.dictpathout
-        #self.corpus.make_type_tot()
 
         self.result = {u'total' : dict(tot), u'formes_actives' : dict(act), u'formes_supplémentaires' : dict(supp), u'hapax' : dict(hapax), u'glob' : ''}
         occurrences = sum([val[1][1] for val in tot]) + len(hapax)
 
         self.result = {u'total' : dict(tot), u'formes_actives' : dict(act), u'formes_supplémentaires' : dict(supp), u'hapax' : dict(hapax), u'glob' : ''}
         occurrences = sum([val[1][1] for val in tot]) + len(hapax)
@@ -73,7 +66,7 @@ class Stat(AnalyseText) :
         print float(occurrences), float(len(self.corpus.ucis))
         txt += 'moyenne d\'occurrences par texte : %.2f' % (float(occurrences)/float(len(self.corpus.ucis)))
         if self.dlg :
         print float(occurrences), float(len(self.corpus.ucis))
         txt += 'moyenne d\'occurrences par texte : %.2f' % (float(occurrences)/float(len(self.corpus.ucis)))
         if self.dlg :
-             self.dlg.Update(7, u'Ecriture...')
+            self.dlg.Update(7, u'Ecriture...')
         self.result['glob'] = txt
         self.print_result()
         # for Zipf grap
         self.result['glob'] = txt
         self.print_result()
         # for Zipf grap
@@ -98,10 +91,7 @@ class Stat(AnalyseText) :
         while pid.poll() == None :
             sleep(0.2)
         check_Rresult(self.parent, pid)
         while pid.poll() == None :
             sleep(0.2)
         check_Rresult(self.parent, pid)
-        #CreateIraFile(self.dictpathout, 0, corpname = os.path.basename(self.corpus.parametre['filename']), section = 'stat')
         if self.dlg :
         if self.dlg :
-            #OpenAnalyse(self.parent, self.pathout['Analyse.ira'])
-            #self.DoLayout(self.parent)
             self.dlg.Destroy()
 
     def print_result(self) :
             self.dlg.Destroy()
 
     def print_result(self) :
@@ -109,201 +99,8 @@ class Stat(AnalyseText) :
             if key != 'glob' :
                 dico = self.result[key]
                 toprint = [[dico[val][0],`dico[val][1]`, dico[val][2]] for val in dico]
             if key != 'glob' :
                 dico = self.result[key]
                 toprint = [[dico[val][0],`dico[val][1]`, dico[val][2]] for val in dico]
-                #toprint = [[line[0], `line[1]`] for line in self.result[key]]
                 with open(self.pathout['%s.csv' % key], 'w') as f :
                     f.write('\n'.join([';'.join([val for val in ligne]) for ligne in toprint]).encode(self.parent.syscoding))
             else :
                 with open(self.pathout['%s.txt' % 'glob'], 'w') as f :
                     f.write(self.result['glob'].encode(self.parent.syscoding))
                 with open(self.pathout['%s.csv' % key], 'w') as f :
                     f.write('\n'.join([';'.join([val for val in ligne]) for ligne in toprint]).encode(self.parent.syscoding))
             else :
                 with open(self.pathout['%s.txt' % 'glob'], 'w') as f :
                     f.write(self.result['glob'].encode(self.parent.syscoding))
-            #self.parametres['pathout'] = self.pathout['Analyse.ira']
-            #DoConf().makeoptions(['stat'],[self.parametres], self.pathout['Analyse.ira'])
-
-
-#class Stat():
-#    def __init__(self, parent, corpus, cmd = False, lem = True, exp = True):
-#####################################################################   
-#        logger.info('start text stat')
-#        self.conf = None
-#        self.parent = parent
-#        self.type = 'alceste'
-#        self.cmd = cmd
-#        self.ConfigPath = parent.ConfigPath
-#        self.DictPath = parent.DictPath
-#        self.KeyConf = RawConfigParser()
-#        self.KeyConf.read(self.ConfigPath['key'])
-#        page = getPage(self.parent)
-#        if page is not None :
-#            self.corpus = getCorpus(page)
-#            if self.corpus is not None :
-#                self.pathout = ConstructPathOut(self.corpus.parametre['openpath'], 'Stat')
-#                self.dictpathout = StatTxtPathOut(self.pathout)
-#                self.val = wx.ID_OK
-#        else :
-#            self.corpus = Corpus(parent)
-#            self.corpus.parametre['encodage'] = parent.corpus_encodage
-#            self.corpus.parametre['lang'] = parent.corpus_lang
-#            self.corpus.parametre['filename'] = parent.filename
-#            self.pathout = ConstructPathOut(self.corpus.parametre['filename'], 'Stat')
-#            self.dictpathout = StatTxtPathOut(self.pathout)
-#            self.corpus.dictpathout = self.dictpathout
-#            if not self.cmd :
-#                dial = StatDialog(self,parent)
-#                dial.CenterOnParent()
-#                self.val = dial.ShowModal()
-#            else :
-#                self.val = wx.ID_OK
-#            if self.val == wx.ID_OK :
-#                if not self.cmd :
-#                    if dial.radio_lem.GetSelection() == 0 : lem = True
-#                    else : lem = False
-#                    if dial.exp.GetSelection() == 0 : exp = True
-#                    else : exp = False
-#                    self.make_uce = dial.check_uce.GetValue()
-#                    self.corpus.parametre['nbforme_uce'] = dial.spin_ctrl_4.GetValue()
-#                    self.corpus.parametre['max_actives'] = dial.spin_max_actives.GetValue()
-#                    self.corpus.parametre['eff_min_uce'] = self.corpus.parametre['nbforme_uce']
-#                else :
-#                    lem = True
-#                    exp = True
-#                    self.make_uce = False
-#                    self.corpus.parametre['nbforme_uce'] = None
-#                    self.corpus.parametre['eff_min_uce'] = None
-#                self.corpus.parametre['lem'] = lem
-#                self.corpus.parametre['expressions'] = exp
-#                self.corpus.supplementaires = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "2"]
-#                self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]
-#                self.make_corpus()
-#
-#        if self.val == wx.ID_OK :
-#            if 'supplementaires' not in dir(self.corpus) :
-#                print 'supplementaire'
-#                self.corpus.supplementaires = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "2"]
-#                print self.corpus.supplementaires
-#            else :
-#                print 'corpus supplementaires'
-#                print self.corpus.supplementaires
-#            if 'typeactive' not in dir(self.corpus) :
-#                self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]
-#            self.make_stats()
-#
-#    def make_corpus(self) :
-#        if not self.cmd :
-#            self.dlg = progressbar(self, 7)
-#        else :
-#            self.dlg = None
-#        self.corpus.content = self.parent.content
-#        #print 'ATTENTION : FROM TT'
-#        #prepare_for_treetagger(self.corpus, self.parent)
-#        #get_ucis_from_tt(self.corpus)
-#        #qsdfqsdf
-#        ucis_txt, ucis_paras_txt = self.corpus.start_analyse(self.parent, dlg = self.dlg, cmd = self.cmd, fromtt = False)
-#        #self.corpus.make_et_table()
-#        #self.corpus.make_len_uce(self.corpus.get_tot_occ_from_ucis_txt(ucis_txt))
-##        print 'ATTTTTENTION CHECK_DOUBLON'
-##        self.corpus.check_double(ucis_txt)
-#        del ucis_txt
-#        
-#        if not self.cmd :
-#            self.dlg.Update(5, '%i UCI...' % len(ucis_paras_txt))
-#        self.corpus.make_ucis_paras_uces(ucis_paras_txt, make_uce = self.make_uce)
-#        del ucis_paras_txt
-#
-##        print 'ATTENTION EFF PAR UCI'
-##        effuci = [[`i`, `len(uce)`] for i, uci in enumerate(self.corpus.ucis_paras_uces) for para in uci for uce in para]
-##        with open('/home/pierre/fac/identite/taille_uci.csv', 'w') as f :
-##            f.write('\n'.join([';'.join(val) for val in effuci]))
-##        print effuci[0:30]
-##        print max(effuci), min(effuci), float(sum(effuci))/float(len(effuci))
-##        qsdfqsdfqsd
-#
-#
-#        if self.corpus.para_coords != [[] for val in self.corpus.para_coords] :
-#            self.corpus.parametre['para'] = True
-#        else :
-#            self.corpus.parametre['para'] = False
-#        self.corpus.make_etoiles(self.corpus.para_coords)
-#
-#        print 'len(ucis_paras_uces', len(self.corpus.ucis_paras_uces)
-#        
-#        if not self.cmd :
-#            self.dlg.Update(6, u'Dictionnaires')
-#        uces, orderuces = self.corpus.make_forms_and_uces()
-#        self.corpus.make_lems(self.parent.lexique)
-#
-#    def make_stats(self):
-#        if not self.cmd :
-#            if not 'dlg' in dir(self) :
-#                self.dlg = progressbar(self, 7)
-#        if not self.corpus.parametre['lem'] :
-#            formes = self.corpus.formes
-#        else :
-#            formes = self.corpus.make_lem_eff()
-#        tot = [[forme, formes[forme][0], formes[forme][2]] for forme in formes if formes[forme][0] > 1]
-#        tot = sortedby(tot, 2,1)
-#        tot = [[i, val] for i, val in enumerate(tot)]
-#        hapax = [[forme, formes[forme][0], formes[forme][2]] for forme in formes if formes[forme][0] == 1]
-#        hapax = sortedby(hapax, 1, 1)
-#        hapax = [[i, val] for i, val in enumerate(hapax)]
-#        act = [[forme, formes[forme][0], formes[forme][2]] for forme in formes if formes[forme][2] in self.corpus.typeactive]
-#        act = sortedby(act, 2, 1)
-#        act = [[i, val] for i, val in enumerate(act)]
-#        supp = [[forme, formes[forme][0], formes[forme][2]] for forme in formes if formes[forme][2] in self.corpus.supplementaires]
-#        supp = sortedby(supp, 2, 1)
-#        supp = [[i, val] for i, val in enumerate(supp)]
-#        self.corpus.dictpathout = self.dictpathout
-#        #self.corpus.make_type_tot()
-#
-#        self.result = {u'total' : dict(tot), u'formes_actives' : dict(act), u'formes_supplémentaires' : dict(supp), u'hapax' : dict(hapax), u'glob' : ''}
-#        occurrences = sum([val[1][1] for val in tot]) + len(hapax)
-#        phapax = (float(len(hapax)) / float(occurrences)) * 100
-#        phapax_forme = (float(len(hapax)) / (float(len(formes)) + len(hapax))) * 100
-#        moy_occu_mot = float(occurrences) / float(len(formes))
-#        txt = 'Globale\n'
-#        txt += 'nombre d\'uci : %i\n' % len(self.corpus.ucis)
-#        txt += 'nombre d\'occurrences : %i\n' % occurrences
-#        txt += 'nombre de formes : %i\n' % (len(formes) + len(hapax))
-#        txt += 'moyenne d\'occurrences par forme : %.2f\n' % moy_occu_mot
-#        txt += 'nombre d\'hapax : %i (%.2f%% des occurrences - %.2f%% des formes)\n' % (len(hapax), phapax, phapax_forme)
-#        print float(occurrences), float(len(self.corpus.ucis))
-#        txt += 'moyenne d\'occurrences par uci : %.2f' % (float(occurrences)/float(len(self.corpus.ucis)))
-#        if not self.cmd :
-#             self.dlg.Update(7, u'Ecriture...')
-#        self.result['glob'] = txt
-#        self.print_result()
-#        # for Zipf grap
-#        txt = """
-#        source("%s")
-#        tot <- read.csv2("%s", header = FALSE, row.names = 1)
-#        hapax <- read.csv2("%s", header = FALSE, row.names = 1)
-#        tot <- rbind(tot, hapax)
-#        open_file_graph("%s", width = 400, height = 400)
-#        plot(log(tot[,1]), log = 'x', xlab='log(rangs)', ylab = 'log(frequences)', col = 'red', pch=16)
-#        dev.off()
-#        """ % (self.parent.RscriptsPath['Rgraph'], ffr(os.path.join(self.pathout, 'total.csv')), ffr(os.path.join(self.pathout, 'hapax.csv')), self.dictpathout['zipf'])
-#        tmpscript = tempfile.mktemp(dir=self.parent.TEMPDIR)
-#        with open(tmpscript, 'w') as f :
-#            f.write(txt)
-#        pid = exec_rcode(self.parent.RPath, tmpscript, wait = False)
-#        while pid.poll() == None :
-#            sleep(0.2)
-#        check_Rresult(self.parent, pid)
-#        self.corpus.save_corpus(self.dictpathout['db'])
-#        CreateIraFile(self.dictpathout, 0, corpname = os.path.basename(self.corpus.parametre['filename']), section = 'stat')
-#        if not self.cmd :
-#            OpenAnalyse(self.parent, self.dictpathout['ira'])
-#            #self.DoLayout(self.parent)
-#            self.dlg.Destroy()
-#
-#    def print_result(self) :
-#        for key in self.result :
-#            if key != 'glob' :
-#                dico = self.result[key]
-#                toprint = [[dico[val][0],`dico[val][1]`, dico[val][2]] for val in dico]
-#                #toprint = [[line[0], `line[1]`] for line in self.result[key]]
-#                output = open(os.path.join(self.pathout,'%s.csv' % key), 'w')
-#                output.write('\n'.join([';'.join([val for val in ligne]) for ligne in toprint]))
-#                output.close()
-#            else :
-#                output = open(os.path.join(self.pathout,'%s.txt' % 'glob'), 'w')
-#                output.write(self.result['glob'])
-#                output.close()
index e35ea4b..307439f 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -22,6 +22,12 @@ def istext(line) :
     else :
         return False
 
     else :
         return False
 
+def isthem(line):
+    if line.startswith(u'-*') :
+        return True
+    else :
+        return False
+
 def testvar(line, variable) :
     line = line.split()
     varmod = [val.split('_') for val in line[1:]]
 def testvar(line, variable) :
     line = line.split()
     varmod = [val.split('_') for val in line[1:]]
@@ -48,8 +54,10 @@ class Extract :
             parametres = dial.make_param()
             if option == 'splitvar' :
                 SplitFromVar(parametres)
             parametres = dial.make_param()
             if option == 'splitvar' :
                 SplitFromVar(parametres)
-            else :
+            elif option == 'mods' :
                 ExtractMods(parametres)
                 ExtractMods(parametres)
+            elif option == 'them' :
+                SplitFromThem(parametres)
         dial.Destroy()
         dial = wx.MessageDialog(parent, 'Done !', style = wx.OK)
         dial.ShowModal()
         dial.Destroy()
         dial = wx.MessageDialog(parent, 'Done !', style = wx.OK)
         dial.ShowModal()
@@ -84,6 +92,43 @@ class SplitFromVar :
         for f in filedict :
             filedict[f].close()
 
         for f in filedict :
             filedict[f].close()
 
+class SplitFromThem :
+    def __init__(self, parametres) :
+        self.filein = parametres['filein']
+        self.them = parametres['them']
+        self.encodein = parametres['encodein']
+        self.encodeout = parametres['encodeout']
+        self.basepath = os.path.dirname(self.filein)
+        self.pathout = os.path.join(self.basepath, '_'.join([them.replace(u'-*','') for them in self.them]))
+        self.fileout = open(self.pathout, 'w')
+        self.doparse()
+        self.fileout.close()
+    
+    def doparse(self):
+        text = ''
+        keepline = False
+        lastet = ''
+        with codecs.open(self.filein, 'r', self.encodein) as fin :
+            for line in fin :
+                if istext(line) :
+                    self.writetext(self.fileout, lastet, text)
+                    text = ''
+                    lastet = line
+                if isthem(line) :
+                    l = line.strip().rstrip('\n\r')
+                    if l in self.them :
+                        keepline = True
+                    else :
+                        keepline = False
+                if keepline :
+                    text += line
+            self.writetext(self.fileout, lastet, text)
+    
+    def writetext(self, fileout, lastet, text):
+        if text != '' :
+            self.fileout.write(lastet.encode(self.encodeout) + text.encode(self.encodeout))
+            
+
 class ExtractMods :
     def __init__(self, parametres) :
         self.onefile = parametres.get('onefile', False)
 class ExtractMods :
     def __init__(self, parametres) :
         self.onefile = parametres.get('onefile', False)
diff --git a/tree.py b/tree.py
index 69a78cb..76808aa 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -10,11 +10,14 @@ import wx.lib.agw.customtreectrl as CT
 import logging
 from openanalyse import OpenAnalyse
 from corpus import Corpus, copycorpus
 import logging
 from openanalyse import OpenAnalyse
 from corpus import Corpus, copycorpus
-from functions import DoConf, GetTxtProfile
+from tableau import Tableau, copymatrix
+from functions import DoConf, GetTxtProfile, TGen
 from profile_segment import ProfileSegment, ProfilType
 from search_tools import SearchFrame
 from dialog import PrefSimpleFile, PrefExport
 from profile_segment import ProfileSegment, ProfilType
 from search_tools import SearchFrame
 from dialog import PrefSimpleFile, PrefExport
-from layout import open_antiprofil
+from layout import open_antiprofil, TgenLayout
+from guifunct import TGenFrame
+from textaslexico import TgenSpec
 
 log = logging.getLogger('iramuteq.tree')
 
 
 log = logging.getLogger('iramuteq.tree')
 
@@ -116,6 +119,12 @@ class LeftTree(CT.CustomTreeCtrl):
         self.ild['clustersimitxt'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'clustersimitxt.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['clustercloud'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'clustercloud.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['spec'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'spec.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['clustersimitxt'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'clustersimitxt.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['clustercloud'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'clustercloud.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['spec'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'spec.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        imgmatroot = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matroot.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['matrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['freq'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'frequences.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['chi2'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'chi2.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['reinertmatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'reinertmatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['simimatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.SetImageList(self.il)
         
         self.count = 0
         self.SetImageList(self.il)
         
         self.count = 0
@@ -154,15 +163,28 @@ class LeftTree(CT.CustomTreeCtrl):
 
         self.matroot = self.AppendItem(self.root, u'Matrices')
         self.SetPyData(self.matroot, {'uuid': 'matroot'})
 
         self.matroot = self.AppendItem(self.root, u'Matrices')
         self.SetPyData(self.matroot, {'uuid': 'matroot'})
-        self.SetItemImage(self.matroot, 24, CT.TreeItemIcon_Normal)
-        self.SetItemImage(self.matroot, 13, CT.TreeItemIcon_Expanded)
+        self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Normal)
+        self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Expanded)
         
         
-        for matrix in self.history.matrix :
-            last = self.AppendItem(self.matroot, matrix['name'])
-            self.SetPyData(last, matrix)
-            self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
-            self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
-
+        orphmat = []
+        for matrix in reversed(self.history.matrix) :
+            if 'matrix_name' in matrix :
+                child = self.AppendItem(self.matroot, matrix['matrix_name'])
+                self.SetPyData(child, matrix)
+                self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Normal)
+                self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Expanded)
+                if 'analyses' in matrix :
+                    for y in matrix['analyses'] :
+                        last = self.AppendItem(child, y['name'], ct_type=0)
+                        self.SetPyData(last, y)
+                        if y['type'] in self.ild :
+                            img = self.ild[y['type']]
+                        else :
+                            img = 24
+                        self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
+                        self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
+            else :
+                orphmat.append(matrix)     
 
         self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
         #self.Bind(wx.EVT_IDLE, self.OnIdle)
 
         self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
         #self.Bind(wx.EVT_IDLE, self.OnIdle)
@@ -292,6 +314,7 @@ class LeftTree(CT.CustomTreeCtrl):
         if itemParent is None :
             itemParent = self.root
         child, cookie = self.GetFirstChild(itemParent)
         if itemParent is None :
             itemParent = self.root
         child, cookie = self.GetFirstChild(itemParent)
+        
         while child :
             pydata = self.GetPyData(child)
             if pydata['uuid'] == uuid :
         while child :
             pydata = self.GetPyData(child)
             if pydata['uuid'] == uuid :
@@ -365,18 +388,34 @@ class LeftTree(CT.CustomTreeCtrl):
                 stat = menu.Append(wx.ID_ANY, _(u"Statistics").decode('utf8'))
                 spec = menu.Append(wx.ID_ANY, _(u"Specificities and CA").decode('utf8'))
                 classification = wx.Menu()
                 stat = menu.Append(wx.ID_ANY, _(u"Statistics").decode('utf8'))
                 spec = menu.Append(wx.ID_ANY, _(u"Specificities and CA").decode('utf8'))
                 classification = wx.Menu()
-                alceste = classification.Append(wx.ID_ANY, _(u"Reinert method").decode('utf8'))
+                reinert = classification.Append(wx.ID_ANY, _(u"Reinert method").decode('utf8'))
                 #pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
                 menu.AppendMenu(-1, _(u"Clustering").decode('utf8'), classification)
                 simi = menu.Append(wx.ID_ANY, _(u"Similarities analysis").decode('utf8'))
                 wdc = menu.Append(wx.ID_ANY, _(u"Wordcloud").decode('utf8'))
                 #pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
                 menu.AppendMenu(-1, _(u"Clustering").decode('utf8'), classification)
                 simi = menu.Append(wx.ID_ANY, _(u"Similarities analysis").decode('utf8'))
                 wdc = menu.Append(wx.ID_ANY, _(u"Wordcloud").decode('utf8'))
+                subcorpus = wx.Menu()
+                subcorpusfrommeta = subcorpus.Append(wx.ID_ANY, _(u'Sub corpora from metadata').decode('utf8'))
+                subcorpusfromtheme = subcorpus.Append(wx.ID_ANY, _(u'Sub corpora from thematic').decode('utf8'))
+                menu.AppendMenu(-1, _(u"SubCorpora").decode('utf8'), subcorpus)
                 menu.AppendSeparator()
                 menu.AppendSeparator()
-                self.Bind(wx.EVT_MENU, self.OnAlceste, alceste)
+                self.Bind(wx.EVT_MENU, self.OnReinert, reinert)
                 #self.Bind(wx.EVT_MENU, self.OnPam, pam)
                 self.Bind(wx.EVT_MENU, self.OnStat, stat)
                 self.Bind(wx.EVT_MENU, self.OnSpec, spec)
                 self.Bind(wx.EVT_MENU, self.OnSimiTxt, simi)
                 self.Bind(wx.EVT_MENU, self.OnWordCloud, wdc)
                 #self.Bind(wx.EVT_MENU, self.OnPam, pam)
                 self.Bind(wx.EVT_MENU, self.OnStat, stat)
                 self.Bind(wx.EVT_MENU, self.OnSpec, spec)
                 self.Bind(wx.EVT_MENU, self.OnSimiTxt, simi)
                 self.Bind(wx.EVT_MENU, self.OnWordCloud, wdc)
+                self.Bind(wx.EVT_MENU, self.OnSubTextFromMeta, subcorpusfrommeta)
+                self.Bind(wx.EVT_MENU, self.OnSubTextFromTheme, subcorpusfromtheme)
+            elif 'matrix_name' in pydata :
+                freq = menu.Append(wx.ID_ANY, _(u"Frequency").decode('utf8'))
+                chi2 = menu.Append(wx.ID_ANY, _(u"Chi square").decode('utf8'))
+                chdreinert = menu.Append(wx.ID_ANY, _(u"Reinert clustering").decode('utf8'))
+                simi = menu.Append(wx.ID_ANY, _(u"Similarity analysis").decode('utf8'))
+                menu.AppendSeparator()
+                self.Bind(wx.EVT_MENU, self.OnFreq, freq)
+                self.Bind(wx.EVT_MENU, self.OnChiSquare, chi2)
+                self.Bind(wx.EVT_MENU, self.OnSimiTab, simi)
+                self.Bind(wx.EVT_MENU, self.OnCHDReinert, chdreinert)
             elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
                 openmenu = wx.Menu()
                 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
             elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
                 openmenu = wx.Menu()
                 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
@@ -389,6 +428,7 @@ class LeftTree(CT.CustomTreeCtrl):
                 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
                 statclasse = menu.Append(wx.ID_ANY, _(u"Clusters statistics").decode('utf8'))
                 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
                 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
                 statclasse = menu.Append(wx.ID_ANY, _(u"Clusters statistics").decode('utf8'))
                 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
+                export_classes = menu.Append(wx.ID_ANY, _(u"Exports Clusters").decode('utf8'))
                 menu.AppendSeparator()
                 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
                 self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
                 menu.AppendSeparator()
                 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
                 self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
@@ -398,13 +438,20 @@ class LeftTree(CT.CustomTreeCtrl):
                 self.Bind(wx.EVT_MENU, self.OnNavig, navig)
                 self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
                 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
                 self.Bind(wx.EVT_MENU, self.OnNavig, navig)
                 self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
                 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
+                self.Bind(wx.EVT_MENU, self.OnExportClasses, export_classes)
             elif pydata.get('type', False) == 'stat'  and pydata['uuid'] in self.parent.history.opened :
                 export_dictionary =  menu.Append(wx.ID_ANY, _(u"Export dictionary").decode('utf8'))
                 export_lems =  menu.Append(wx.ID_ANY, _(u"Export lemma dictionary").decode('utf8'))
                 self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
                 self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
                 menu.AppendSeparator()
             elif pydata.get('type', False) == 'stat'  and pydata['uuid'] in self.parent.history.opened :
                 export_dictionary =  menu.Append(wx.ID_ANY, _(u"Export dictionary").decode('utf8'))
                 export_lems =  menu.Append(wx.ID_ANY, _(u"Export lemma dictionary").decode('utf8'))
                 self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
                 self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
                 menu.AppendSeparator()
-            elif pydata.get('type', False) == 'gnepamatrix' and pydata['uuid'] in self.parent.history.opened :
+            elif pydata.get('type', False) == 'spec'  and pydata['uuid'] in self.parent.history.opened :
+                tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
+                computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
+                self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
+                self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
+                menu.AppendSeparator()
+            elif pydata.get('type', False) == 'reinertmatrix' and pydata['uuid'] in self.parent.history.opened :
                 openmenu = wx.Menu()
                 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
                 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
                 openmenu = wx.Menu()
                 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
                 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
@@ -432,17 +479,32 @@ class LeftTree(CT.CustomTreeCtrl):
             menu.Destroy()
 
     def getcorpus(self):
             menu.Destroy()
 
     def getcorpus(self):
+        busy = wx.BusyInfo(_("Please wait...Reading corpus").decode('utf8'), self.parent)
+        wx.SafeYield()
         if self.pydata['uuid'] in self.parent.history.openedcorpus :
         if self.pydata['uuid'] in self.parent.history.openedcorpus :
-            return copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
+            corpus = copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
         elif 'corpus_name' in self.pydata :
         elif 'corpus_name' in self.pydata :
-            return Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
+            corpus = Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
         else :
             cuuid = self.pydata['corpus']
             if cuuid in self.parent.history.openedcorpus :
         else :
             cuuid = self.pydata['corpus']
             if cuuid in self.parent.history.openedcorpus :
-                return copycorpus(self.parent.history.openedcorpus[cuuid])
+                corpus = copycorpus(self.parent.history.openedcorpus[cuuid])
             else :
                 irapath = self.parent.history.corpus[cuuid]['ira']
             else :
                 irapath = self.parent.history.corpus[cuuid]['ira']
-                return Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
+                corpus = Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
+        del busy
+        return corpus
+    
+    def getmatrix(self):
+        if 'matrix_name' in self.pydata :
+            matrix = Tableau(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('matrix'))
+            matrix.open()
+            return copymatrix(matrix)
+        else :
+            cuuid = self.pydata['matrix']
+            matrix = Tableau(self.parent, parametres = DoConf(self.history.matrixanalyse[cuuid]['ira']).getoptions('matrix'))
+            matrix.open()
+            return copymatrix(matrix)
 
     def OnSpec(self, evt) :
         self.parent.OnTextSpec(evt, self.getcorpus())
 
     def OnSpec(self, evt) :
         self.parent.OnTextSpec(evt, self.getcorpus())
@@ -450,8 +512,8 @@ class LeftTree(CT.CustomTreeCtrl):
     def OnStat(self, evt) :
         self.parent.OnTextStat(evt, self.getcorpus())
         
     def OnStat(self, evt) :
         self.parent.OnTextStat(evt, self.getcorpus())
         
-    def OnAlceste(self, evt) :
-        self.parent.OnTextAlceste(evt, self.getcorpus())
+    def OnReinert(self, evt) :
+        self.parent.OnTextReinert(evt, self.getcorpus())
 
     def OnPam(self, evt) :
         self.parent.OnPamSimple(evt, self.getcorpus())
 
     def OnPam(self, evt) :
         self.parent.OnPamSimple(evt, self.getcorpus())
@@ -461,6 +523,24 @@ class LeftTree(CT.CustomTreeCtrl):
 
     def OnWordCloud(self, evt) :
         self.parent.OnWordCloud(evt, self.getcorpus())
 
     def OnWordCloud(self, evt) :
         self.parent.OnWordCloud(evt, self.getcorpus())
+    
+    def OnFreq(self, evt):
+        self.parent.OnFreq(evt, self.getmatrix())
+        
+    def OnChiSquare(self, evt):
+        self.parent.OnChi2(evt, self.getmatrix())
+        
+    def OnSimiTab(self, evt): 
+        self.parent.OnSimiTab(evt, self.getmatrix())
+        
+    def OnCHDReinert(self, evt):
+        self.parent.OnCHDReinert(evt, self.getmatrix())
+    
+    def OnSubTextFromMeta(self, evt):
+        self.parent.OnSubText(self.getcorpus(), parametres = {'frommeta' : True})
+    
+    def OnSubTextFromTheme(self, evt):
+        self.parent.OnSubText(self.getcorpus(), parametres = {'fromtheme' : True})    
 
     def OnProfSR(self, evt) :
         ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
 
     def OnProfSR(self, evt) :
         ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
@@ -577,6 +657,47 @@ class LeftTree(CT.CustomTreeCtrl):
         dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
         dial.ShowModal()
         dial.Destroy()
         dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
         dial.ShowModal()
         dial.Destroy()
+    
+    def OnTgenEditor(self, evt):
+        corpus = self.page.corpus
+        tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
+        tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
+        if os.path.exists(tgenpath) :
+            tgen.read(tgenpath)
+        if isinstance(evt, list) :
+            i = 0
+            while 'tgen%i' %i in tgen.tgen :
+                i += 1
+            tgenname = 'tgen%i' %i
+            tgen.tgen[tgenname] = evt
+        tgenframe = TGenFrame(self.parent, corpus, tgen)
+        tgenframe.Show()
+        if isinstance(evt, list) :
+            tgenframe.OnNewTgen(None, tgen = tgenname)
+    
+    def OnTgenCompute(self, evt):
+        corpus = self.page.corpus
+        tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')        
+        self.page.parametres['tgenpath'] = tgenpath
+        tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
+        self.page.parametres['etoiles'] = self.page.etoiles
+        TgenSpec(self.parent, corpus, self.page.parametres)
+        TgenLayout(self.page)
+    
+    def OnExportClasses(self, event):
+        corpus = self.page.corpus
+        if self.page.parametres['classif_mode'] != 2 :
+            uci = False
+        else :
+            uci = True
+        busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self.parent)
+        wx.SafeYield()
+        for i in range(1, self.page.parametres['clnb'] + 1) :
+            corpus.export_classe(self.page.pathout['classe_%i_export.txt' % i], i, uci = uci)
+        del busy
+        dial = wx.MessageDialog(self, self.page.pathout['classe_x_export.txt'], u"Export", wx.OK|wx.ICON_INFORMATION)
+        dial.ShowModal()
+        dial.Destroy()
 
     def OnItemBackground(self, event):
 
 
     def OnItemBackground(self, event):
 
@@ -745,7 +866,6 @@ class LeftTree(CT.CustomTreeCtrl):
                 self.GiveFocus(child, uuid)
                 child, cookie = self.GetNextChild(itemParent, cookie)
             #item = self.AppendItem(child, parametres['name'])
                 self.GiveFocus(child, uuid)
                 child, cookie = self.GetNextChild(itemParent, cookie)
             #item = self.AppendItem(child, parametres['name'])
-            print corpus
             if corpus is not None : 
                 item = self.AppendItem(corpus, parametres['name'])
             else :
             if corpus is not None : 
                 item = self.AppendItem(corpus, parametres['name'])
             else :
@@ -760,9 +880,40 @@ class LeftTree(CT.CustomTreeCtrl):
         self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
         self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
         self.SetItemBold(item, bold)
         self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
         self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
         self.SetItemBold(item, bold)
+    
+    def AddMatAnalyse(self, parametres, itemParent = None, bold = True) :
+        uuid = parametres.get('matrix', None)
+        if uuid is not None :
+            if itemParent is None :
+                itemParent = self.matroot
+            child, cookie = self.GetFirstChild(itemParent)
+            matrix = None
+            while child :
+                pydata = self.GetPyData(child)
+                if pydata['uuid'] == uuid :
+                    matrix = child
+                    break
+                self.GiveFocus(child, uuid)
+                child, cookie = self.GetNextChild(itemParent, cookie)
+            #item = self.AppendItem(child, parametres['name'])
+            if matrix is not None : 
+                item = self.AppendItem(matrix, parametres['name'])
+            else :
+                item = self.AppendItem(self.matroot, parametres['name'])
+        self.SetPyData(item, parametres)
+        if parametres['type'] in self.ild :
+            img = self.ild[parametres['type']]
+        else :
+            img = 24
+        self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
+        self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
+        self.SetItemBold(item, bold)    
         
     def OnItemAppend(self, item):
         
     def OnItemAppend(self, item):
-        child = self.InsertItem(self.textroot, 0, item['corpus_name'])
+        if 'corpus_name' in item :
+            child = self.InsertItem(self.textroot, 0, item['corpus_name'])
+        else :
+            child = self.InsertItem(self.matroot, 0, item['matrix_name'])
         self.SetPyData(child, item)
         self.history.addtab(item)
         if item['type'] in self.ild :
         self.SetPyData(child, item)
         self.history.addtab(item)
         if item['type'] in self.ild :