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
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)
52 self.lenact = len(profclasse)
54 self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
55 self.lensup = self.lensup - self.lenact
56 profclasse.pop(self.lensup)
59 self.lenet = len(profclasse) - (self.lenact + self.lensup)
60 # print self.lenact, self.lensup, self.lenet
61 for i, line in enumerate(classen) :
63 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
66 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
67 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
68 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
75 self.il = wx.ImageList(16, 16)
76 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
78 s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
80 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
82 #adding some attributes (colourful background for each item rows)
83 self.attr1 = wx.ListItemAttr()
84 self.attr1.SetBackgroundColour((220, 220, 220))
85 self.attrsg = wx.ListItemAttr()
86 self.attrsg.SetBackgroundColour((230, 230, 230))
87 self.attr2 = wx.ListItemAttr()
88 self.attr2.SetBackgroundColour((190, 249, 236))
89 self.attr2s = wx.ListItemAttr()
90 self.attr2s.SetBackgroundColour((211, 252, 244))
91 self.attr3 = wx.ListItemAttr()
92 self.attr3.SetBackgroundColour((245, 180, 180))
93 self.attr3s = wx.ListItemAttr()
94 self.attr3s.SetBackgroundColour((245, 190, 190))
97 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
98 self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
99 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
100 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
101 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
102 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
103 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
104 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
107 self.SetColumnWidth(0, 60)
108 self.SetColumnWidth(1, 70)
109 self.SetColumnWidth(2, 80)
110 self.SetColumnWidth(3, 100)
111 self.SetColumnWidth(4, 70)
112 self.SetColumnWidth(5, 60)
113 self.SetColumnWidth(6, 140)
114 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
116 #These two should probably be passed to init more cleanly
117 #setting the numbers of items = number of elements in the dictionary
118 self.itemDataMap = dictdata
119 self.itemIndexMap = dictdata.keys()
120 self.SetItemCount(len(dictdata))
123 listmix.ListCtrlAutoWidthMixin.__init__(self)
124 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
126 #sort by genre (column 2), A->Z ascending order (1)
127 self.SortListItems(0, 1)
130 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
131 #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
132 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
133 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
136 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
139 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
142 search_id = wx.NewId()
143 searchall_id = wx.NewId()
144 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
145 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
146 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
147 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
148 self.SetAcceleratorTable(self.accel_tbl)
152 def OnColClick(self,event):
155 def OnItemSelected(self, event):
156 self.currentItem = event.m_itemIndex
157 #print 'OnItemSelected: "%s", "%s", "%s", "%s"\n' % (self.currentItem, self.GetItemText(self.currentItem), self.getColumnText(self.currentItem, 1), self.getColumnText(self.currentItem, 2))
158 #self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
160 # self.GetItemText(self.currentItem),
161 # self.getColumnText(self.currentItem, 1),
162 # self.getColumnText(self.currentItem, 2)))
164 def OnItemActivated(self, event):
165 self.currentItem = event.m_itemIndex
166 #print "OnItemActivated: %s\nTopItem: %s\n" % (self.GetItemText(self.currentItem), self.GetTopItem())
167 #self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
168 # (self.GetItemText(self.currentItem), self.GetTopItem()))
170 def getColumnText(self, index, col):
171 item = self.GetItem(index, col)
172 return item.GetText()
174 def OnItemDeselected(self, evt):
176 #self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
179 #---------------------------------------------------
180 # These methods are callbacks for implementing the
181 # "virtualness" of the list...
183 def OnGetItemText(self, item, col):
184 index=self.itemIndexMap[item]
185 s = self.itemDataMap[index][col]
188 def OnGetItemImage(self, item):
189 index=self.itemIndexMap[item]
190 genre=self.itemDataMap[index][2]
196 elif genre=="New Age":
201 def OnGetItemAttr(self, item):
202 index=self.itemIndexMap[item]
203 #genre=self.itemDataMap[index][2]
204 if index < self.lenact :
209 elif index >= self.lenact and index < (self.lenact + self.lensup) :
214 elif index >= (self.lenact + self.lensup) :
224 # elif genre=="Jazz":
226 # elif genre=="New Age":
231 #---------------------------------------------------
233 # Here's a better SortItems() method --
234 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
235 # and it knows to sort on another column if the chosen columns have the same value.
237 def SortItems(self,sorter=cmp):
238 items = list(self.itemDataMap.keys())
240 self.itemIndexMap = items
245 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
246 def GetListCtrl(self):
249 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
250 def GetSortImages(self):
251 return (self.sm_dn, self.sm_up)
253 def onsearch(self, evt) :
254 self.dial = SearchDial(self, self, 6, True)
255 self.dial.CenterOnParent()
256 self.dial.ShowModal()
259 def onsearchall(self, evt) :
260 if 'FrameSearch' not in dir(self.Source) :
261 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
262 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
263 self.dial.CenterOnParent()
264 self.dial.ShowModal()
267 def OnRightClick(self, event):
269 # only do this part the first time so the events are only bound once
271 if not hasattr(self, "popupID1"):
272 self.popupID1 = wx.NewId()
273 self.popupID2 = wx.NewId()
274 self.popupID3 = wx.NewId()
275 self.popupID4 = wx.NewId()
276 self.popupID5 = wx.NewId()
277 self.popupID6 = wx.NewId()
278 self.popupID7 = wx.NewId()
279 self.popupID8 = wx.NewId()
280 self.popupID9 = wx.NewId()
281 #self.popupID10 = wx.NewId()
282 self.popupIDgraph = wx.NewId()
283 self.idseg = wx.NewId()
284 self.iducecarac = wx.NewId()
285 self.idtablex = wx.NewId()
286 self.idchimod = wx.NewId()
287 self.idwordgraph = wx.NewId()
288 self.popup_proxe = wx.NewId()
289 self.idlexdendro = wx.NewId()
290 self.idexport = wx.NewId()
291 # self.export_classes = wx.NewId()
293 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
294 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
295 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
296 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
297 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
298 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
299 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
300 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
301 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
302 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
303 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
304 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
305 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
306 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
307 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
308 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
309 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
310 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
311 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
312 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
313 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
317 menu.Append(self.popupID1, u"Formes associées")
318 menu.Append(self.idtablex, u"Chi2 par classe")
319 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
320 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
321 menu.Append(self.idwordgraph, u"Graphe du mot")
322 #menu.Append(self.export_classes, u"Exporter le corpus...")
324 #menu.Append(self.popupID10, u"Spécificités")
326 menu_conc = wx.Menu()
327 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
328 menu_conc.Append(self.popupID3, u"dans les uce classées")
329 menu_conc.Append(self.popupID4, u"dans toutes les uce")
330 menu.AppendMenu(-1, u"Concordancier", menu_conc)
331 menu_cnrtl = wx.Menu()
332 menu_cnrtl.Append(self.popupID5, u"Définition")
333 menu_cnrtl.Append(self.popupID6, u"Etymologie")
334 menu_cnrtl.Append(self.popupID7, u"Synonymie")
335 menu_cnrtl.Append(self.popupID8, u"Antonymie")
336 menu_cnrtl.Append(self.popupID9, u"Morphologie")
337 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
338 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
339 menu.AppendSeparator()
340 menu.Append(self.popupIDgraph, u"Graphe de la classe")
341 menu.Append(self.idseg, u"Segments répétés")
342 menu.Append(self.iducecarac, u"UCE caractéristiques")
343 menu.Append(self.idexport, 'Partitionner...')
344 #menu.Append(self.popupID2, u"Concordancier")
345 # menu.Append(self.popupID3, "recharger")
349 elif 'tableau' in dir(self.Source) :
350 if not hasattr(self, "pop1"):
351 self.pop1 = wx.NewId()
352 self.pop2 = wx.NewId()
353 self.pop3 = wx.NewId()
354 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
355 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
356 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
359 menu.Append(self.pop2, u"Chi2 par classe")
360 menu.Append(self.pop3, u"Chi2 modalités de la variable")
361 menu.AppendSeparator()
362 menu.Append(self.pop1, u"Graph de la classe")
366 def onexport(self, evt) :
367 if 'corpus' in dir(self.Source):
368 corpus = self.Source.corpus
369 ClasseCHD(self.parent, corpus, self.cl)
371 def getselectedwords(self) :
372 words = [self.getColumnText(self.GetFirstSelected(), 6)]
373 last = self.GetFirstSelected()
374 while self.GetNextSelected(last) != -1:
375 last = self.GetNextSelected(last)
376 words.append(self.getColumnText(last, 6))
379 def quest_var_mod(self, evt) :
380 if 'corpus' in dir(self.Source):
381 corpus = self.Source.corpus
382 if self.var_mod == {} :
383 self.var_mod = self.Source.corpus.make_etoiles_dict()
385 corpus = self.Source.tableau
386 if self.var_mod == {} :
387 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
388 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
389 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
393 vchistable = [line[1:] for line in chistable]
394 fchistable = [line[0] for line in chistable]
395 word = self.getselectedwords()[0]
396 if len(word.split('_')) > 1 :
397 var = word.split('_')
398 words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
403 if word in fchistable :
404 tableout.append(vchistable[fchistable.index(word)])
406 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
407 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
408 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
409 file = open(tmpscript,'w')
412 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
413 win = MessageImage(self,u"Graphique", size=(700, 500))
414 win.addsaveimage(tmpgraph)
415 txt = "<img src='%s'>" % tmpgraph
416 win.HtmlPage.SetPage(txt)
419 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
420 dial.CenterOnParent()
424 def quest_simi(self, evt) :
425 tableau = self.Source.tableau
426 tab = tableau.make_table_from_classe(self.cl, self.la)
427 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
428 self.filename = os.path.join(pathout,'mat01.csv')
429 tableau.printtable(self.filename, tab)
431 paramsimi = {'coeff' : 0,
454 'cola' : (200,200,200),
462 # self.tableau.actives = {}
463 # self.tableau.lchi = self.lchi
464 # self.tableau.chi = {}
465 # for i, val in enumerate(self.la) :
466 # self.tableau.actives[val] = [self.lfreq[i]]
467 # self.tableau.chi[val] = [self.lchi[i]]
470 self.tableau.chi = {}
471 self.tableau.lchi = self.lchi
472 self.tableau.parametre['fromprof'] = True
473 for i, val in enumerate(self.la) :
474 act[val] = [self.lfreq[i]]
475 self.tableau.chi[val] = [self.lchi[i]]
476 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
478 def onwordgraph(self, evt):
479 word = self.getColumnText(self.GetFirstSelected(), 6)
480 dlg = progressbar(self, 2)
481 corpus = self.Source.corpus
482 uces = corpus.lc[self.cl-1]
483 dlg.Update(1, u'Tableau...')
484 #tab = corpus.make_table_with_classe(uces, self.la)
485 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
486 self.filename = os.path.join(pathout,'mat01.csv')
487 dlg.Update(2, u'Ecriture...')
488 #corpus.write_tab(tab, self.filename)
490 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
492 paramsimi = {'coeff' : 0,
513 'cola' : (200,200,200),
521 self.tableau = Tableau(self.parent, '')
522 self.tableau.listactives = self.la
523 self.tableau.actives = {}
524 for i, val in enumerate(self.la) :
525 self.tableau.actives[val] = [self.lfreq[i]]
526 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
528 def on_graph(self, evt):
529 dlg = progressbar(self, 2)
530 corpus = self.Source.corpus
531 uces = corpus.lc[self.cl-1]
532 dlg.Update(1, u'Tableau...')
533 #tab = corpus.make_table_with_classe(uces, self.la)
534 pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
535 self.filename = os.path.join(pathout,'mat01.csv')
536 dlg.Update(2, u'Ecriture...')
537 #corpus.write_tab(tab, self.filename)
539 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
541 paramsimi = {'coeff' : 0,
564 'cola' : (200,200,200),
572 self.tableau = Tableau(self.parent, '')
573 self.tableau.listactives = self.la
574 self.tableau.actives = {}
575 self.tableau.lchi = self.lchi
576 self.tableau.chi = {}
577 self.tableau.parametre['fromprof'] = True
578 for i, val in enumerate(self.la) :
579 self.tableau.actives[val] = [self.lfreq[i]]
580 self.tableau.chi[val] = [self.lchi[i]]
581 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
583 def on_segments(self,evt) :
584 dlg = progressbar(self, 2)
585 corpus = self.Source.corpus
586 uces = corpus.lc[self.cl-1]
588 dlg.Update(1, u'Segments...')
589 for i in range(2,10) :
590 li = corpus.find_segments_in_classe(uces, i, 1000)
595 l.sort(reverse = True)
597 dlg.Update(2, 'Tri...')
598 for i, line in enumerate(l) :
599 d[i] = [line[1],line[0], line[2]]
601 para={'dico': d,'fline':first}
603 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
606 def on_uce_carac(self,evt) :
607 dial = PrefUCECarac(self, self.parent)
608 dial.CenterOnParent()
609 if dial.ShowModal() == wx.ID_OK :
610 limite = dial.spin_eff.GetValue()
611 atype = dial.radio_type.GetSelection()
612 dlg = progressbar(self,maxi = 4)
613 corpus = self.Source.corpus
614 uces = corpus.lc[self.cl-1]
615 tab = corpus.make_table_with_classe(uces, self.la)
617 dlg.Update(2, u'score...')
619 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
621 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]
622 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
624 ntab2.sort(reverse = True)
625 ntab2 = ntab2[:limite]
626 nuces = [val[1] for val in ntab2]
627 dlg.Update(3, u'concordancier...')
628 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
629 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
632 for uce in ucestxt1 :
633 ucetxt = ' '+uce[1]+' '
634 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
636 listmot = corpus.getlems()[lem].formes
638 forme = corpus.getforme(id).forme
639 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
640 ucestxt.append(ucetxt)
641 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
642 dlg.Update(4, u'texte...')
643 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
644 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
645 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>'
646 win.HtmlPage.SetPage(win.html)
650 def on_tablex(self, evt):
651 if 'corpus' in dir(self.Source):
652 corpus = self.Source.corpus
654 corpus = self.Source.tableau
655 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
656 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
660 vchistable = [line[1:] for line in chistable]
661 fchistable = [line[0] for line in chistable]
662 words = self.getselectedwords()
663 tableout = [vchistable[fchistable.index(word)] for word in words]
664 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
667 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
668 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
669 file = open(tmpscript,'w')
672 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
673 w = 100 + (20 * nbwords) + (100 * nbcl)
674 h = 100 + (nbwords * 15)
675 if w > 1100 : w = 1100
678 win = MessageImage(self, u"Graphique", size=(w, h))
679 win.addsaveimage(tmpgraph)
680 txt = "<img src='%s'>" % tmpgraph
681 win.HtmlPage.SetPage(txt)
684 def onlexdendro(self, evt):
685 if 'corpus' in dir(self.Source):
686 corpus = self.Source.corpus
688 corpus = self.Source.tableau
689 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
690 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
694 vchistable = [line[1:] for line in chistable]
695 fchistable = [line[0] for line in chistable]
696 words = self.getselectedwords()
697 tableout = [vchistable[fchistable.index(word)] for word in words]
698 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
699 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
700 rownames = 'c("' + '","'.join(words) + '")'
701 colnames = 'c("' + '","'.join(title) + '")'
706 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
711 height <- (30*ncol(di)) + (15*nrow(di))
712 height <- ifelse(height <= 400, 400, height)
714 open_file_graph("%s", width=width, height=height)
715 plot.dendro.lex(tree.cut1$tree.cl, di)
716 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
717 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
718 file = open(tmpscript,'w')
721 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
722 win = MessageImage(self, u"Graphique", size=(700, 500))
723 win.addsaveimage(tmpgraph)
724 txt = "<img src='%s'>" % tmpgraph
725 win.HtmlPage.SetPage(txt)
729 def make_concord(self, uces, title, color = 'red') :
730 corpus = self.Source.corpus
731 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
732 last = self.GetFirstSelected()
733 while self.GetNextSelected(last) != -1:
734 last = self.GetNextSelected(last)
735 ListWord.append(self.getColumnText(last, 6))
736 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
737 win = message(self, title, size=(750, 600))
738 toshow = ['<html>\n<H1>Concordancier</H1>\n']
739 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
742 for word in ListWord :
743 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
744 ucef = list(set(ucef))
746 res = corpus.getconcorde(ucef)
747 txt = '<br>'.join(toshow) +'<br><br>'
749 ucetxt = ' '+uce[1]+' '
750 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
751 for forme in listmot:
752 forme = corpus.getforme(forme).forme
753 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
754 txt += ucetxt + '<br><br>'
755 win.HtmlPage.SetPage(txt)
758 def OnPopupTwo(self, event):
759 corpus = self.Source.corpus
760 uces = corpus.lc[self.cl-1]
761 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
764 def OnPopupThree(self, event):
765 corpus = self.Source.corpus
766 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
767 win = self.make_concord(uces, "Concordancier - UCE classées")
770 def OnPopupFour(self, event):
771 corpus = self.Source.corpus
772 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
773 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
776 def OnPopupFive(self, event):
777 word = self.getColumnText(self.GetFirstSelected(), 6)
778 lk = "http://www.cnrtl.fr/definition/" + word
781 def OnPopupSix(self, event):
782 word = self.getColumnText(self.GetFirstSelected(), 6)
783 lk = "http://www.cnrtl.fr/etymologie/" + word
786 def OnPopupSeven(self, event):
787 word = self.getColumnText(self.GetFirstSelected(), 6)
788 lk = "http://www.cnrtl.fr/synonymie/" + word
791 def OnPopupHeight(self, event):
792 word = self.getColumnText(self.GetFirstSelected(), 6)
793 lk = "http://www.cnrtl.fr/antonymie/" + word
796 def OnPopupNine(self, event):
797 word = self.getColumnText(self.GetFirstSelected(), 6)
798 lk = "http://www.cnrtl.fr/morphologie/" + word
801 def onproxe(self, evt) :
802 word = self.getColumnText(self.GetFirstSelected(), 6)
803 lk = "http://www.cnrtl.fr/proxemie/" + word
807 #---------------------------------------------------------------------------
808 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
809 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
810 # size=wx.DefaultSize, style=0):
811 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
812 # listmix.ListCtrlAutoWidthMixin.__init__(self)
815 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
816 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
817 # self.parent = parent
818 # classe = ProfClasse
820 # self.Source = gparent
821 # if 'tableau' in dir(self.Source):
822 # self.tableau = self.Source.tableau
823 # self.Alceste = Alceste
827 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
829 # search_id = wx.NewId()
830 # searchall_id = wx.NewId()
831 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
832 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
833 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
834 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
835 # self.SetAcceleratorTable(self.accel_tbl)
837 # self.il = wx.ImageList(16, 16)
838 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
839 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
840 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
843 # self.list = ProfListctrl(self, tID,
846 # | wx.LC_EDIT_LABELS
847 # | wx.LC_SORT_ASCENDING
849 # line1 = classe.pop(0)
854 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
855 # if len(classen) == 0 :
860 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
863 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
865 # lenact = len(classen)
869 # lenet = len(classen)
872 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
874 # lensup = lensup[0] - lenact
875 # lenet = len(classen) - lensup
878 # lenet = len(classen)
881 # self.lenact = lenact
883 # debet = lenact + lensup
884 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
885 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
887 # self.PopulateList(dictdata, debet, debsup, Alceste)
889 # self.Bind(wx.EVT_SIZE, self.OnSize)
890 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
891 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
894 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
897 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
898 # self.itemDataMap = dictdata
899 # listmix.ColumnSorterMixin.__init__(self, 8)
901 ##-----------------------------------------------------------------------------------------
903 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
906 # # for normal, simple columns, you can add them like this:
907 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
908 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
909 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
910 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
911 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
912 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
913 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
914 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
916 # for key in dictdata : #.iteritems():
917 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
919 # for val in dictdata[key][1:]:
920 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
922 # self.list.SetItemData(index, key)
924 # self.list.SetColumnWidth(0, 60)
925 # self.list.SetColumnWidth(1, 70)
926 # self.list.SetColumnWidth(2, 80)
927 # self.list.SetColumnWidth(3, 100)
928 # self.list.SetColumnWidth(4, 70)
929 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
930 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
931 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
933 # # show how to change the colour of a couple items
934 # for i in range(limitsup, limit):
935 # item = self.list.GetItem(i)
936 # item.SetTextColour(wx.RED)
937 # self.list.SetItem(item)
939 # for i in range(limit, len(dictdata)):
940 # item = self.list.GetItem(i)
941 # item.SetTextColour(wx.BLUE)
942 # self.list.SetItem(item)
944 # if self.lenact != 0 :
945 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
946 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
947 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
953 # def do_greyline(self):
954 # for row in xrange(self.list.GetItemCount()):
956 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
958 # self.list.SetItemBackgroundColour(row, wx.WHITE)
961 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
962 # def GetListCtrl(self):
965 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
966 # def GetSortImages(self):
967 # return (self.sm_dn, self.sm_up)
970 # def OnRightDown(self, event):
973 # item, flags = self.list.HitTest((x, y))
975 # if flags & wx.LIST_HITTEST_ONITEM:
976 # self.list.Select(item)
981 # def getColumnText(self, index, col):
982 # item = self.list.GetItem(index, col)
983 # return item.GetText()
986 # def OnItemSelected(self, event):
987 # self.currentItem = event.m_itemIndex
990 # def onsearch(self, evt) :
991 # self.dial = SearchDial(self, self, 6, True)
992 # self.dial.CenterOnParent()
993 # self.dial.ShowModal()
994 # self.dial.Destroy()
996 # def onsearchall(self, evt) :
997 # if 'FrameSearch' not in dir(self.Source) :
998 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
999 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
1000 # self.dial.CenterOnParent()
1001 # self.dial.ShowModal()
1002 # self.dial.Destroy()
1004 # def OnRightClick(self, event):
1006 # # only do this part the first time so the events are only bound once
1008 # if not hasattr(self, "popupID1"):
1009 # self.popupID1 = wx.NewId()
1010 # self.popupID2 = wx.NewId()
1011 # self.popupID3 = wx.NewId()
1012 # self.popupID4 = wx.NewId()
1013 # self.popupID5 = wx.NewId()
1014 # self.popupID6 = wx.NewId()
1015 # self.popupID7 = wx.NewId()
1016 # self.popupID8 = wx.NewId()
1017 # self.popupID9 = wx.NewId()
1018 # #self.popupID10 = wx.NewId()
1019 # self.popupIDgraph = wx.NewId()
1020 # self.idseg = wx.NewId()
1021 # self.iducecarac = wx.NewId()
1022 # self.idtablex = wx.NewId()
1023 # self.idchimod = wx.NewId()
1024 # self.idwordgraph = wx.NewId()
1025 # self.popup_proxe = wx.NewId()
1026 # self.idlexdendro = wx.NewId()
1027 # self.idexport = wx.NewId()
1028 # # self.export_classes = wx.NewId()
1030 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1031 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1032 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1033 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1034 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1035 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1036 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1037 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1038 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1039 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1040 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1041 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1042 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1043 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1044 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1045 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1046 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1047 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1048 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1049 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1050 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1054 # menu.Append(self.popupID1, u"Formes associées")
1055 # menu.Append(self.idtablex, u"Chi2 par classe")
1056 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1057 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1058 # menu.Append(self.idwordgraph, u"Graphe du mot")
1059 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1061 # #menu.Append(self.popupID10, u"Spécificités")
1063 # menu_conc = wx.Menu()
1064 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1065 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1066 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1067 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1068 # menu_cnrtl = wx.Menu()
1069 # menu_cnrtl.Append(self.popupID5, u"Définition")
1070 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1071 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1072 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1073 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1074 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1075 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1076 # menu.AppendSeparator()
1077 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1078 # menu.Append(self.idseg, u"Segments répétés")
1079 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1080 # menu.Append(self.idexport, 'Partitionner...')
1081 # #menu.Append(self.popupID2, u"Concordancier")
1082 # # menu.Append(self.popupID3, "recharger")
1084 # self.PopupMenu(menu)
1086 # elif 'tableau' in dir(self.Source) :
1087 # if not hasattr(self, "pop1"):
1088 # self.pop1 = wx.NewId()
1089 # self.pop2 = wx.NewId()
1090 # self.pop3 = wx.NewId()
1091 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1092 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1093 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1096 # menu.Append(self.pop2, u"Chi2 par classe")
1097 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1098 # menu.AppendSeparator()
1099 # menu.Append(self.pop1, u"Graph de la classe")
1100 # self.PopupMenu(menu)
1103 # def onexport(self, evt) :
1104 # if 'corpus' in dir(self.Source):
1105 # corpus = self.Source.corpus
1106 # ClasseCHD(self.parent, corpus, self.cl)
1108 # def quest_var_mod(self, evt) :
1109 # if 'corpus' in dir(self.Source):
1110 # corpus = self.Source.corpus
1111 # if self.var_mod == {} :
1112 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1114 # corpus = self.Source.tableau
1115 # if self.var_mod == {} :
1116 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1117 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1118 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1119 # title = chistable[0]
1122 # vchistable = [line[1:] for line in chistable]
1123 # fchistable = [line[0] for line in chistable]
1124 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1125 # if len(word.split('_')) > 1 :
1126 # var = word.split('_')[0]
1127 # words = [word for word in self.var_mod[var]]
1131 # for word in words :
1132 # if word in fchistable :
1133 # tableout.append(vchistable[fchistable.index(word)])
1134 # kwords.append(word)
1135 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1136 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1137 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1138 # file = open(tmpscript,'w')
1141 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1142 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1143 # win.addsaveimage(tmpgraph)
1144 # txt = "<img src='%s'>" % tmpgraph
1145 # win.HtmlPage.SetPage(txt)
1148 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1149 # dial.CenterOnParent()
1153 # def quest_simi(self, evt) :
1154 # tableau = self.Source.tableau
1155 # tab = tableau.make_table_from_classe(self.cl, self.la)
1156 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1157 # self.filename = os.path.join(pathout,'mat01.csv')
1158 # tableau.printtable(self.filename, tab)
1160 # paramsimi = {'coeff' : 0,
1165 # 'coeff_tv_nb' : 0,
1170 # 'coeff_temin' : 1,
1171 # 'coeff_temax' : 10,
1178 # 'cexfromchi' : True,
1179 # 'sfromchi': False,
1182 # 'cols' : (255,0,0),
1183 # 'cola' : (200,200,200),
1187 # 'keep_coord' : True,
1191 ## self.tableau.actives = {}
1192 ## self.tableau.lchi = self.lchi
1193 ## self.tableau.chi = {}
1194 ## for i, val in enumerate(self.la) :
1195 ## self.tableau.actives[val] = [self.lfreq[i]]
1196 ## self.tableau.chi[val] = [self.lchi[i]]
1199 # self.tableau.chi = {}
1200 # self.tableau.lchi = self.lchi
1201 # self.tableau.parametre['fromprof'] = True
1202 # for i, val in enumerate(self.la) :
1203 # act[val] = [self.lfreq[i]]
1204 # self.tableau.chi[val] = [self.lchi[i]]
1205 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1207 # def onwordgraph(self, evt):
1208 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1209 # dlg = progressbar(self, 2)
1210 # corpus = self.Source.corpus
1211 # uces = corpus.lc[self.cl-1]
1212 # dlg.Update(1, u'Tableau...')
1213 # #tab = corpus.make_table_with_classe(uces, self.la)
1214 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1215 # self.filename = os.path.join(pathout,'mat01.csv')
1216 # dlg.Update(2, u'Ecriture...')
1217 # #corpus.write_tab(tab, self.filename)
1219 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1221 # paramsimi = {'coeff' : 0,
1226 # 'coeff_tv_nb' : 0,
1231 # 'coeff_temin' : 1,
1232 # 'coeff_temax' : 10,
1241 # 'cols' : (255,0,0),
1242 # 'cola' : (200,200,200),
1246 # 'keep_coord' : True,
1250 # self.tableau = Tableau(self.parent, '')
1251 # self.tableau.listactives = self.la
1252 # self.tableau.actives = {}
1253 # for i, val in enumerate(self.la) :
1254 # self.tableau.actives[val] = [self.lfreq[i]]
1255 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1258 def OnPopupOne(self, event):
1259 corpus = self.Source.corpus
1260 #print 'ATTENTION PRINT ET TABLE'
1261 #corpus.make_et_table()
1262 word = self.getColumnText(self.GetFirstSelected(), 6)
1263 lems = corpus.getlems()
1264 uces = corpus.lc[self.cl-1]
1266 #FIXME : donner aussi eff reel a la place de nb uce
1267 for forme in lems[word].formes :
1268 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1269 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1272 rep.append([corpus.getforme(forme).forme, nb])
1273 win = message(self, u"Formes associées", wx.Size(300, 200))
1274 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1275 win.HtmlPage.SetPage(win.html)
1278 # def on_graph(self, evt):
1279 # dlg = progressbar(self, 2)
1280 # corpus = self.Source.corpus
1281 # uces = corpus.lc[self.cl-1]
1282 # dlg.Update(1, u'Tableau...')
1283 # #tab = corpus.make_table_with_classe(uces, self.la)
1284 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1285 # self.filename = os.path.join(pathout,'mat01.csv')
1286 # dlg.Update(2, u'Ecriture...')
1287 # #corpus.write_tab(tab, self.filename)
1289 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1291 # paramsimi = {'coeff' : 0,
1296 # 'coeff_tv_nb' : 0,
1301 # 'coeff_temin' : 1,
1302 # 'coeff_temax' : 10,
1309 # 'cexfromchi' : True,
1310 # 'sfromchi': False,
1313 # 'cols' : (255,0,0),
1314 # 'cola' : (200,200,200),
1318 # 'keep_coord' : True,
1322 # self.tableau = Tableau(self.parent, '')
1323 # self.tableau.listactives = self.la
1324 # self.tableau.actives = {}
1325 # self.tableau.lchi = self.lchi
1326 # self.tableau.chi = {}
1327 # self.tableau.parametre['fromprof'] = True
1328 # for i, val in enumerate(self.la) :
1329 # self.tableau.actives[val] = [self.lfreq[i]]
1330 # self.tableau.chi[val] = [self.lchi[i]]
1331 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1333 # def on_segments(self,evt) :
1334 # dlg = progressbar(self, 2)
1335 # corpus = self.Source.corpus
1336 # uces = corpus.lc[self.cl-1]
1338 # dlg.Update(1, u'Segments...')
1339 # for i in range(2,10) :
1340 # li = corpus.find_segments_in_classe(uces, i, 1000)
1345 # l.sort(reverse = True)
1347 # dlg.Update(2, 'Tri...')
1348 # for i, line in enumerate(l) :
1349 # d[i] = [line[1],line[0], line[2]]
1350 # first = ['','','']
1351 # para={'dico': d,'fline':first}
1353 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1356 # def on_uce_carac(self,evt) :
1357 # dial = PrefUCECarac(self, self.parent)
1358 # dial.CenterOnParent()
1359 # if dial.ShowModal() == wx.ID_OK :
1360 # limite = dial.spin_eff.GetValue()
1361 # atype = dial.radio_type.GetSelection()
1362 # dlg = progressbar(self,maxi = 4)
1363 # corpus = self.Source.corpus
1364 # uces = corpus.lc[self.cl-1]
1365 # tab = corpus.make_table_with_classe(uces, self.la)
1367 # dlg.Update(2, u'score...')
1369 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1371 # 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]
1372 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1374 # ntab2.sort(reverse = True)
1375 # ntab2 = ntab2[:limite]
1376 # nuces = [val[1] for val in ntab2]
1377 # dlg.Update(3, u'concordancier...')
1378 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1379 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1382 # for uce in ucestxt1 :
1383 # ucetxt = ' '+uce[1]+' '
1384 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1385 # for lem in self.la :
1386 # listmot = corpus.getlems()[lem].formes
1387 # for id in listmot :
1388 # forme = corpus.getforme(id).forme
1389 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1390 # ucestxt.append(ucetxt)
1391 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1392 # dlg.Update(4, u'texte...')
1393 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1394 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1395 # 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>'
1396 # win.HtmlPage.SetPage(win.html)
1400 # def on_tablex(self, evt):
1401 # if 'corpus' in dir(self.Source):
1402 # corpus = self.Source.corpus
1404 # corpus = self.Source.tableau
1405 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1406 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1407 # title = chistable[0]
1410 # vchistable = [line[1:] for line in chistable]
1411 # fchistable = [line[0] for line in chistable]
1412 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1413 # tableout = [vchistable[fchistable.index(words[0])]]
1414 # last = self.list.GetFirstSelected()
1415 # while self.list.GetNextSelected(last) != -1:
1416 # last = self.list.GetNextSelected(last)
1417 # word = self.getColumnText(last, 6)
1418 # words.append(word)
1419 # tableout.append(vchistable[fchistable.index(word)])
1420 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1422 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1423 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1424 # file = open(tmpscript,'w')
1428 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1429 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1430 # win.addsaveimage(tmpgraph)
1431 # txt = "<img src='%s'>" % tmpgraph
1432 # win.HtmlPage.SetPage(txt)
1435 # def onlexdendro(self, evt):
1436 # if 'corpus' in dir(self.Source):
1437 # corpus = self.Source.corpus
1439 # corpus = self.Source.tableau
1440 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1441 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1442 # title = chistable[0]
1445 # vchistable = [line[1:] for line in chistable]
1446 # fchistable = [line[0] for line in chistable]
1447 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1448 # tableout = [vchistable[fchistable.index(words[0])]]
1449 # last = self.list.GetFirstSelected()
1450 # while self.list.GetNextSelected(last) != -1:
1451 # last = self.list.GetNextSelected(last)
1452 # word = self.getColumnText(last, 6)
1453 # words.append(word)
1454 # tableout.append(vchistable[fchistable.index(word)])
1455 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1456 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1457 # rownames = 'c("' + '","'.join(words) + '")'
1458 # colnames = 'c("' + '","'.join(title) + '")'
1460 # rownb = len(words)
1463 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1465 # colnames(di) <- %s
1468 # height <- (30*ncol(di)) + (15*nrow(di))
1469 # height <- ifelse(height <= 400, 400, height)
1471 # open_file_graph("%s", width=width, height=height)
1472 # plot.dendro.lex(tree.cut1$tree.cl, di)
1473 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1474 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1475 # file = open(tmpscript,'w')
1478 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1479 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1480 # win.addsaveimage(tmpgraph)
1481 # txt = "<img src='%s'>" % tmpgraph
1482 # win.HtmlPage.SetPage(txt)
1486 # def make_concord(self, uces, title, color = 'red') :
1487 # corpus = self.Source.corpus
1488 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1489 # last = self.list.GetFirstSelected()
1490 # while self.list.GetNextSelected(last) != -1:
1491 # last = self.list.GetNextSelected(last)
1492 # ListWord.append(self.getColumnText(last, 6))
1493 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1494 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1495 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1496 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1499 # for word in ListWord :
1500 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1501 # ucef = list(set(ucef))
1503 # res = corpus.getconcorde(ucef)
1504 # txt = '<br>'.join(toshow) +'<br><br>'
1506 # ucetxt = ' '+uce[1]+' '
1507 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1508 # for forme in listmot:
1509 # forme = corpus.getforme(forme).forme
1510 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1511 # txt += ucetxt + '<br><br>'
1512 # win.HtmlPage.SetPage(txt)
1515 # def OnPopupTwo(self, event):
1516 # corpus = self.Source.corpus
1517 # uces = corpus.lc[self.cl-1]
1518 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1521 # def OnPopupThree(self, event):
1522 # corpus = self.Source.corpus
1523 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1524 # win = self.make_concord(uces, "Concordancier - UCE classées")
1527 # def OnPopupFour(self, event):
1528 # corpus = self.Source.corpus
1529 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1530 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1533 # def OnPopupFive(self, event):
1534 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1535 # lk = "http://www.cnrtl.fr/definition/" + word
1536 # webbrowser.open(lk)
1538 # def OnPopupSix(self, event):
1539 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1540 # lk = "http://www.cnrtl.fr/etymologie/" + word
1541 # webbrowser.open(lk)
1543 # def OnPopupSeven(self, event):
1544 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1545 # lk = "http://www.cnrtl.fr/synonymie/" + word
1546 # webbrowser.open(lk)
1548 # def OnPopupHeight(self, event):
1549 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1550 # lk = "http://www.cnrtl.fr/antonymie/" + word
1551 # webbrowser.open(lk)
1553 # def OnPopupNine(self, event):
1554 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1555 # lk = "http://www.cnrtl.fr/morphologie/" + word
1556 # webbrowser.open(lk)
1558 # def onproxe(self, evt) :
1559 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1560 # lk = "http://www.cnrtl.fr/proxemie/" + word
1561 # webbrowser.open(lk)
1563 # def OnSize(self, event):
1564 # w, h = self.GetClientSizeTuple()
1565 # self.list.SetDimensions(0, 0, w, h)
1567 # def OnColClick(self, event):
1568 # self.do_greyline()
1571 #class wliste(wx.Frame):
1572 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1573 # wx.Frame.__init__(self, parent, id)
1574 # self.liste = ListForSpec(self, parent, d, fline)
1575 # self.button_1 = wx.Button(self, -1, "Fermer")
1576 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1577 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1578 # self.__do_layout()
1580 # def __do_layout(self):
1581 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1582 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1583 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1584 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1585 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1586 # self.SetAutoLayout(True)
1587 # self.SetSizer(sizer_1)
1590 # def OnCloseMe(self, event):
1593 # def OnCloseWindow(self, event):
1596 class message(wx.Dialog):
1597 def __init__(self, parent, title, size):
1598 wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1600 self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1603 self.HtmlPage=wx.html.HtmlWindow(self, -1)
1604 self.HtmlPage.SetMinSize( size )
1605 if "gtk2" in wx.PlatformInfo:
1606 self.HtmlPage.SetStandardFonts()
1607 self.HtmlPage.SetFonts('Courier','Courier')
1609 self.button_1 = wx.Button(self, wx.ID_CANCEL)
1610 self.button_2 = wx.Button(self, wx.ID_SAVE)
1612 self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1613 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1614 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1617 def __do_layout(self):
1618 sizer_2 = wx.BoxSizer(wx.VERTICAL)
1619 sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1620 m_sdbSizer1 = wx.StdDialogButtonSizer()
1621 m_sdbSizer1.AddButton( self.button_1 )
1622 m_sdbSizer1.AddButton( self.button_2 )
1623 m_sdbSizer1.Realize()
1624 sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1625 self.SetSizer(sizer_2)
1629 def OnSavePage(self, evt) :
1630 dlg = wx.FileDialog(
1631 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1632 defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1634 dlg.SetFilterIndex(2)
1635 dlg.CenterOnParent()
1636 if dlg.ShowModal() == wx.ID_OK:
1637 path = dlg.GetPath()
1638 with open(path, 'w') as f :
1641 def OnCloseMe(self, event):
1644 def OnCloseWindow(self, event):