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, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
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, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
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)
666 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
667 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
668 file = open(tmpscript,'w')
672 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
673 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
674 win.addsaveimage(tmpgraph)
675 txt = "<img src='%s'>" % tmpgraph
676 win.HtmlPage.SetPage(txt)
679 def onlexdendro(self, evt):
680 if 'corpus' in dir(self.Source):
681 corpus = self.Source.corpus
683 corpus = self.Source.tableau
684 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
685 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
689 vchistable = [line[1:] for line in chistable]
690 fchistable = [line[0] for line in chistable]
691 words = self.getselectedwords()
692 tableout = [vchistable[fchistable.index(word)] for word in words]
693 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
694 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
695 rownames = 'c("' + '","'.join(words) + '")'
696 colnames = 'c("' + '","'.join(title) + '")'
701 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
706 height <- (30*ncol(di)) + (15*nrow(di))
707 height <- ifelse(height <= 400, 400, height)
709 open_file_graph("%s", width=width, height=height)
710 plot.dendro.lex(tree.cut1$tree.cl, di)
711 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
712 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
713 file = open(tmpscript,'w')
716 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
717 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
718 win.addsaveimage(tmpgraph)
719 txt = "<img src='%s'>" % tmpgraph
720 win.HtmlPage.SetPage(txt)
724 def make_concord(self, uces, title, color = 'red') :
725 corpus = self.Source.corpus
726 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
727 last = self.GetFirstSelected()
728 while self.GetNextSelected(last) != -1:
729 last = self.GetNextSelected(last)
730 ListWord.append(self.getColumnText(last, 6))
731 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
732 win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
733 toshow = ['<html>\n<H1>Concordancier</H1>\n']
734 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
737 for word in ListWord :
738 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
739 ucef = list(set(ucef))
741 res = corpus.getconcorde(ucef)
742 txt = '<br>'.join(toshow) +'<br><br>'
744 ucetxt = ' '+uce[1]+' '
745 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
746 for forme in listmot:
747 forme = corpus.getforme(forme).forme
748 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
749 txt += ucetxt + '<br><br>'
750 win.HtmlPage.SetPage(txt)
753 def OnPopupTwo(self, event):
754 corpus = self.Source.corpus
755 uces = corpus.lc[self.cl-1]
756 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
759 def OnPopupThree(self, event):
760 corpus = self.Source.corpus
761 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
762 win = self.make_concord(uces, "Concordancier - UCE classées")
765 def OnPopupFour(self, event):
766 corpus = self.Source.corpus
767 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
768 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
771 def OnPopupFive(self, event):
772 word = self.getColumnText(self.GetFirstSelected(), 6)
773 lk = "http://www.cnrtl.fr/definition/" + word
776 def OnPopupSix(self, event):
777 word = self.getColumnText(self.GetFirstSelected(), 6)
778 lk = "http://www.cnrtl.fr/etymologie/" + word
781 def OnPopupSeven(self, event):
782 word = self.getColumnText(self.GetFirstSelected(), 6)
783 lk = "http://www.cnrtl.fr/synonymie/" + word
786 def OnPopupHeight(self, event):
787 word = self.getColumnText(self.GetFirstSelected(), 6)
788 lk = "http://www.cnrtl.fr/antonymie/" + word
791 def OnPopupNine(self, event):
792 word = self.getColumnText(self.GetFirstSelected(), 6)
793 lk = "http://www.cnrtl.fr/morphologie/" + word
796 def onproxe(self, evt) :
797 word = self.getColumnText(self.GetFirstSelected(), 6)
798 lk = "http://www.cnrtl.fr/proxemie/" + word
802 #---------------------------------------------------------------------------
803 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
804 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
805 # size=wx.DefaultSize, style=0):
806 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
807 # listmix.ListCtrlAutoWidthMixin.__init__(self)
810 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
811 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
812 # self.parent = parent
813 # classe = ProfClasse
815 # self.Source = gparent
816 # if 'tableau' in dir(self.Source):
817 # self.tableau = self.Source.tableau
818 # self.Alceste = Alceste
822 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
824 # search_id = wx.NewId()
825 # searchall_id = wx.NewId()
826 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
827 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
828 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
829 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
830 # self.SetAcceleratorTable(self.accel_tbl)
832 # self.il = wx.ImageList(16, 16)
833 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
834 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
835 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
838 # self.list = ProfListctrl(self, tID,
841 # | wx.LC_EDIT_LABELS
842 # | wx.LC_SORT_ASCENDING
844 # line1 = classe.pop(0)
849 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
850 # if len(classen) == 0 :
855 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
858 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
860 # lenact = len(classen)
864 # lenet = len(classen)
867 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
869 # lensup = lensup[0] - lenact
870 # lenet = len(classen) - lensup
873 # lenet = len(classen)
876 # self.lenact = lenact
878 # debet = lenact + lensup
879 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
880 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
882 # self.PopulateList(dictdata, debet, debsup, Alceste)
884 # self.Bind(wx.EVT_SIZE, self.OnSize)
885 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
886 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
889 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
892 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
893 # self.itemDataMap = dictdata
894 # listmix.ColumnSorterMixin.__init__(self, 8)
896 ##-----------------------------------------------------------------------------------------
898 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
901 # # for normal, simple columns, you can add them like this:
902 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
903 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
904 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
905 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
906 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
907 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
908 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
909 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
911 # for key in dictdata : #.iteritems():
912 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
914 # for val in dictdata[key][1:]:
915 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
917 # self.list.SetItemData(index, key)
919 # self.list.SetColumnWidth(0, 60)
920 # self.list.SetColumnWidth(1, 70)
921 # self.list.SetColumnWidth(2, 80)
922 # self.list.SetColumnWidth(3, 100)
923 # self.list.SetColumnWidth(4, 70)
924 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
925 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
926 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
928 # # show how to change the colour of a couple items
929 # for i in range(limitsup, limit):
930 # item = self.list.GetItem(i)
931 # item.SetTextColour(wx.RED)
932 # self.list.SetItem(item)
934 # for i in range(limit, len(dictdata)):
935 # item = self.list.GetItem(i)
936 # item.SetTextColour(wx.BLUE)
937 # self.list.SetItem(item)
939 # if self.lenact != 0 :
940 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
941 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
942 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
948 # def do_greyline(self):
949 # for row in xrange(self.list.GetItemCount()):
951 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
953 # self.list.SetItemBackgroundColour(row, wx.WHITE)
956 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
957 # def GetListCtrl(self):
960 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
961 # def GetSortImages(self):
962 # return (self.sm_dn, self.sm_up)
965 # def OnRightDown(self, event):
968 # item, flags = self.list.HitTest((x, y))
970 # if flags & wx.LIST_HITTEST_ONITEM:
971 # self.list.Select(item)
976 # def getColumnText(self, index, col):
977 # item = self.list.GetItem(index, col)
978 # return item.GetText()
981 # def OnItemSelected(self, event):
982 # self.currentItem = event.m_itemIndex
985 # def onsearch(self, evt) :
986 # self.dial = SearchDial(self, self, 6, True)
987 # self.dial.CenterOnParent()
988 # self.dial.ShowModal()
989 # self.dial.Destroy()
991 # def onsearchall(self, evt) :
992 # if 'FrameSearch' not in dir(self.Source) :
993 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
994 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
995 # self.dial.CenterOnParent()
996 # self.dial.ShowModal()
997 # self.dial.Destroy()
999 # def OnRightClick(self, event):
1001 # # only do this part the first time so the events are only bound once
1003 # if not hasattr(self, "popupID1"):
1004 # self.popupID1 = wx.NewId()
1005 # self.popupID2 = wx.NewId()
1006 # self.popupID3 = wx.NewId()
1007 # self.popupID4 = wx.NewId()
1008 # self.popupID5 = wx.NewId()
1009 # self.popupID6 = wx.NewId()
1010 # self.popupID7 = wx.NewId()
1011 # self.popupID8 = wx.NewId()
1012 # self.popupID9 = wx.NewId()
1013 # #self.popupID10 = wx.NewId()
1014 # self.popupIDgraph = wx.NewId()
1015 # self.idseg = wx.NewId()
1016 # self.iducecarac = wx.NewId()
1017 # self.idtablex = wx.NewId()
1018 # self.idchimod = wx.NewId()
1019 # self.idwordgraph = wx.NewId()
1020 # self.popup_proxe = wx.NewId()
1021 # self.idlexdendro = wx.NewId()
1022 # self.idexport = wx.NewId()
1023 # # self.export_classes = wx.NewId()
1025 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1026 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1027 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1028 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1029 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1030 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1031 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1032 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1033 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1034 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1035 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1036 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1037 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1038 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1039 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1040 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1041 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1042 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1043 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1044 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1045 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1049 # menu.Append(self.popupID1, u"Formes associées")
1050 # menu.Append(self.idtablex, u"Chi2 par classe")
1051 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1052 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1053 # menu.Append(self.idwordgraph, u"Graphe du mot")
1054 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1056 # #menu.Append(self.popupID10, u"Spécificités")
1058 # menu_conc = wx.Menu()
1059 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1060 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1061 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1062 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1063 # menu_cnrtl = wx.Menu()
1064 # menu_cnrtl.Append(self.popupID5, u"Définition")
1065 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1066 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1067 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1068 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1069 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1070 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1071 # menu.AppendSeparator()
1072 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1073 # menu.Append(self.idseg, u"Segments répétés")
1074 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1075 # menu.Append(self.idexport, 'Partitionner...')
1076 # #menu.Append(self.popupID2, u"Concordancier")
1077 # # menu.Append(self.popupID3, "recharger")
1079 # self.PopupMenu(menu)
1081 # elif 'tableau' in dir(self.Source) :
1082 # if not hasattr(self, "pop1"):
1083 # self.pop1 = wx.NewId()
1084 # self.pop2 = wx.NewId()
1085 # self.pop3 = wx.NewId()
1086 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1087 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1088 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1091 # menu.Append(self.pop2, u"Chi2 par classe")
1092 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1093 # menu.AppendSeparator()
1094 # menu.Append(self.pop1, u"Graph de la classe")
1095 # self.PopupMenu(menu)
1098 # def onexport(self, evt) :
1099 # if 'corpus' in dir(self.Source):
1100 # corpus = self.Source.corpus
1101 # ClasseCHD(self.parent, corpus, self.cl)
1103 # def quest_var_mod(self, evt) :
1104 # if 'corpus' in dir(self.Source):
1105 # corpus = self.Source.corpus
1106 # if self.var_mod == {} :
1107 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1109 # corpus = self.Source.tableau
1110 # if self.var_mod == {} :
1111 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1112 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1113 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1114 # title = chistable[0]
1117 # vchistable = [line[1:] for line in chistable]
1118 # fchistable = [line[0] for line in chistable]
1119 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1120 # if len(word.split('_')) > 1 :
1121 # var = word.split('_')[0]
1122 # words = [word for word in self.var_mod[var]]
1126 # for word in words :
1127 # if word in fchistable :
1128 # tableout.append(vchistable[fchistable.index(word)])
1129 # kwords.append(word)
1130 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1131 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1132 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1133 # file = open(tmpscript,'w')
1136 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1137 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1138 # win.addsaveimage(tmpgraph)
1139 # txt = "<img src='%s'>" % tmpgraph
1140 # win.HtmlPage.SetPage(txt)
1143 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1144 # dial.CenterOnParent()
1148 # def quest_simi(self, evt) :
1149 # tableau = self.Source.tableau
1150 # tab = tableau.make_table_from_classe(self.cl, self.la)
1151 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1152 # self.filename = os.path.join(pathout,'mat01.csv')
1153 # tableau.printtable(self.filename, tab)
1155 # paramsimi = {'coeff' : 0,
1160 # 'coeff_tv_nb' : 0,
1165 # 'coeff_temin' : 1,
1166 # 'coeff_temax' : 10,
1173 # 'cexfromchi' : True,
1174 # 'sfromchi': False,
1177 # 'cols' : (255,0,0),
1178 # 'cola' : (200,200,200),
1182 # 'keep_coord' : True,
1186 ## self.tableau.actives = {}
1187 ## self.tableau.lchi = self.lchi
1188 ## self.tableau.chi = {}
1189 ## for i, val in enumerate(self.la) :
1190 ## self.tableau.actives[val] = [self.lfreq[i]]
1191 ## self.tableau.chi[val] = [self.lchi[i]]
1194 # self.tableau.chi = {}
1195 # self.tableau.lchi = self.lchi
1196 # self.tableau.parametre['fromprof'] = True
1197 # for i, val in enumerate(self.la) :
1198 # act[val] = [self.lfreq[i]]
1199 # self.tableau.chi[val] = [self.lchi[i]]
1200 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1202 # def onwordgraph(self, evt):
1203 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1204 # dlg = progressbar(self, 2)
1205 # corpus = self.Source.corpus
1206 # uces = corpus.lc[self.cl-1]
1207 # dlg.Update(1, u'Tableau...')
1208 # #tab = corpus.make_table_with_classe(uces, self.la)
1209 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1210 # self.filename = os.path.join(pathout,'mat01.csv')
1211 # dlg.Update(2, u'Ecriture...')
1212 # #corpus.write_tab(tab, self.filename)
1214 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1216 # paramsimi = {'coeff' : 0,
1221 # 'coeff_tv_nb' : 0,
1226 # 'coeff_temin' : 1,
1227 # 'coeff_temax' : 10,
1236 # 'cols' : (255,0,0),
1237 # 'cola' : (200,200,200),
1241 # 'keep_coord' : True,
1245 # self.tableau = Tableau(self.parent, '')
1246 # self.tableau.listactives = self.la
1247 # self.tableau.actives = {}
1248 # for i, val in enumerate(self.la) :
1249 # self.tableau.actives[val] = [self.lfreq[i]]
1250 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1253 def OnPopupOne(self, event):
1254 corpus = self.Source.corpus
1255 #print 'ATTENTION PRINT ET TABLE'
1256 #corpus.make_et_table()
1257 word = self.getColumnText(self.GetFirstSelected(), 6)
1258 lems = corpus.getlems()
1259 uces = corpus.lc[self.cl-1]
1261 #FIXME : donner aussi eff reel a la place de nb uce
1262 for forme in lems[word].formes :
1263 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1264 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1267 rep.append([corpus.getforme(forme).forme, nb])
1268 win = message(self, -1, u"Formes associées", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
1269 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1270 win.HtmlPage.SetPage(win.html)
1273 # def on_graph(self, evt):
1274 # dlg = progressbar(self, 2)
1275 # corpus = self.Source.corpus
1276 # uces = corpus.lc[self.cl-1]
1277 # dlg.Update(1, u'Tableau...')
1278 # #tab = corpus.make_table_with_classe(uces, self.la)
1279 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1280 # self.filename = os.path.join(pathout,'mat01.csv')
1281 # dlg.Update(2, u'Ecriture...')
1282 # #corpus.write_tab(tab, self.filename)
1284 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1286 # paramsimi = {'coeff' : 0,
1291 # 'coeff_tv_nb' : 0,
1296 # 'coeff_temin' : 1,
1297 # 'coeff_temax' : 10,
1304 # 'cexfromchi' : True,
1305 # 'sfromchi': False,
1308 # 'cols' : (255,0,0),
1309 # 'cola' : (200,200,200),
1313 # 'keep_coord' : True,
1317 # self.tableau = Tableau(self.parent, '')
1318 # self.tableau.listactives = self.la
1319 # self.tableau.actives = {}
1320 # self.tableau.lchi = self.lchi
1321 # self.tableau.chi = {}
1322 # self.tableau.parametre['fromprof'] = True
1323 # for i, val in enumerate(self.la) :
1324 # self.tableau.actives[val] = [self.lfreq[i]]
1325 # self.tableau.chi[val] = [self.lchi[i]]
1326 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1328 # def on_segments(self,evt) :
1329 # dlg = progressbar(self, 2)
1330 # corpus = self.Source.corpus
1331 # uces = corpus.lc[self.cl-1]
1333 # dlg.Update(1, u'Segments...')
1334 # for i in range(2,10) :
1335 # li = corpus.find_segments_in_classe(uces, i, 1000)
1340 # l.sort(reverse = True)
1342 # dlg.Update(2, 'Tri...')
1343 # for i, line in enumerate(l) :
1344 # d[i] = [line[1],line[0], line[2]]
1345 # first = ['','','']
1346 # para={'dico': d,'fline':first}
1348 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1351 # def on_uce_carac(self,evt) :
1352 # dial = PrefUCECarac(self, self.parent)
1353 # dial.CenterOnParent()
1354 # if dial.ShowModal() == wx.ID_OK :
1355 # limite = dial.spin_eff.GetValue()
1356 # atype = dial.radio_type.GetSelection()
1357 # dlg = progressbar(self,maxi = 4)
1358 # corpus = self.Source.corpus
1359 # uces = corpus.lc[self.cl-1]
1360 # tab = corpus.make_table_with_classe(uces, self.la)
1362 # dlg.Update(2, u'score...')
1364 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1366 # 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]
1367 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1369 # ntab2.sort(reverse = True)
1370 # ntab2 = ntab2[:limite]
1371 # nuces = [val[1] for val in ntab2]
1372 # dlg.Update(3, u'concordancier...')
1373 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1374 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1377 # for uce in ucestxt1 :
1378 # ucetxt = ' '+uce[1]+' '
1379 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1380 # for lem in self.la :
1381 # listmot = corpus.getlems()[lem].formes
1382 # for id in listmot :
1383 # forme = corpus.getforme(id).forme
1384 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1385 # ucestxt.append(ucetxt)
1386 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1387 # dlg.Update(4, u'texte...')
1388 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1389 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1390 # 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>'
1391 # win.HtmlPage.SetPage(win.html)
1395 # def on_tablex(self, evt):
1396 # if 'corpus' in dir(self.Source):
1397 # corpus = self.Source.corpus
1399 # corpus = self.Source.tableau
1400 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1401 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1402 # title = chistable[0]
1405 # vchistable = [line[1:] for line in chistable]
1406 # fchistable = [line[0] for line in chistable]
1407 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1408 # tableout = [vchistable[fchistable.index(words[0])]]
1409 # last = self.list.GetFirstSelected()
1410 # while self.list.GetNextSelected(last) != -1:
1411 # last = self.list.GetNextSelected(last)
1412 # word = self.getColumnText(last, 6)
1413 # words.append(word)
1414 # tableout.append(vchistable[fchistable.index(word)])
1415 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1417 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1418 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1419 # file = open(tmpscript,'w')
1423 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1424 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1425 # win.addsaveimage(tmpgraph)
1426 # txt = "<img src='%s'>" % tmpgraph
1427 # win.HtmlPage.SetPage(txt)
1430 # def onlexdendro(self, evt):
1431 # if 'corpus' in dir(self.Source):
1432 # corpus = self.Source.corpus
1434 # corpus = self.Source.tableau
1435 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1436 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1437 # title = chistable[0]
1440 # vchistable = [line[1:] for line in chistable]
1441 # fchistable = [line[0] for line in chistable]
1442 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1443 # tableout = [vchistable[fchistable.index(words[0])]]
1444 # last = self.list.GetFirstSelected()
1445 # while self.list.GetNextSelected(last) != -1:
1446 # last = self.list.GetNextSelected(last)
1447 # word = self.getColumnText(last, 6)
1448 # words.append(word)
1449 # tableout.append(vchistable[fchistable.index(word)])
1450 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1451 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1452 # rownames = 'c("' + '","'.join(words) + '")'
1453 # colnames = 'c("' + '","'.join(title) + '")'
1455 # rownb = len(words)
1458 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1460 # colnames(di) <- %s
1463 # height <- (30*ncol(di)) + (15*nrow(di))
1464 # height <- ifelse(height <= 400, 400, height)
1466 # open_file_graph("%s", width=width, height=height)
1467 # plot.dendro.lex(tree.cut1$tree.cl, di)
1468 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1469 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1470 # file = open(tmpscript,'w')
1473 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1474 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1475 # win.addsaveimage(tmpgraph)
1476 # txt = "<img src='%s'>" % tmpgraph
1477 # win.HtmlPage.SetPage(txt)
1481 # def make_concord(self, uces, title, color = 'red') :
1482 # corpus = self.Source.corpus
1483 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1484 # last = self.list.GetFirstSelected()
1485 # while self.list.GetNextSelected(last) != -1:
1486 # last = self.list.GetNextSelected(last)
1487 # ListWord.append(self.getColumnText(last, 6))
1488 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1489 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1490 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1491 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1494 # for word in ListWord :
1495 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1496 # ucef = list(set(ucef))
1498 # res = corpus.getconcorde(ucef)
1499 # txt = '<br>'.join(toshow) +'<br><br>'
1501 # ucetxt = ' '+uce[1]+' '
1502 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1503 # for forme in listmot:
1504 # forme = corpus.getforme(forme).forme
1505 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1506 # txt += ucetxt + '<br><br>'
1507 # win.HtmlPage.SetPage(txt)
1510 # def OnPopupTwo(self, event):
1511 # corpus = self.Source.corpus
1512 # uces = corpus.lc[self.cl-1]
1513 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1516 # def OnPopupThree(self, event):
1517 # corpus = self.Source.corpus
1518 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1519 # win = self.make_concord(uces, "Concordancier - UCE classées")
1522 # def OnPopupFour(self, event):
1523 # corpus = self.Source.corpus
1524 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1525 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1528 # def OnPopupFive(self, event):
1529 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1530 # lk = "http://www.cnrtl.fr/definition/" + word
1531 # webbrowser.open(lk)
1533 # def OnPopupSix(self, event):
1534 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1535 # lk = "http://www.cnrtl.fr/etymologie/" + word
1536 # webbrowser.open(lk)
1538 # def OnPopupSeven(self, event):
1539 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1540 # lk = "http://www.cnrtl.fr/synonymie/" + word
1541 # webbrowser.open(lk)
1543 # def OnPopupHeight(self, event):
1544 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1545 # lk = "http://www.cnrtl.fr/antonymie/" + word
1546 # webbrowser.open(lk)
1548 # def OnPopupNine(self, event):
1549 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1550 # lk = "http://www.cnrtl.fr/morphologie/" + word
1551 # webbrowser.open(lk)
1553 # def onproxe(self, evt) :
1554 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1555 # lk = "http://www.cnrtl.fr/proxemie/" + word
1556 # webbrowser.open(lk)
1558 # def OnSize(self, event):
1559 # w, h = self.GetClientSizeTuple()
1560 # self.list.SetDimensions(0, 0, w, h)
1562 # def OnColClick(self, event):
1563 # self.do_greyline()
1566 #class wliste(wx.Frame):
1567 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1568 # wx.Frame.__init__(self, parent, id)
1569 # self.liste = ListForSpec(self, parent, d, fline)
1570 # self.button_1 = wx.Button(self, -1, "Fermer")
1571 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1572 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1573 # self.__do_layout()
1575 # def __do_layout(self):
1576 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1577 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1578 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1579 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1580 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1581 # self.SetAutoLayout(True)
1582 # self.SetSizer(sizer_1)
1585 # def OnCloseMe(self, event):
1588 # def OnCloseWindow(self, event):
1591 class message(wx.Frame):
1592 def __init__(self, *args, **kwds):
1593 kwds["style"] = wx.DEFAULT_FRAME_STYLE
1594 wx.Frame.__init__(self, *args, **kwds)
1596 self.HtmlPage=wx.html.HtmlWindow(self, -1)
1597 if "gtk2" in wx.PlatformInfo:
1598 self.HtmlPage.SetStandardFonts()
1599 self.HtmlPage.SetFonts('Courier','Courier')
1600 self.button_1 = wx.Button(self, -1, "Fermer")
1601 self.button_2 = wx.Button(self, -1, u"Enregistrer...")
1603 self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1604 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1605 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1608 def __do_layout(self):
1609 sizer_1 = wx.BoxSizer(wx.VERTICAL)
1610 sizer_2 = wx.BoxSizer(wx.VERTICAL)
1611 sizer_2.Add(self.HtmlPage, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1612 sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
1613 sizer_2.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
1614 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1615 self.SetAutoLayout(True)
1616 self.SetSizer(sizer_1)
1619 def OnSavePage(self, evt) :
1620 dlg = wx.FileDialog(
1621 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1622 defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1624 dlg.SetFilterIndex(2)
1625 dlg.CenterOnParent()
1626 if dlg.ShowModal() == wx.ID_OK:
1627 path = dlg.GetPath()
1628 with open(path, 'w') as f :
1631 def OnCloseMe(self, event):
1634 def OnCloseWindow(self, event):
1637 #def getSmallUpArrowData():
1639 #'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
1640 #\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
1641 #\x00\x00<IDAT8\x8dcddbf\xa0\x040Q\xa4{h\x18\xf0\xff\xdf\xdf\xffd\x1b\x00\xd3\
1642 #\x8c\xcf\x10\x9c\x06\xa0k\xc2e\x08m\xc2\x00\x97m\xd8\xc41\x0c \x14h\xe8\xf2\
1643 #\x8c\xa3)q\x10\x18\x00\x00R\xd8#\xec\xb2\xcd\xc1Y\x00\x00\x00\x00IEND\xaeB`\
1646 #def getSmallUpArrowBitmap():
1647 # return wx.BitmapFromImage(getSmallUpArrowImage())
1649 #def getSmallUpArrowImage():
1650 # stream = cStringIO.StringIO(getSmallUpArrowData())
1651 # return wx.ImageFromStream(stream)
1653 ##----------------------------------------------------------------------
1654 #def getSmallDnArrowData():
1656 #"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
1657 #\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
1658 #\x00\x00HIDAT8\x8dcddbf\xa0\x040Q\xa4{\xd4\x00\x06\x06\x06\x06\x06\x16t\x81\
1659 #\xff\xff\xfe\xfe'\xa4\x89\x91\x89\x99\x11\xa7\x0b\x90%\ti\xc6j\x00>C\xb0\x89\
1660 #\xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\
1661 #?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82"
1663 #def getSmallDnArrowBitmap():
1664 # return wx.BitmapFromImage(getSmallDnArrowImage())
1666 #def getSmallDnArrowImage():
1667 # stream = cStringIO.StringIO(getSmallDnArrowData())
1668 # return wx.ImageFromStream(stream)