...
[iramuteq] / ProfList.py
index f564d60..e882f7e 100644 (file)
@@ -274,6 +274,8 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                 self.idlexdendro = wx.NewId()
                 self.idcloud = wx.NewId()
                 self.idexport = wx.NewId()
+                self.idexporttropes = wx.NewId()
+                self.idexportowledge = wx.NewId()
             #    self.export_classes = wx.NewId()
    
                 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
@@ -296,6 +298,8 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
                 self.Bind(wx.EVT_MENU, self.oncloud, id = self.idcloud)
                 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
+                self.Bind(wx.EVT_MENU, self.onexporttropes, id = self.idexporttropes)
+                self.Bind(wx.EVT_MENU, self.onexportowledge, id = self.idexportowledge)
              #  self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
    #            self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
     
@@ -329,6 +333,8 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
             menu.Append(self.iducecarac, u"Segments de texte caractéristiques")
             menu.Append(self.idcloud, u"Nuage de la classe")
             menu.Append(self.idexport, u'Exporter...')
+            menu.Append(self.idexporttropes, 'Exporter pour Tropes')
+            menu.Append(self.idexportowledge, 'Exporter pour Owledge')
             #menu.Append(self.popupID2, u"Concordancier")
     #        menu.Append(self.popupID3, "recharger")
     
@@ -379,6 +385,28 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         #if 'corpus' in dir(self.Source):
         #    corpus = self.Source.corpus
         #ClasseCHD(self.parent, corpus, self.cl)
+    
+    def onexporttropes(self, evt) :
+        if 'corpus' in dir(self.Source):
+            corpus = self.Source.corpus
+        if self.Source.parametres['classif_mode'] != 2 :
+            uci = False
+        else :
+            uci = True
+        fileout = self.Source.pathout['export_tropes_classe_%i.txt' % self.cl]
+        corpus.export_tropes(fileout, self.cl, uci = uci)
+    
+    def onexportowledge(self, evt):
+        if 'corpus' in dir(self.Source):
+            corpus = self.Source.corpus
+        if self.Source.parametres['classif_mode'] != 2 :
+            uci = False
+        else :
+            uci = True
+        repout = self.Source.pathout['export_owledge_classe_%i' % self.cl]
+        if not os.path.exists(repout) :
+            os.mkdir(repout)
+        corpus.export_owledge(repout, self.cl, uci = uci)        
 
     def getselectedwords(self) :
         words = [self.getColumnText(self.GetFirstSelected(), 6)]
@@ -436,12 +464,12 @@ 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)
+        pathout = ConstructPathOut(self.Source.pathout.dirout, 'simi_classe_%i' %self.cl)
         if self.tmpchi is None :
-            self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            self.tmpchi = os.path.join(pathout,'chi.csv')
             with open(self.tmpchi, 'w') as f:
                 f.write('\n'.join([str(val) for val in self.lchi]))
-        tab = tableau.make_table_from_classe(self.cl, self.la)
-        pathout = ConstructPathOut(self.Source.pathout.dirout, 'simi_classe_%i' %self.cl)
         self.filename = os.path.join(pathout,'mat01.csv')
         tableau.printtable(self.filename, tab)
         del tab
@@ -483,7 +511,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
         act = {}
         tableau.chi = {}
         tableau.lchi = self.lchi
-        tableau.parametre['fromprof'] = True
+        tableau.parametres['fromprof'] = True
         for i, val in enumerate(self.la) :
             act[val] = [self.lfreq[i]]
             tableau.chi[val] = [self.lchi[i]]
@@ -492,7 +520,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
     def onwordgraph(self, evt):
         word = self.getColumnText(self.GetFirstSelected(), 6)
         if self.tmpchi is None :
-            self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            self.tmpchi = os.path.join(self.Source.parametres['pathout'],'chi_%i.csv' % self.cl)
             with open(self.tmpchi, 'w') as f:
                 f.write('\n'.join([str(val) for val in self.lchi]))
         index = self.la.index(word)
@@ -508,7 +536,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
 
     def on_graph(self, evt):
         if self.tmpchi is None :
-            self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
+            self.tmpchi = os.path.join(self.Source.parametres['pathout'],'chi_%i.csv' % self.cl)
             with open(self.tmpchi, 'w') as f:
                 f.write('\n'.join([str(val) for val in self.lchi]))
         parametres = {'type' : 'clustersimitxt', 
@@ -572,10 +600,11 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
             nuces = [val[1] for val in ntab2]
             dlg.Update(3, u'concordancier...')
             ucis_txt, ucestxt = doconcorde(corpus, nuces, self.la, uci = uci)
+            items = dict([[i, '<br>'.join([ucis_txt[i], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table><br>' % ntab2[i][0], ucestxt[i]])] for i in range(0,len(ucestxt))])
             dlg.Update(4, u'texte...')
-            win = message(self, u"Segments de texte caractéristiques - Classe %i" % self.cl, (750, 600))
-            win.html = '<html>\n' + '<br>'.join(['<br>'.join([ucis_txt[i], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table>' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
-            win.HtmlPage.SetPage(win.html)
+            win = message(self, items, u"Segments de texte caractéristiques - Classe %i" % self.cl, (750, 600))
+            #win.html = '<html>\n' + '<br>'.join(['<br>'.join([ucis_txt[i], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table>' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
+            #win.HtmlPage.SetPage(win.html)
             dlg.Destroy()
             win.Show(True)
     
@@ -680,16 +709,19 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                 ucef += list(set(corpus.getlemucis(word)).intersection(uces))            
                 uci = True
         ucis_txt, ucestxt = doconcorde(corpus, ucef, ListWord, uci = uci)
-        win = message(self, title, size=(750, 600))
-        win.html = ('<html>\n<h1>%s</h1>' % ' '.join(ListWord)) + '<br>'.join(['<br>'.join([ucis_txt[i], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
-        win.HtmlPage.SetPage(win.html)
+        items = dict([[i, '<br><br>'.join([ucis_txt[i], ucestxt[i]])] for i in range(0,len(ucestxt))])
+        win = message(self, items, title, (800, 500))
+        #win = message(self, title, size=(750, 600))
+        #win.html = ('<html>\n<h1>%s</h1>' % ' '.join(ListWord)) + '<br>'.join(['<br>'.join([ucis_txt[i], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
+        #win.HtmlPage.SetPage(win.html)
         return win
 
     def OnPopupTwo(self, event):
-        corpus = self.Source.corpus
-        uces = corpus.lc[self.cl-1]
-        win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
-        win.Show(True)
+        if 'corpus' in dir(self.Source) :
+            corpus = self.Source.corpus
+            uces = corpus.lc[self.cl-1]
+            win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
+            win.Show(True)
     
     def OnPopupThree(self, event):
         corpus = self.Source.corpus
@@ -752,9 +784,11 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col
                 nb = len(ucef)
                 rep.append([corpus.getforme(forme).forme, nb])
         rep.sort(key = itemgetter(1), reverse = True)
-        win = message(self, u"Formes associées", wx.Size(300, 200))
-        win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
-        win.HtmlPage.SetPage(win.html)
+        #win = message(self, u"Formes associées", wx.Size(300, 200))
+        items = dict([[i, '\t:\t'.join([str(val) for val in forme])] for i, forme in enumerate(rep)])
+        win = message(self, items, u"Formes associées", (300, 200))
+        #win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
+        #win.HtmlPage.SetPage(win.html)
         win.Show(True)