1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
19 import wx.lib.mixins.listctrl as listmix
20 from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial, message
24 from tableau import Tableau
25 from search_tools import SearchFrame
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
41 self.Alceste = Alceste
46 line1 = profclasse.pop(0)
47 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
49 self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
50 profclasse.pop(self.lenact)
53 self.lenact = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
54 profclasse.pop(self.lenact)
56 self.lenact = len(profclasse)
58 self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
59 self.lensup = self.lensup - self.lenact
60 profclasse.pop(self.lensup)
62 self.lensup = len(profclasse) - self.lenact
63 self.lenet = len(profclasse) - (self.lenact + self.lensup)
64 # print self.lenact, self.lensup, self.lenet
65 for i, line in enumerate(classen) :
67 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
70 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
71 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
72 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
79 self.il = wx.ImageList(16, 16)
80 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
82 s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
84 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
86 #adding some attributes (colourful background for each item rows)
87 self.attr1 = wx.ListItemAttr()
88 self.attr1.SetBackgroundColour((220, 220, 220))
89 self.attrsg = wx.ListItemAttr()
90 self.attrsg.SetBackgroundColour((230, 230, 230))
91 self.attr2 = wx.ListItemAttr()
92 self.attr2.SetBackgroundColour((190, 249, 236))
93 self.attr2s = wx.ListItemAttr()
94 self.attr2s.SetBackgroundColour((211, 252, 244))
95 self.attr3 = wx.ListItemAttr()
96 self.attr3.SetBackgroundColour((245, 180, 180))
97 self.attr3s = wx.ListItemAttr()
98 self.attr3s.SetBackgroundColour((245, 190, 190))
101 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
102 self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
103 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
104 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
105 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
106 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
107 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
108 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
111 self.SetColumnWidth(0, 60)
112 self.SetColumnWidth(1, 70)
113 self.SetColumnWidth(2, 80)
114 self.SetColumnWidth(3, 100)
115 self.SetColumnWidth(4, 70)
116 self.SetColumnWidth(5, 60)
117 self.SetColumnWidth(6, 140)
118 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
120 #These two should probably be passed to init more cleanly
121 #setting the numbers of items = number of elements in the dictionary
122 self.itemDataMap = dictdata
123 self.itemIndexMap = dictdata.keys()
124 self.SetItemCount(len(dictdata))
127 listmix.ListCtrlAutoWidthMixin.__init__(self)
128 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
130 #sort by genre (column 2), A->Z ascending order (1)
131 self.SortListItems(0, 1)
134 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
135 #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
136 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
137 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
140 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
143 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
146 search_id = wx.NewId()
147 searchall_id = wx.NewId()
148 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
149 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
150 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
151 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
152 self.SetAcceleratorTable(self.accel_tbl)
156 def OnColClick(self,event):
159 def OnItemSelected(self, event):
160 self.currentItem = event.m_itemIndex
162 def OnItemActivated(self, event):
163 self.currentItem = event.m_itemIndex
165 def getColumnText(self, index, col):
166 item = self.GetItem(index, col)
167 return item.GetText()
169 def OnItemDeselected(self, evt):
171 #---------------------------------------------------
172 # These methods are callbacks for implementing the
173 # "virtualness" of the list...
175 def OnGetItemText(self, item, col):
176 index=self.itemIndexMap[item]
177 s = self.itemDataMap[index][col]
180 def OnGetItemImage(self, item):
181 index=self.itemIndexMap[item]
182 genre=self.itemDataMap[index][2]
188 elif genre=="New Age":
193 def OnGetItemAttr(self, item):
194 index=self.itemIndexMap[item]
195 if index < self.lenact :
200 elif index >= self.lenact and index < (self.lenact + self.lensup) :
205 elif index >= (self.lenact + self.lensup) :
213 #---------------------------------------------------
215 # Here's a better SortItems() method --
216 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
217 # and it knows to sort on another column if the chosen columns have the same value.
219 def SortItems(self,sorter=cmp):
220 items = list(self.itemDataMap.keys())
222 self.itemIndexMap = items
227 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
228 def GetListCtrl(self):
231 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
232 def GetSortImages(self):
233 return (self.sm_dn, self.sm_up)
235 def onsearch(self, evt) :
236 self.dial = SearchDial(self, self, 6, True)
237 self.dial.CenterOnParent()
238 self.dial.ShowModal()
241 def onsearchall(self, evt) :
242 if 'FrameSearch' not in dir(self.Source) :
243 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
244 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
245 self.dial.CenterOnParent()
246 self.dial.ShowModal()
249 def OnRightClick(self, event):
251 # only do this part the first time so the events are only bound once
253 if not hasattr(self, "popupID1"):
254 self.popupID1 = wx.NewId()
255 self.popupID2 = wx.NewId()
256 self.popupID3 = wx.NewId()
257 self.popupID4 = wx.NewId()
258 self.popupID5 = wx.NewId()
259 self.popupID6 = wx.NewId()
260 self.popupID7 = wx.NewId()
261 self.popupID8 = wx.NewId()
262 self.popupID9 = wx.NewId()
263 #self.popupID10 = wx.NewId()
264 self.popupIDgraph = wx.NewId()
265 self.idseg = wx.NewId()
266 self.iducecarac = wx.NewId()
267 self.idtablex = wx.NewId()
268 self.idchimod = wx.NewId()
269 self.idwordgraph = wx.NewId()
270 self.popup_proxe = wx.NewId()
271 self.idlexdendro = wx.NewId()
272 self.idexport = wx.NewId()
273 # self.export_classes = wx.NewId()
275 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
276 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
277 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
278 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
279 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
280 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
281 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
282 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
283 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
284 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
285 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
286 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
287 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
288 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
289 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
290 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
291 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
292 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
293 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
294 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
295 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
299 menu.Append(self.popupID1, u"Formes associées")
300 menu.Append(self.idtablex, u"Chi2 par classe")
301 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
302 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
303 menu.Append(self.idwordgraph, u"Graphe du mot")
304 #menu.Append(self.export_classes, u"Exporter le corpus...")
306 #menu.Append(self.popupID10, u"Spécificités")
308 menu_conc = wx.Menu()
309 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
310 menu_conc.Append(self.popupID3, u"dans les uce classées")
311 menu_conc.Append(self.popupID4, u"dans toutes les uce")
312 menu.AppendMenu(-1, u"Concordancier", menu_conc)
313 menu_cnrtl = wx.Menu()
314 menu_cnrtl.Append(self.popupID5, u"Définition")
315 menu_cnrtl.Append(self.popupID6, u"Etymologie")
316 menu_cnrtl.Append(self.popupID7, u"Synonymie")
317 menu_cnrtl.Append(self.popupID8, u"Antonymie")
318 menu_cnrtl.Append(self.popupID9, u"Morphologie")
319 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
320 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
321 menu.AppendSeparator()
322 menu.Append(self.popupIDgraph, u"Graphe de la classe")
323 menu.Append(self.idseg, u"Segments répétés")
324 menu.Append(self.iducecarac, u"UCE caractéristiques")
325 menu.Append(self.idexport, 'Partitionner...')
326 #menu.Append(self.popupID2, u"Concordancier")
327 # menu.Append(self.popupID3, "recharger")
331 elif 'tableau' in dir(self.Source) :
332 if not hasattr(self, "pop1"):
333 self.pop1 = wx.NewId()
334 self.pop2 = wx.NewId()
335 self.pop3 = wx.NewId()
336 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
337 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
338 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
341 menu.Append(self.pop2, u"Chi2 par classe")
342 menu.Append(self.pop3, u"Chi2 modalités de la variable")
343 menu.AppendSeparator()
344 menu.Append(self.pop1, u"Graph de la classe")
348 def onexport(self, evt) :
349 if 'corpus' in dir(self.Source):
350 corpus = self.Source.corpus
351 ClasseCHD(self.parent, corpus, self.cl)
353 def getselectedwords(self) :
354 words = [self.getColumnText(self.GetFirstSelected(), 6)]
355 last = self.GetFirstSelected()
356 while self.GetNextSelected(last) != -1:
357 last = self.GetNextSelected(last)
358 words.append(self.getColumnText(last, 6))
361 def quest_var_mod(self, evt) :
362 if 'corpus' in dir(self.Source):
363 corpus = self.Source.corpus
364 if self.var_mod == {} :
365 self.var_mod = self.Source.corpus.make_etoiles_dict()
367 corpus = self.Source.tableau
368 if self.var_mod == {} :
369 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
370 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
371 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
375 vchistable = [line[1:] for line in chistable]
376 fchistable = [line[0] for line in chistable]
377 word = self.getselectedwords()[0]
378 if len(word.split('_')) > 1 :
379 var = word.split('_')
380 words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
385 if word in fchistable :
386 tableout.append(vchistable[fchistable.index(word)])
388 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
389 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
390 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
391 file = open(tmpscript,'w')
394 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
395 win = MessageImage(self,u"Graphique", size=(700, 500))
396 win.addsaveimage(tmpgraph)
397 txt = "<img src='%s'>" % tmpgraph
398 win.HtmlPage.SetPage(txt)
401 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
402 dial.CenterOnParent()
406 def quest_simi(self, evt) :
407 tableau = self.Source.tableau
408 tab = tableau.make_table_from_classe(self.cl, self.la)
409 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
410 self.filename = os.path.join(pathout,'mat01.csv')
411 tableau.printtable(self.filename, tab)
413 paramsimi = {'coeff' : 0,
436 'cola' : (200,200,200),
444 # self.tableau.actives = {}
445 # self.tableau.lchi = self.lchi
446 # self.tableau.chi = {}
447 # for i, val in enumerate(self.la) :
448 # self.tableau.actives[val] = [self.lfreq[i]]
449 # self.tableau.chi[val] = [self.lchi[i]]
452 self.tableau.chi = {}
453 self.tableau.lchi = self.lchi
454 self.tableau.parametre['fromprof'] = True
455 for i, val in enumerate(self.la) :
456 act[val] = [self.lfreq[i]]
457 self.tableau.chi[val] = [self.lchi[i]]
458 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
460 def onwordgraph(self, evt):
461 word = self.getColumnText(self.GetFirstSelected(), 6)
462 dlg = progressbar(self, 2)
463 corpus = self.Source.corpus
464 uces = corpus.lc[self.cl-1]
465 dlg.Update(1, u'Tableau...')
466 #tab = corpus.make_table_with_classe(uces, self.la)
467 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
468 self.filename = os.path.join(pathout,'mat01.csv')
469 dlg.Update(2, u'Ecriture...')
470 #corpus.write_tab(tab, self.filename)
472 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
474 paramsimi = {'coeff' : 0,
495 'cola' : (200,200,200),
503 self.tableau = Tableau(self.parent, '')
504 self.tableau.listactives = self.la
505 self.tableau.actives = {}
506 for i, val in enumerate(self.la) :
507 self.tableau.actives[val] = [self.lfreq[i]]
508 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
510 def on_graph(self, evt):
511 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = {'type' : 'clustersimitxt', 'pathout' : self.Source.parametres['pathout']}, dlg = progressbar(self, 4))
512 #dlg = progressbar(self, 2)
513 #corpus = self.Source.corpus
514 #uces = corpus.lc[self.cl-1]
515 #dlg.Update(1, u'Tableau...')
516 ##tab = corpus.make_table_with_classe(uces, self.la)
517 #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
518 #self.filename = os.path.join(pathout,'mat01.csv')
519 #dlg.Update(2, u'Ecriture...')
520 ##corpus.write_tab(tab, self.filename)
522 #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
524 #paramsimi = {'coeff' : 0,
535 # 'coeff_temax' : 10,
542 # 'cexfromchi' : True,
546 # 'cols' : (255,0,0),
547 # 'cola' : (200,200,200),
551 # 'keep_coord' : True,
555 #self.tableau = Tableau(self.parent, '')
556 #self.tableau.listactives = self.la
557 #self.tableau.actives = {}
558 #self.tableau.lchi = self.lchi
559 #self.tableau.chi = {}
560 #self.tableau.parametre['fromprof'] = True
561 #for i, val in enumerate(self.la) :
562 # self.tableau.actives[val] = [self.lfreq[i]]
563 # self.tableau.chi[val] = [self.lchi[i]]
564 #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
566 def on_segments(self,evt) :
567 dlg = progressbar(self, 2)
568 corpus = self.Source.corpus
569 uces = corpus.lc[self.cl-1]
571 dlg.Update(1, u'Segments...')
572 for i in range(2,10) :
573 li = corpus.find_segments_in_classe(uces, i, 1000)
578 l.sort(reverse = True)
580 dlg.Update(2, 'Tri...')
581 for i, line in enumerate(l) :
582 d[i] = [line[1],line[0], line[2]]
584 para={'dico': d,'fline':first}
586 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
589 def on_uce_carac(self,evt) :
590 dial = PrefUCECarac(self, self.parent)
591 dial.CenterOnParent()
592 if dial.ShowModal() == wx.ID_OK :
593 limite = dial.spin_eff.GetValue()
594 atype = dial.radio_type.GetSelection()
595 dlg = progressbar(self,maxi = 4)
596 corpus = self.Source.corpus
597 uces = corpus.lc[self.cl-1]
598 tab = corpus.make_table_with_classe(uces, self.la)
600 dlg.Update(2, u'score...')
602 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
604 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab]
605 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
607 ntab2.sort(reverse = True)
608 ntab2 = ntab2[:limite]
609 nuces = [val[1] for val in ntab2]
610 dlg.Update(3, u'concordancier...')
611 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
612 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
615 for uce in ucestxt1 :
616 ucetxt = ' '+uce[1]+' '
617 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
619 listmot = corpus.getlems()[lem].formes
621 forme = corpus.getforme(id).forme
622 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
623 ucestxt.append(ucetxt)
624 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
625 dlg.Update(4, u'texte...')
626 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
627 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
628 win.html = '<html>\n' + '<br><br>'.join(['<br>'.join([ucis_txt[i], 'score : ' + str(ntab2[i][0]), ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
629 win.HtmlPage.SetPage(win.html)
633 def on_tablex(self, evt):
634 if 'corpus' in dir(self.Source):
635 corpus = self.Source.corpus
637 corpus = self.Source.tableau
638 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
639 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
643 vchistable = [line[1:] for line in chistable]
644 fchistable = [line[0] for line in chistable]
645 words = self.getselectedwords()
646 tableout = [vchistable[fchistable.index(word)] for word in words]
647 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
650 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
651 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
652 file = open(tmpscript,'w')
655 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
656 w = 100 + (20 * nbwords) + (100 * nbcl)
657 h = 100 + (nbwords * 15)
658 if w > 1100 : w = 1100
661 win = MessageImage(self, u"Graphique", size=(w, h))
662 win.addsaveimage(tmpgraph)
663 txt = "<img src='%s'>" % tmpgraph
664 win.HtmlPage.SetPage(txt)
667 def onlexdendro(self, evt):
668 if 'corpus' in dir(self.Source):
669 corpus = self.Source.corpus
671 corpus = self.Source.tableau
672 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
673 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
677 vchistable = [line[1:] for line in chistable]
678 fchistable = [line[0] for line in chistable]
679 words = self.getselectedwords()
680 tableout = [vchistable[fchistable.index(word)] for word in words]
681 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
682 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
683 rownames = 'c("' + '","'.join(words) + '")'
684 colnames = 'c("' + '","'.join(title) + '")'
689 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
694 height <- (30*ncol(di)) + (15*nrow(di))
695 height <- ifelse(height <= 400, 400, height)
697 open_file_graph("%s", width=width, height=height)
698 plot.dendro.lex(tree.cut1$tree.cl, di)
699 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
700 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
701 file = open(tmpscript,'w')
704 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
705 win = MessageImage(self, u"Graphique", size=(700, 500))
706 win.addsaveimage(tmpgraph)
707 txt = "<img src='%s'>" % tmpgraph
708 win.HtmlPage.SetPage(txt)
712 def make_concord(self, uces, title, color = 'red') :
713 corpus = self.Source.corpus
714 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
715 last = self.GetFirstSelected()
716 while self.GetNextSelected(last) != -1:
717 last = self.GetNextSelected(last)
718 ListWord.append(self.getColumnText(last, 6))
719 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
720 win = message(self, title, size=(750, 600))
721 toshow = ['<html>\n<H1>Concordancier</H1>\n']
722 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
725 for word in ListWord :
726 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
727 ucef = list(set(ucef))
729 res = corpus.getconcorde(ucef)
730 txt = '<br>'.join(toshow) +'<br><br>'
732 ucetxt = ' '+uce[1]+' '
733 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
734 for forme in listmot:
735 forme = corpus.getforme(forme).forme
736 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
737 txt += ucetxt + '<br><br>'
738 win.HtmlPage.SetPage(txt)
741 def OnPopupTwo(self, event):
742 corpus = self.Source.corpus
743 uces = corpus.lc[self.cl-1]
744 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
747 def OnPopupThree(self, event):
748 corpus = self.Source.corpus
749 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
750 win = self.make_concord(uces, "Concordancier - UCE classées")
753 def OnPopupFour(self, event):
754 corpus = self.Source.corpus
755 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
756 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
759 def OnPopupFive(self, event):
760 word = self.getColumnText(self.GetFirstSelected(), 6)
761 lk = "http://www.cnrtl.fr/definition/" + word
764 def OnPopupSix(self, event):
765 word = self.getColumnText(self.GetFirstSelected(), 6)
766 lk = "http://www.cnrtl.fr/etymologie/" + word
769 def OnPopupSeven(self, event):
770 word = self.getColumnText(self.GetFirstSelected(), 6)
771 lk = "http://www.cnrtl.fr/synonymie/" + word
774 def OnPopupHeight(self, event):
775 word = self.getColumnText(self.GetFirstSelected(), 6)
776 lk = "http://www.cnrtl.fr/antonymie/" + word
779 def OnPopupNine(self, event):
780 word = self.getColumnText(self.GetFirstSelected(), 6)
781 lk = "http://www.cnrtl.fr/morphologie/" + word
784 def onproxe(self, evt) :
785 word = self.getColumnText(self.GetFirstSelected(), 6)
786 lk = "http://www.cnrtl.fr/proxemie/" + word
790 #---------------------------------------------------------------------------
791 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
792 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
793 # size=wx.DefaultSize, style=0):
794 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
795 # listmix.ListCtrlAutoWidthMixin.__init__(self)
798 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
799 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
800 # self.parent = parent
801 # classe = ProfClasse
803 # self.Source = gparent
804 # if 'tableau' in dir(self.Source):
805 # self.tableau = self.Source.tableau
806 # self.Alceste = Alceste
810 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
812 # search_id = wx.NewId()
813 # searchall_id = wx.NewId()
814 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
815 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
816 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
817 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
818 # self.SetAcceleratorTable(self.accel_tbl)
820 # self.il = wx.ImageList(16, 16)
821 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
822 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
823 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
826 # self.list = ProfListctrl(self, tID,
829 # | wx.LC_EDIT_LABELS
830 # | wx.LC_SORT_ASCENDING
832 # line1 = classe.pop(0)
837 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
838 # if len(classen) == 0 :
843 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
846 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
848 # lenact = len(classen)
852 # lenet = len(classen)
855 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
857 # lensup = lensup[0] - lenact
858 # lenet = len(classen) - lensup
861 # lenet = len(classen)
864 # self.lenact = lenact
866 # debet = lenact + lensup
867 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
868 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
870 # self.PopulateList(dictdata, debet, debsup, Alceste)
872 # self.Bind(wx.EVT_SIZE, self.OnSize)
873 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
874 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
877 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
880 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
881 # self.itemDataMap = dictdata
882 # listmix.ColumnSorterMixin.__init__(self, 8)
884 ##-----------------------------------------------------------------------------------------
886 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
889 # # for normal, simple columns, you can add them like this:
890 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
891 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
892 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
893 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
894 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
895 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
896 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
897 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
899 # for key in dictdata : #.iteritems():
900 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
902 # for val in dictdata[key][1:]:
903 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
905 # self.list.SetItemData(index, key)
907 # self.list.SetColumnWidth(0, 60)
908 # self.list.SetColumnWidth(1, 70)
909 # self.list.SetColumnWidth(2, 80)
910 # self.list.SetColumnWidth(3, 100)
911 # self.list.SetColumnWidth(4, 70)
912 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
913 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
914 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
916 # # show how to change the colour of a couple items
917 # for i in range(limitsup, limit):
918 # item = self.list.GetItem(i)
919 # item.SetTextColour(wx.RED)
920 # self.list.SetItem(item)
922 # for i in range(limit, len(dictdata)):
923 # item = self.list.GetItem(i)
924 # item.SetTextColour(wx.BLUE)
925 # self.list.SetItem(item)
927 # if self.lenact != 0 :
928 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
929 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
930 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
936 # def do_greyline(self):
937 # for row in xrange(self.list.GetItemCount()):
939 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
941 # self.list.SetItemBackgroundColour(row, wx.WHITE)
944 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
945 # def GetListCtrl(self):
948 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
949 # def GetSortImages(self):
950 # return (self.sm_dn, self.sm_up)
953 # def OnRightDown(self, event):
956 # item, flags = self.list.HitTest((x, y))
958 # if flags & wx.LIST_HITTEST_ONITEM:
959 # self.list.Select(item)
964 # def getColumnText(self, index, col):
965 # item = self.list.GetItem(index, col)
966 # return item.GetText()
969 # def OnItemSelected(self, event):
970 # self.currentItem = event.m_itemIndex
973 # def onsearch(self, evt) :
974 # self.dial = SearchDial(self, self, 6, True)
975 # self.dial.CenterOnParent()
976 # self.dial.ShowModal()
977 # self.dial.Destroy()
979 # def onsearchall(self, evt) :
980 # if 'FrameSearch' not in dir(self.Source) :
981 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
982 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
983 # self.dial.CenterOnParent()
984 # self.dial.ShowModal()
985 # self.dial.Destroy()
987 # def OnRightClick(self, event):
989 # # only do this part the first time so the events are only bound once
991 # if not hasattr(self, "popupID1"):
992 # self.popupID1 = wx.NewId()
993 # self.popupID2 = wx.NewId()
994 # self.popupID3 = wx.NewId()
995 # self.popupID4 = wx.NewId()
996 # self.popupID5 = wx.NewId()
997 # self.popupID6 = wx.NewId()
998 # self.popupID7 = wx.NewId()
999 # self.popupID8 = wx.NewId()
1000 # self.popupID9 = wx.NewId()
1001 # #self.popupID10 = wx.NewId()
1002 # self.popupIDgraph = wx.NewId()
1003 # self.idseg = wx.NewId()
1004 # self.iducecarac = wx.NewId()
1005 # self.idtablex = wx.NewId()
1006 # self.idchimod = wx.NewId()
1007 # self.idwordgraph = wx.NewId()
1008 # self.popup_proxe = wx.NewId()
1009 # self.idlexdendro = wx.NewId()
1010 # self.idexport = wx.NewId()
1011 # # self.export_classes = wx.NewId()
1013 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1014 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1015 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1016 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1017 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1018 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1019 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1020 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1021 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1022 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1023 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1024 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1025 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1026 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1027 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1028 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1029 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1030 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1031 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1032 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1033 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1037 # menu.Append(self.popupID1, u"Formes associées")
1038 # menu.Append(self.idtablex, u"Chi2 par classe")
1039 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1040 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1041 # menu.Append(self.idwordgraph, u"Graphe du mot")
1042 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1044 # #menu.Append(self.popupID10, u"Spécificités")
1046 # menu_conc = wx.Menu()
1047 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1048 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1049 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1050 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1051 # menu_cnrtl = wx.Menu()
1052 # menu_cnrtl.Append(self.popupID5, u"Définition")
1053 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1054 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1055 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1056 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1057 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1058 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1059 # menu.AppendSeparator()
1060 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1061 # menu.Append(self.idseg, u"Segments répétés")
1062 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1063 # menu.Append(self.idexport, 'Partitionner...')
1064 # #menu.Append(self.popupID2, u"Concordancier")
1065 # # menu.Append(self.popupID3, "recharger")
1067 # self.PopupMenu(menu)
1069 # elif 'tableau' in dir(self.Source) :
1070 # if not hasattr(self, "pop1"):
1071 # self.pop1 = wx.NewId()
1072 # self.pop2 = wx.NewId()
1073 # self.pop3 = wx.NewId()
1074 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1075 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1076 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1079 # menu.Append(self.pop2, u"Chi2 par classe")
1080 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1081 # menu.AppendSeparator()
1082 # menu.Append(self.pop1, u"Graph de la classe")
1083 # self.PopupMenu(menu)
1086 # def onexport(self, evt) :
1087 # if 'corpus' in dir(self.Source):
1088 # corpus = self.Source.corpus
1089 # ClasseCHD(self.parent, corpus, self.cl)
1091 # def quest_var_mod(self, evt) :
1092 # if 'corpus' in dir(self.Source):
1093 # corpus = self.Source.corpus
1094 # if self.var_mod == {} :
1095 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1097 # corpus = self.Source.tableau
1098 # if self.var_mod == {} :
1099 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1100 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1101 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1102 # title = chistable[0]
1105 # vchistable = [line[1:] for line in chistable]
1106 # fchistable = [line[0] for line in chistable]
1107 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1108 # if len(word.split('_')) > 1 :
1109 # var = word.split('_')[0]
1110 # words = [word for word in self.var_mod[var]]
1114 # for word in words :
1115 # if word in fchistable :
1116 # tableout.append(vchistable[fchistable.index(word)])
1117 # kwords.append(word)
1118 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1119 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1120 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1121 # file = open(tmpscript,'w')
1124 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1125 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1126 # win.addsaveimage(tmpgraph)
1127 # txt = "<img src='%s'>" % tmpgraph
1128 # win.HtmlPage.SetPage(txt)
1131 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1132 # dial.CenterOnParent()
1136 # def quest_simi(self, evt) :
1137 # tableau = self.Source.tableau
1138 # tab = tableau.make_table_from_classe(self.cl, self.la)
1139 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1140 # self.filename = os.path.join(pathout,'mat01.csv')
1141 # tableau.printtable(self.filename, tab)
1143 # paramsimi = {'coeff' : 0,
1148 # 'coeff_tv_nb' : 0,
1153 # 'coeff_temin' : 1,
1154 # 'coeff_temax' : 10,
1161 # 'cexfromchi' : True,
1162 # 'sfromchi': False,
1165 # 'cols' : (255,0,0),
1166 # 'cola' : (200,200,200),
1170 # 'keep_coord' : True,
1174 ## self.tableau.actives = {}
1175 ## self.tableau.lchi = self.lchi
1176 ## self.tableau.chi = {}
1177 ## for i, val in enumerate(self.la) :
1178 ## self.tableau.actives[val] = [self.lfreq[i]]
1179 ## self.tableau.chi[val] = [self.lchi[i]]
1182 # self.tableau.chi = {}
1183 # self.tableau.lchi = self.lchi
1184 # self.tableau.parametre['fromprof'] = True
1185 # for i, val in enumerate(self.la) :
1186 # act[val] = [self.lfreq[i]]
1187 # self.tableau.chi[val] = [self.lchi[i]]
1188 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1190 # def onwordgraph(self, evt):
1191 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1192 # dlg = progressbar(self, 2)
1193 # corpus = self.Source.corpus
1194 # uces = corpus.lc[self.cl-1]
1195 # dlg.Update(1, u'Tableau...')
1196 # #tab = corpus.make_table_with_classe(uces, self.la)
1197 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1198 # self.filename = os.path.join(pathout,'mat01.csv')
1199 # dlg.Update(2, u'Ecriture...')
1200 # #corpus.write_tab(tab, self.filename)
1202 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1204 # paramsimi = {'coeff' : 0,
1209 # 'coeff_tv_nb' : 0,
1214 # 'coeff_temin' : 1,
1215 # 'coeff_temax' : 10,
1224 # 'cols' : (255,0,0),
1225 # 'cola' : (200,200,200),
1229 # 'keep_coord' : True,
1233 # self.tableau = Tableau(self.parent, '')
1234 # self.tableau.listactives = self.la
1235 # self.tableau.actives = {}
1236 # for i, val in enumerate(self.la) :
1237 # self.tableau.actives[val] = [self.lfreq[i]]
1238 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1241 def OnPopupOne(self, event):
1242 corpus = self.Source.corpus
1243 #print 'ATTENTION PRINT ET TABLE'
1244 #corpus.make_et_table()
1245 word = self.getColumnText(self.GetFirstSelected(), 6)
1246 lems = corpus.getlems()
1247 uces = corpus.lc[self.cl-1]
1249 #FIXME : donner aussi eff reel a la place de nb uce
1250 for forme in lems[word].formes :
1251 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1252 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1255 rep.append([corpus.getforme(forme).forme, nb])
1256 win = message(self, u"Formes associées", wx.Size(300, 200))
1257 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1258 win.HtmlPage.SetPage(win.html)
1261 # def on_graph(self, evt):
1262 # dlg = progressbar(self, 2)
1263 # corpus = self.Source.corpus
1264 # uces = corpus.lc[self.cl-1]
1265 # dlg.Update(1, u'Tableau...')
1266 # #tab = corpus.make_table_with_classe(uces, self.la)
1267 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1268 # self.filename = os.path.join(pathout,'mat01.csv')
1269 # dlg.Update(2, u'Ecriture...')
1270 # #corpus.write_tab(tab, self.filename)
1272 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1274 # paramsimi = {'coeff' : 0,
1279 # 'coeff_tv_nb' : 0,
1284 # 'coeff_temin' : 1,
1285 # 'coeff_temax' : 10,
1292 # 'cexfromchi' : True,
1293 # 'sfromchi': False,
1296 # 'cols' : (255,0,0),
1297 # 'cola' : (200,200,200),
1301 # 'keep_coord' : True,
1305 # self.tableau = Tableau(self.parent, '')
1306 # self.tableau.listactives = self.la
1307 # self.tableau.actives = {}
1308 # self.tableau.lchi = self.lchi
1309 # self.tableau.chi = {}
1310 # self.tableau.parametre['fromprof'] = True
1311 # for i, val in enumerate(self.la) :
1312 # self.tableau.actives[val] = [self.lfreq[i]]
1313 # self.tableau.chi[val] = [self.lchi[i]]
1314 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1316 # def on_segments(self,evt) :
1317 # dlg = progressbar(self, 2)
1318 # corpus = self.Source.corpus
1319 # uces = corpus.lc[self.cl-1]
1321 # dlg.Update(1, u'Segments...')
1322 # for i in range(2,10) :
1323 # li = corpus.find_segments_in_classe(uces, i, 1000)
1328 # l.sort(reverse = True)
1330 # dlg.Update(2, 'Tri...')
1331 # for i, line in enumerate(l) :
1332 # d[i] = [line[1],line[0], line[2]]
1333 # first = ['','','']
1334 # para={'dico': d,'fline':first}
1336 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1339 # def on_uce_carac(self,evt) :
1340 # dial = PrefUCECarac(self, self.parent)
1341 # dial.CenterOnParent()
1342 # if dial.ShowModal() == wx.ID_OK :
1343 # limite = dial.spin_eff.GetValue()
1344 # atype = dial.radio_type.GetSelection()
1345 # dlg = progressbar(self,maxi = 4)
1346 # corpus = self.Source.corpus
1347 # uces = corpus.lc[self.cl-1]
1348 # tab = corpus.make_table_with_classe(uces, self.la)
1350 # dlg.Update(2, u'score...')
1352 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1354 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab]
1355 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1357 # ntab2.sort(reverse = True)
1358 # ntab2 = ntab2[:limite]
1359 # nuces = [val[1] for val in ntab2]
1360 # dlg.Update(3, u'concordancier...')
1361 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1362 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1365 # for uce in ucestxt1 :
1366 # ucetxt = ' '+uce[1]+' '
1367 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1368 # for lem in self.la :
1369 # listmot = corpus.getlems()[lem].formes
1370 # for id in listmot :
1371 # forme = corpus.getforme(id).forme
1372 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1373 # ucestxt.append(ucetxt)
1374 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1375 # dlg.Update(4, u'texte...')
1376 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1377 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1378 # win.html = '<html>\n' + '<br><br>'.join(['<br>'.join([ucis_txt[i], 'score : ' + str(ntab2[i][0]), ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
1379 # win.HtmlPage.SetPage(win.html)
1383 # def on_tablex(self, evt):
1384 # if 'corpus' in dir(self.Source):
1385 # corpus = self.Source.corpus
1387 # corpus = self.Source.tableau
1388 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1389 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1390 # title = chistable[0]
1393 # vchistable = [line[1:] for line in chistable]
1394 # fchistable = [line[0] for line in chistable]
1395 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1396 # tableout = [vchistable[fchistable.index(words[0])]]
1397 # last = self.list.GetFirstSelected()
1398 # while self.list.GetNextSelected(last) != -1:
1399 # last = self.list.GetNextSelected(last)
1400 # word = self.getColumnText(last, 6)
1401 # words.append(word)
1402 # tableout.append(vchistable[fchistable.index(word)])
1403 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1405 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1406 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1407 # file = open(tmpscript,'w')
1411 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1412 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1413 # win.addsaveimage(tmpgraph)
1414 # txt = "<img src='%s'>" % tmpgraph
1415 # win.HtmlPage.SetPage(txt)
1418 # def onlexdendro(self, evt):
1419 # if 'corpus' in dir(self.Source):
1420 # corpus = self.Source.corpus
1422 # corpus = self.Source.tableau
1423 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1424 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1425 # title = chistable[0]
1428 # vchistable = [line[1:] for line in chistable]
1429 # fchistable = [line[0] for line in chistable]
1430 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1431 # tableout = [vchistable[fchistable.index(words[0])]]
1432 # last = self.list.GetFirstSelected()
1433 # while self.list.GetNextSelected(last) != -1:
1434 # last = self.list.GetNextSelected(last)
1435 # word = self.getColumnText(last, 6)
1436 # words.append(word)
1437 # tableout.append(vchistable[fchistable.index(word)])
1438 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1439 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1440 # rownames = 'c("' + '","'.join(words) + '")'
1441 # colnames = 'c("' + '","'.join(title) + '")'
1443 # rownb = len(words)
1446 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1448 # colnames(di) <- %s
1451 # height <- (30*ncol(di)) + (15*nrow(di))
1452 # height <- ifelse(height <= 400, 400, height)
1454 # open_file_graph("%s", width=width, height=height)
1455 # plot.dendro.lex(tree.cut1$tree.cl, di)
1456 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1457 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1458 # file = open(tmpscript,'w')
1461 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1462 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1463 # win.addsaveimage(tmpgraph)
1464 # txt = "<img src='%s'>" % tmpgraph
1465 # win.HtmlPage.SetPage(txt)
1469 # def make_concord(self, uces, title, color = 'red') :
1470 # corpus = self.Source.corpus
1471 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1472 # last = self.list.GetFirstSelected()
1473 # while self.list.GetNextSelected(last) != -1:
1474 # last = self.list.GetNextSelected(last)
1475 # ListWord.append(self.getColumnText(last, 6))
1476 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1477 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1478 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1479 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1482 # for word in ListWord :
1483 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1484 # ucef = list(set(ucef))
1486 # res = corpus.getconcorde(ucef)
1487 # txt = '<br>'.join(toshow) +'<br><br>'
1489 # ucetxt = ' '+uce[1]+' '
1490 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1491 # for forme in listmot:
1492 # forme = corpus.getforme(forme).forme
1493 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1494 # txt += ucetxt + '<br><br>'
1495 # win.HtmlPage.SetPage(txt)
1498 # def OnPopupTwo(self, event):
1499 # corpus = self.Source.corpus
1500 # uces = corpus.lc[self.cl-1]
1501 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1504 # def OnPopupThree(self, event):
1505 # corpus = self.Source.corpus
1506 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1507 # win = self.make_concord(uces, "Concordancier - UCE classées")
1510 # def OnPopupFour(self, event):
1511 # corpus = self.Source.corpus
1512 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1513 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1516 # def OnPopupFive(self, event):
1517 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1518 # lk = "http://www.cnrtl.fr/definition/" + word
1519 # webbrowser.open(lk)
1521 # def OnPopupSix(self, event):
1522 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1523 # lk = "http://www.cnrtl.fr/etymologie/" + word
1524 # webbrowser.open(lk)
1526 # def OnPopupSeven(self, event):
1527 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1528 # lk = "http://www.cnrtl.fr/synonymie/" + word
1529 # webbrowser.open(lk)
1531 # def OnPopupHeight(self, event):
1532 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1533 # lk = "http://www.cnrtl.fr/antonymie/" + word
1534 # webbrowser.open(lk)
1536 # def OnPopupNine(self, event):
1537 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1538 # lk = "http://www.cnrtl.fr/morphologie/" + word
1539 # webbrowser.open(lk)
1541 # def onproxe(self, evt) :
1542 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1543 # lk = "http://www.cnrtl.fr/proxemie/" + word
1544 # webbrowser.open(lk)
1546 # def OnSize(self, event):
1547 # w, h = self.GetClientSizeTuple()
1548 # self.list.SetDimensions(0, 0, w, h)
1550 # def OnColClick(self, event):
1551 # self.do_greyline()
1554 #class wliste(wx.Frame):
1555 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1556 # wx.Frame.__init__(self, parent, id)
1557 # self.liste = ListForSpec(self, parent, d, fline)
1558 # self.button_1 = wx.Button(self, -1, "Fermer")
1559 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1560 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1561 # self.__do_layout()
1563 # def __do_layout(self):
1564 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1565 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1566 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1567 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1568 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1569 # self.SetAutoLayout(True)
1570 # self.SetSizer(sizer_1)
1573 # def OnCloseMe(self, event):
1576 # def OnCloseWindow(self, event):
1579 #class message(wx.Dialog):
1580 # def __init__(self, parent, title, size, save = True):
1581 # wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1583 # self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1586 # self.HtmlPage=wx.html.HtmlWindow(self, -1)
1587 # self.HtmlPage.SetMinSize( size )
1588 # if "gtk2" in wx.PlatformInfo:
1589 # self.HtmlPage.SetStandardFonts()
1590 # self.HtmlPage.SetFonts('Courier','Courier')
1592 # self.button_1 = wx.Button(self, wx.ID_CANCEL)
1594 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1596 # self.button_2 = wx.Button(self, wx.ID_SAVE)
1597 # self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1598 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1599 # self.__do_layout()
1601 # def __do_layout(self):
1602 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1603 # sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1604 # m_sdbSizer1 = wx.StdDialogButtonSizer()
1605 # m_sdbSizer1.AddButton( self.button_1 )
1607 # m_sdbSizer1.AddButton( self.button_2 )
1608 # m_sdbSizer1.Realize()
1609 # sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1610 # self.SetSizer(sizer_2)
1612 # sizer_2.Fit( self )
1614 # def OnSavePage(self, evt) :
1615 # dlg = wx.FileDialog(
1616 # self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1617 # defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1619 # dlg.SetFilterIndex(2)
1620 # dlg.CenterOnParent()
1621 # if dlg.ShowModal() == wx.ID_OK:
1622 # path = dlg.GetPath()
1623 # with open(path, 'w') as f :
1624 # f.write(self.html)
1626 # def OnCloseMe(self, event):
1629 # def OnCloseWindow(self, event):