...
[iramuteq] / ProfList.py
index 9097897..09b30a2 100644 (file)
@@ -17,7 +17,7 @@ import os
 import sys
 import  wx
 import  wx.lib.mixins.listctrl  as  listmix
 import sys
 import  wx
 import  wx.lib.mixins.listctrl  as  listmix
-from tabsimi import DoSimi
+#from tabsimi import DoSimi
 from listlex import ListForSpec
 from chemins import ConstructPathOut, ffr
 from dialog import PrefExport, PrefUCECarac, SearchDial, message
 from listlex import ListForSpec
 from chemins import ConstructPathOut, ffr
 from dialog import PrefExport, PrefUCECarac, SearchDial, message
@@ -49,13 +49,17 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
             self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
             profclasse.pop(self.lenact)
         except ValueError:
             self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
             profclasse.pop(self.lenact)
         except ValueError:
-            self.lenact = len(profclasse)
+            try :
+                self.lenact = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
+                profclasse.pop(self.lenact)
+            except ValueError:
+                self.lenact = len(profclasse)
         try :
             self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
             self.lensup = self.lensup - self.lenact
             profclasse.pop(self.lensup)
         except ValueError: 
         try :
             self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
             self.lensup = self.lensup - self.lenact
             profclasse.pop(self.lensup)
         except ValueError: 
-            self.lensup = 0
+            self.lensup = len(profclasse) - self.lenact
         self.lenet = len(profclasse) - (self.lenact + self.lensup)
 #        print self.lenact, self.lensup, self.lenet
         for i,  line in enumerate(classen) :
         self.lenet = len(profclasse) - (self.lenact + self.lensup)
 #        print self.lenact, self.lensup, self.lenet
         for i,  line in enumerate(classen) :
@@ -70,6 +74,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
             self.la = []
             self.lchi = []
             self.lfreq = []
             self.la = []
             self.lchi = []
             self.lfreq = []
+        self.tmpchi = None
             
         #adding some art
         self.il = wx.ImageList(16, 16)
             
         #adding some art
         self.il = wx.ImageList(16, 16)
@@ -154,18 +159,9 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
 
     def OnItemSelected(self, event):
         self.currentItem = event.m_itemIndex
 
     def OnItemSelected(self, event):
         self.currentItem = event.m_itemIndex
-        #print 'OnItemSelected: "%s", "%s", "%s", "%s"\n' % (self.currentItem, self.GetItemText(self.currentItem), self.getColumnText(self.currentItem, 1), self.getColumnText(self.currentItem, 2))
-        #self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
-        #                   (self.currentItem,
-        #                    self.GetItemText(self.currentItem),
-        #                    self.getColumnText(self.currentItem, 1),
-        #                    self.getColumnText(self.currentItem, 2)))
 
     def OnItemActivated(self, event):
         self.currentItem = event.m_itemIndex
 
     def OnItemActivated(self, event):
         self.currentItem = event.m_itemIndex
-        #print "OnItemActivated: %s\nTopItem: %s\n" % (self.GetItemText(self.currentItem), self.GetTopItem())
-        #self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
-        #                   (self.GetItemText(self.currentItem), self.GetTopItem()))
 
     def getColumnText(self, index, col):
         item = self.GetItem(index, col)
 
     def getColumnText(self, index, col):
         item = self.GetItem(index, col)
@@ -173,9 +169,6 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
 
     def OnItemDeselected(self, evt):
         pass
 
     def OnItemDeselected(self, evt):
         pass
-        #self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
-
-
     #---------------------------------------------------
     # These methods are callbacks for implementing the
     # "virtualness" of the list...
     #---------------------------------------------------
     # These methods are callbacks for implementing the
     # "virtualness" of the list...
@@ -200,7 +193,6 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
 
     def OnGetItemAttr(self, item):
         index=self.itemIndexMap[item]
 
     def OnGetItemAttr(self, item):
         index=self.itemIndexMap[item]
-        #genre=self.itemDataMap[index][2]
         if index < self.lenact :
             if item % 2 :
                 return self.attr1
         if index < self.lenact :
             if item % 2 :
                 return self.attr1
@@ -219,15 +211,6 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         else :
             return None
 
         else :
             return None
 
-#        if genre=="Rock":
-#            return self.attr2
-#        elif genre=="Jazz":
-#            return self.attr1
-#        elif genre=="New Age":
-#            return self.attr3
-#        else:
-#            return None
-
     #---------------------------------------------------
     # Matt C, 2006/02/22
     # Here's a better SortItems() method --
     #---------------------------------------------------
     # Matt C, 2006/02/22
     # Here's a better SortItems() method --
@@ -393,17 +376,21 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         vchistable = [line[1:] for line in chistable]
         fchistable = [line[0] for line in chistable]
         word = self.getselectedwords()[0]
         vchistable = [line[1:] for line in chistable]
         fchistable = [line[0] for line in chistable]
         word = self.getselectedwords()[0]
+        print self.var_mod
         if len(word.split('_')) > 1 :
             var = word.split('_')
         if len(word.split('_')) > 1 :
             var = word.split('_')
-            words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
+            #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
+            words = [word for word in self.var_mod[var[0]]]
             words.sort()
             tableout = []
             kwords = []
             for word in words :
             words.sort()
             tableout = []
             kwords = []
             for word in words :
+                print word
                 if word in fchistable :
                     tableout.append(vchistable[fchistable.index(word)])
                     kwords.append(word)
             tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
                 if word in fchistable :
                     tableout.append(vchistable[fchistable.index(word)])
                     kwords.append(word)
             tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            print tableout
             txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
             tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
             file = open(tmpscript,'w')
             txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
             tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
             file = open(tmpscript,'w')
@@ -424,13 +411,13 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
     def quest_simi(self, evt) :
         tableau = self.Source.tableau
         tab = tableau.make_table_from_classe(self.cl, self.la)
     def quest_simi(self, evt) :
         tableau = self.Source.tableau
         tab = tableau.make_table_from_classe(self.cl, self.la)
-        pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
+        pathout = ConstructPathOut(os.path.join(self.Source.pathout.dirout, 'simi_classe_%i' %self.cl), 'simi_classe_%i' %self.cl)
         self.filename = os.path.join(pathout,'mat01.csv')
         tableau.printtable(self.filename, tab)
         del tab
         paramsimi = {'coeff' : 0,
                           'layout' : 2,
         self.filename = os.path.join(pathout,'mat01.csv')
         tableau.printtable(self.filename, tab)
         del tab
         paramsimi = {'coeff' : 0,
                           'layout' : 2,
-                          'type' : 1,
+                          'type_graph' : 1,
                           'arbremax' : 1,
                           'coeff_tv' : 1,
                           'coeff_tv_nb' : 0,
                           'arbremax' : 1,
                           'coeff_tv' : 1,
                           'coeff_tv_nb' : 0,
@@ -458,6 +445,9 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                           'keep_coord' : True,
                           'alpha' : 20,
                           'film': False,
                           'keep_coord' : True,
                           'alpha' : 20,
                           'film': False,
+                          'com' : 0,
+                          'communities' : 0,
+                          'halo' : 0
                           }
 #        self.tableau.actives = {}
 #        self.tableau.lchi = self.lchi
                           }
 #        self.tableau.actives = {}
 #        self.tableau.lchi = self.lchi
@@ -467,118 +457,95 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
 #            self.tableau.chi[val] = [self.lchi[i]]
                           
         act = {}
 #            self.tableau.chi[val] = [self.lchi[i]]
                           
         act = {}
-        self.tableau.chi = {}
-        self.tableau.lchi = self.lchi
-        self.tableau.parametre['fromprof'] = True
+        tableau.chi = {}
+        tableau.lchi = self.lchi
+        tableau.parametre['fromprof'] = True
         for i, val in enumerate(self.la) :
             act[val] = [self.lfreq[i]]
         for i, val in enumerate(self.la) :
             act[val] = [self.lfreq[i]]
-            self.tableau.chi[val] = [self.lchi[i]]
-        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
+            tableau.chi[val] = [self.lchi[i]]
+        self.parent.SimiCluster(parametres = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act, tableau = tableau)
 
     def onwordgraph(self, evt):
         word = self.getColumnText(self.GetFirstSelected(), 6)
 
     def onwordgraph(self, evt):
         word = self.getColumnText(self.GetFirstSelected(), 6)
-        dlg = progressbar(self, 2)
-        corpus = self.Source.corpus
-        uces = corpus.lc[self.cl-1]
-        dlg.Update(1, u'Tableau...')
-        #tab = corpus.make_table_with_classe(uces, self.la)
-        pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
-        self.filename = os.path.join(pathout,'mat01.csv')
-        dlg.Update(2, u'Ecriture...')
-        #corpus.write_tab(tab, self.filename)
-        #del tab
-        corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
-        dlg.Destroy()
-        paramsimi = {'coeff' : 0,
-                          'layout' : 2,
-                          'type' : 1,
-                          'arbremax' : 0,
-                          'coeff_tv' : 1,
-                          'coeff_tv_nb' : 0,
-                          'tvprop' : 0,
-                          'tvmin' : 5,
-                          'tvmax' : 30,
-                          'coeff_te' : 1,
-                          'coeff_temin' : 1,
-                          'coeff_temax' : 10,
-                          'label_v': 1,
-                          'label_e': 0,
-                          'vcex' : 1,
-                          'vcexmin' : 10,
-                          'vcexmax' : 25, 
-                          'cex' : 10,
-                          'seuil_ok' : 1,
-                          'seuil' : 1,
-                          'cols' : (255,0,0),
-                          'cola' : (200,200,200),
-                          'width' : 600,
-                          'height' : 600,
-                          'first' : True,
-                          'keep_coord' : True,
-                          'alpha' : 20,
-                          'film': False,
-                          }
-        self.tableau = Tableau(self.parent, '')
-        self.tableau.listactives = self.la
-        self.tableau.actives = {}
-        for i, val in enumerate(self.la) :
-            self.tableau.actives[val] = [self.lfreq[i]]
-        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
+        if self.tmpchi is None :
+            self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            with open(self.tmpchi, 'w') as f:
+                f.write('\n'.join([str(val) for val in self.lchi]))
+        index = self.la.index(word)
+        parametres = {'type' : 'clustersimitxt', 
+                        'pathout' : self.Source.parametres['pathout'],
+                        'word' : index ,
+                        'lem' : self.Source.parametres['lem'],
+                        'tmpchi' : self.tmpchi}
+        #try :
+        self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
+        #except :
+        #    print 'not acitve'
 
     def on_graph(self, evt):
 
     def on_graph(self, evt):
-        dlg = progressbar(self, 2)
-        corpus = self.Source.corpus
-        uces = corpus.lc[self.cl-1]
-        dlg.Update(1, u'Tableau...')
-        #tab = corpus.make_table_with_classe(uces, self.la)
-        pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
-        self.filename = os.path.join(pathout,'mat01.csv')
-        dlg.Update(2, u'Ecriture...')
-        #corpus.write_tab(tab, self.filename)
-        #del tab
-        corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
-        dlg.Destroy()
-        paramsimi = {'coeff' : 0,
-                          'layout' : 2,
-                          'type' : 1,
-                          'arbremax' : 1,
-                          'coeff_tv' : 1,
-                          'coeff_tv_nb' : 0,
-                          'tvprop' : 0,
-                          'tvmin' : 5,
-                          'tvmax' : 30,
-                          'coeff_te' : 1,
-                          'coeff_temin' : 1,
-                          'coeff_temax' : 10,
-                          'label_v': 1,
-                          'label_e': 0,
-                          'vcex' : 0,
-                          'vcexmin' : 10,
-                          'vcexmax' : 25,
-                          'cex' : 10,
-                          'cexfromchi' : True,
-                          'sfromchi': False,
-                          'seuil_ok' : 0,
-                          'seuil' : 1,
-                          'cols' : (255,0,0),
-                          'cola' : (200,200,200),
-                          'width' : 1000,
-                          'height' : 1000,
-                          'first' : True,
-                          'keep_coord' : True,
-                          'alpha' : 20,
-                          'film': False,
-                          }
-        self.tableau = Tableau(self.parent, '')
-        self.tableau.listactives = self.la
-        self.tableau.actives = {}
-        self.tableau.lchi = self.lchi
-        self.tableau.chi = {}
-        self.tableau.parametre['fromprof'] = True
-        for i, val in enumerate(self.la) :
-            self.tableau.actives[val] = [self.lfreq[i]]
-            self.tableau.chi[val] = [self.lchi[i]]
-        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
+        if self.tmpchi is None :
+            self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            with open(self.tmpchi, 'w') as f:
+                f.write('\n'.join([str(val) for val in self.lchi]))
+        parametres = {'type' : 'clustersimitxt', 
+                        'pathout' : self.Source.parametres['pathout'],
+                        'lem' : self.Source.parametres['lem'],
+                        'tmpchi' : self.tmpchi}
+
+        self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
+        #dlg = progressbar(self, 2)
+        #corpus = self.Source.corpus
+        #uces = corpus.lc[self.cl-1]
+        #dlg.Update(1, u'Tableau...')
+        ##tab = corpus.make_table_with_classe(uces, self.la)
+        #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
+        #self.filename = os.path.join(pathout,'mat01.csv')
+        #dlg.Update(2, u'Ecriture...')
+        ##corpus.write_tab(tab, self.filename)
+        ##del tab
+        #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
+        #dlg.Destroy()
+        #paramsimi = {'coeff' : 0,
+        #                  'layout' : 2,
+        #                  'type' : 1,
+        #                  'arbremax' : 1,
+        #                  'coeff_tv' : 1,
+        #                  'coeff_tv_nb' : 0,
+        #                  'tvprop' : 0,
+        #                  'tvmin' : 5,
+        #                  'tvmax' : 30,
+        #                  'coeff_te' : 1,
+        #                  'coeff_temin' : 1,
+        #                  'coeff_temax' : 10,
+        #                  'label_v': 1,
+        #                  'label_e': 0,
+        #                  'vcex' : 0,
+        #                  'vcexmin' : 10,
+        #                  'vcexmax' : 25,
+        #                  'cex' : 10,
+        #                  'cexfromchi' : True,
+        #                  'sfromchi': False,
+        #                  'seuil_ok' : 0,
+        #                  'seuil' : 1,
+        #                  'cols' : (255,0,0),
+        #                  'cola' : (200,200,200),
+        #                  'width' : 1000,
+        #                  'height' : 1000,
+        #                  'first' : True,
+        #                  'keep_coord' : True,
+        #                  'alpha' : 20,
+        #                  'film': False,
+        #                  }
+        #self.tableau = Tableau(self.parent, '')
+        #self.tableau.listactives = self.la
+        #self.tableau.actives = {}
+        #self.tableau.lchi = self.lchi
+        #self.tableau.chi = {}
+        #self.tableau.parametre['fromprof'] = True
+        #for i, val in enumerate(self.la) :
+        #    self.tableau.actives[val] = [self.lfreq[i]]
+        #    self.tableau.chi[val] = [self.lchi[i]]
+        #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
 
     def on_segments(self,evt) :
         dlg = progressbar(self, 2)
 
     def on_segments(self,evt) :
         dlg = progressbar(self, 2)