1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
19 import wx.lib.mixins.listctrl as listmix
20 from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial, message
24 from tableau import Tableau
25 from search_tools import SearchFrame
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
41 self.Alceste = Alceste
46 line1 = profclasse.pop(0)
47 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
49 self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
50 profclasse.pop(self.lenact)
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
158 def OnItemActivated(self, event):
159 self.currentItem = event.m_itemIndex
161 def getColumnText(self, index, col):
162 item = self.GetItem(index, col)
163 return item.GetText()
165 def OnItemDeselected(self, evt):
167 #---------------------------------------------------
168 # These methods are callbacks for implementing the
169 # "virtualness" of the list...
171 def OnGetItemText(self, item, col):
172 index=self.itemIndexMap[item]
173 s = self.itemDataMap[index][col]
176 def OnGetItemImage(self, item):
177 index=self.itemIndexMap[item]
178 genre=self.itemDataMap[index][2]
184 elif genre=="New Age":
189 def OnGetItemAttr(self, item):
190 index=self.itemIndexMap[item]
191 if index < self.lenact :
196 elif index >= self.lenact and index < (self.lenact + self.lensup) :
201 elif index >= (self.lenact + self.lensup) :
209 #---------------------------------------------------
211 # Here's a better SortItems() method --
212 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
213 # and it knows to sort on another column if the chosen columns have the same value.
215 def SortItems(self,sorter=cmp):
216 items = list(self.itemDataMap.keys())
218 self.itemIndexMap = items
223 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
224 def GetListCtrl(self):
227 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
228 def GetSortImages(self):
229 return (self.sm_dn, self.sm_up)
231 def onsearch(self, evt) :
232 self.dial = SearchDial(self, self, 6, True)
233 self.dial.CenterOnParent()
234 self.dial.ShowModal()
237 def onsearchall(self, evt) :
238 if 'FrameSearch' not in dir(self.Source) :
239 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
240 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
241 self.dial.CenterOnParent()
242 self.dial.ShowModal()
245 def OnRightClick(self, event):
247 # only do this part the first time so the events are only bound once
249 if not hasattr(self, "popupID1"):
250 self.popupID1 = wx.NewId()
251 self.popupID2 = wx.NewId()
252 self.popupID3 = wx.NewId()
253 self.popupID4 = wx.NewId()
254 self.popupID5 = wx.NewId()
255 self.popupID6 = wx.NewId()
256 self.popupID7 = wx.NewId()
257 self.popupID8 = wx.NewId()
258 self.popupID9 = wx.NewId()
259 #self.popupID10 = wx.NewId()
260 self.popupIDgraph = wx.NewId()
261 self.idseg = wx.NewId()
262 self.iducecarac = wx.NewId()
263 self.idtablex = wx.NewId()
264 self.idchimod = wx.NewId()
265 self.idwordgraph = wx.NewId()
266 self.popup_proxe = wx.NewId()
267 self.idlexdendro = wx.NewId()
268 self.idexport = wx.NewId()
269 # self.export_classes = wx.NewId()
271 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
272 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
273 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
274 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
275 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
276 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
277 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
278 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
279 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
280 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
281 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
282 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
283 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
284 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
285 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
286 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
287 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
288 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
289 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
290 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
291 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
295 menu.Append(self.popupID1, u"Formes associées")
296 menu.Append(self.idtablex, u"Chi2 par classe")
297 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
298 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
299 menu.Append(self.idwordgraph, u"Graphe du mot")
300 #menu.Append(self.export_classes, u"Exporter le corpus...")
302 #menu.Append(self.popupID10, u"Spécificités")
304 menu_conc = wx.Menu()
305 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
306 menu_conc.Append(self.popupID3, u"dans les uce classées")
307 menu_conc.Append(self.popupID4, u"dans toutes les uce")
308 menu.AppendMenu(-1, u"Concordancier", menu_conc)
309 menu_cnrtl = wx.Menu()
310 menu_cnrtl.Append(self.popupID5, u"Définition")
311 menu_cnrtl.Append(self.popupID6, u"Etymologie")
312 menu_cnrtl.Append(self.popupID7, u"Synonymie")
313 menu_cnrtl.Append(self.popupID8, u"Antonymie")
314 menu_cnrtl.Append(self.popupID9, u"Morphologie")
315 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
316 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
317 menu.AppendSeparator()
318 menu.Append(self.popupIDgraph, u"Graphe de la classe")
319 menu.Append(self.idseg, u"Segments répétés")
320 menu.Append(self.iducecarac, u"UCE caractéristiques")
321 menu.Append(self.idexport, 'Partitionner...')
322 #menu.Append(self.popupID2, u"Concordancier")
323 # menu.Append(self.popupID3, "recharger")
327 elif 'tableau' in dir(self.Source) :
328 if not hasattr(self, "pop1"):
329 self.pop1 = wx.NewId()
330 self.pop2 = wx.NewId()
331 self.pop3 = wx.NewId()
332 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
333 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
334 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
337 menu.Append(self.pop2, u"Chi2 par classe")
338 menu.Append(self.pop3, u"Chi2 modalités de la variable")
339 menu.AppendSeparator()
340 menu.Append(self.pop1, u"Graph de la classe")
344 def onexport(self, evt) :
345 if 'corpus' in dir(self.Source):
346 corpus = self.Source.corpus
347 ClasseCHD(self.parent, corpus, self.cl)
349 def getselectedwords(self) :
350 words = [self.getColumnText(self.GetFirstSelected(), 6)]
351 last = self.GetFirstSelected()
352 while self.GetNextSelected(last) != -1:
353 last = self.GetNextSelected(last)
354 words.append(self.getColumnText(last, 6))
357 def quest_var_mod(self, evt) :
358 if 'corpus' in dir(self.Source):
359 corpus = self.Source.corpus
360 if self.var_mod == {} :
361 self.var_mod = self.Source.corpus.make_etoiles_dict()
363 corpus = self.Source.tableau
364 if self.var_mod == {} :
365 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
366 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
367 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
371 vchistable = [line[1:] for line in chistable]
372 fchistable = [line[0] for line in chistable]
373 word = self.getselectedwords()[0]
374 if len(word.split('_')) > 1 :
375 var = word.split('_')
376 words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
381 if word in fchistable :
382 tableout.append(vchistable[fchistable.index(word)])
384 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
385 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
386 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
387 file = open(tmpscript,'w')
390 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
391 win = MessageImage(self,u"Graphique", size=(700, 500))
392 win.addsaveimage(tmpgraph)
393 txt = "<img src='%s'>" % tmpgraph
394 win.HtmlPage.SetPage(txt)
397 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
398 dial.CenterOnParent()
402 def quest_simi(self, evt) :
403 tableau = self.Source.tableau
404 tab = tableau.make_table_from_classe(self.cl, self.la)
405 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
406 self.filename = os.path.join(pathout,'mat01.csv')
407 tableau.printtable(self.filename, tab)
409 paramsimi = {'coeff' : 0,
432 'cola' : (200,200,200),
440 # self.tableau.actives = {}
441 # self.tableau.lchi = self.lchi
442 # self.tableau.chi = {}
443 # for i, val in enumerate(self.la) :
444 # self.tableau.actives[val] = [self.lfreq[i]]
445 # self.tableau.chi[val] = [self.lchi[i]]
448 self.tableau.chi = {}
449 self.tableau.lchi = self.lchi
450 self.tableau.parametre['fromprof'] = True
451 for i, val in enumerate(self.la) :
452 act[val] = [self.lfreq[i]]
453 self.tableau.chi[val] = [self.lchi[i]]
454 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
456 def onwordgraph(self, evt):
457 word = self.getColumnText(self.GetFirstSelected(), 6)
458 dlg = progressbar(self, 2)
459 corpus = self.Source.corpus
460 uces = corpus.lc[self.cl-1]
461 dlg.Update(1, u'Tableau...')
462 #tab = corpus.make_table_with_classe(uces, self.la)
463 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
464 self.filename = os.path.join(pathout,'mat01.csv')
465 dlg.Update(2, u'Ecriture...')
466 #corpus.write_tab(tab, self.filename)
468 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
470 paramsimi = {'coeff' : 0,
491 'cola' : (200,200,200),
499 self.tableau = Tableau(self.parent, '')
500 self.tableau.listactives = self.la
501 self.tableau.actives = {}
502 for i, val in enumerate(self.la) :
503 self.tableau.actives[val] = [self.lfreq[i]]
504 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
506 def on_graph(self, evt):
507 dlg = progressbar(self, 2)
508 corpus = self.Source.corpus
509 uces = corpus.lc[self.cl-1]
510 dlg.Update(1, u'Tableau...')
511 #tab = corpus.make_table_with_classe(uces, self.la)
512 pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
513 self.filename = os.path.join(pathout,'mat01.csv')
514 dlg.Update(2, u'Ecriture...')
515 #corpus.write_tab(tab, self.filename)
517 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
519 paramsimi = {'coeff' : 0,
542 'cola' : (200,200,200),
550 self.tableau = Tableau(self.parent, '')
551 self.tableau.listactives = self.la
552 self.tableau.actives = {}
553 self.tableau.lchi = self.lchi
554 self.tableau.chi = {}
555 self.tableau.parametre['fromprof'] = True
556 for i, val in enumerate(self.la) :
557 self.tableau.actives[val] = [self.lfreq[i]]
558 self.tableau.chi[val] = [self.lchi[i]]
559 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
561 def on_segments(self,evt) :
562 dlg = progressbar(self, 2)
563 corpus = self.Source.corpus
564 uces = corpus.lc[self.cl-1]
566 dlg.Update(1, u'Segments...')
567 for i in range(2,10) :
568 li = corpus.find_segments_in_classe(uces, i, 1000)
573 l.sort(reverse = True)
575 dlg.Update(2, 'Tri...')
576 for i, line in enumerate(l) :
577 d[i] = [line[1],line[0], line[2]]
579 para={'dico': d,'fline':first}
581 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
584 def on_uce_carac(self,evt) :
585 dial = PrefUCECarac(self, self.parent)
586 dial.CenterOnParent()
587 if dial.ShowModal() == wx.ID_OK :
588 limite = dial.spin_eff.GetValue()
589 atype = dial.radio_type.GetSelection()
590 dlg = progressbar(self,maxi = 4)
591 corpus = self.Source.corpus
592 uces = corpus.lc[self.cl-1]
593 tab = corpus.make_table_with_classe(uces, self.la)
595 dlg.Update(2, u'score...')
597 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
599 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]
600 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
602 ntab2.sort(reverse = True)
603 ntab2 = ntab2[:limite]
604 nuces = [val[1] for val in ntab2]
605 dlg.Update(3, u'concordancier...')
606 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
607 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
610 for uce in ucestxt1 :
611 ucetxt = ' '+uce[1]+' '
612 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
614 listmot = corpus.getlems()[lem].formes
616 forme = corpus.getforme(id).forme
617 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
618 ucestxt.append(ucetxt)
619 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
620 dlg.Update(4, u'texte...')
621 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
622 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
623 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>'
624 win.HtmlPage.SetPage(win.html)
628 def on_tablex(self, evt):
629 if 'corpus' in dir(self.Source):
630 corpus = self.Source.corpus
632 corpus = self.Source.tableau
633 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
634 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
638 vchistable = [line[1:] for line in chistable]
639 fchistable = [line[0] for line in chistable]
640 words = self.getselectedwords()
641 tableout = [vchistable[fchistable.index(word)] for word in words]
642 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
645 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
646 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
647 file = open(tmpscript,'w')
650 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
651 w = 100 + (20 * nbwords) + (100 * nbcl)
652 h = 100 + (nbwords * 15)
653 if w > 1100 : w = 1100
656 win = MessageImage(self, u"Graphique", size=(w, h))
657 win.addsaveimage(tmpgraph)
658 txt = "<img src='%s'>" % tmpgraph
659 win.HtmlPage.SetPage(txt)
662 def onlexdendro(self, evt):
663 if 'corpus' in dir(self.Source):
664 corpus = self.Source.corpus
666 corpus = self.Source.tableau
667 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
668 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
672 vchistable = [line[1:] for line in chistable]
673 fchistable = [line[0] for line in chistable]
674 words = self.getselectedwords()
675 tableout = [vchistable[fchistable.index(word)] for word in words]
676 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
677 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
678 rownames = 'c("' + '","'.join(words) + '")'
679 colnames = 'c("' + '","'.join(title) + '")'
684 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
689 height <- (30*ncol(di)) + (15*nrow(di))
690 height <- ifelse(height <= 400, 400, height)
692 open_file_graph("%s", width=width, height=height)
693 plot.dendro.lex(tree.cut1$tree.cl, di)
694 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
695 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
696 file = open(tmpscript,'w')
699 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
700 win = MessageImage(self, u"Graphique", size=(700, 500))
701 win.addsaveimage(tmpgraph)
702 txt = "<img src='%s'>" % tmpgraph
703 win.HtmlPage.SetPage(txt)
707 def make_concord(self, uces, title, color = 'red') :
708 corpus = self.Source.corpus
709 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
710 last = self.GetFirstSelected()
711 while self.GetNextSelected(last) != -1:
712 last = self.GetNextSelected(last)
713 ListWord.append(self.getColumnText(last, 6))
714 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
715 win = message(self, title, size=(750, 600))
716 toshow = ['<html>\n<H1>Concordancier</H1>\n']
717 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
720 for word in ListWord :
721 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
722 ucef = list(set(ucef))
724 res = corpus.getconcorde(ucef)
725 txt = '<br>'.join(toshow) +'<br><br>'
727 ucetxt = ' '+uce[1]+' '
728 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
729 for forme in listmot:
730 forme = corpus.getforme(forme).forme
731 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
732 txt += ucetxt + '<br><br>'
733 win.HtmlPage.SetPage(txt)
736 def OnPopupTwo(self, event):
737 corpus = self.Source.corpus
738 uces = corpus.lc[self.cl-1]
739 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
742 def OnPopupThree(self, event):
743 corpus = self.Source.corpus
744 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
745 win = self.make_concord(uces, "Concordancier - UCE classées")
748 def OnPopupFour(self, event):
749 corpus = self.Source.corpus
750 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
751 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
754 def OnPopupFive(self, event):
755 word = self.getColumnText(self.GetFirstSelected(), 6)
756 lk = "http://www.cnrtl.fr/definition/" + word
759 def OnPopupSix(self, event):
760 word = self.getColumnText(self.GetFirstSelected(), 6)
761 lk = "http://www.cnrtl.fr/etymologie/" + word
764 def OnPopupSeven(self, event):
765 word = self.getColumnText(self.GetFirstSelected(), 6)
766 lk = "http://www.cnrtl.fr/synonymie/" + word
769 def OnPopupHeight(self, event):
770 word = self.getColumnText(self.GetFirstSelected(), 6)
771 lk = "http://www.cnrtl.fr/antonymie/" + word
774 def OnPopupNine(self, event):
775 word = self.getColumnText(self.GetFirstSelected(), 6)
776 lk = "http://www.cnrtl.fr/morphologie/" + word
779 def onproxe(self, evt) :
780 word = self.getColumnText(self.GetFirstSelected(), 6)
781 lk = "http://www.cnrtl.fr/proxemie/" + word
785 #---------------------------------------------------------------------------
786 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
787 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
788 # size=wx.DefaultSize, style=0):
789 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
790 # listmix.ListCtrlAutoWidthMixin.__init__(self)
793 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
794 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
795 # self.parent = parent
796 # classe = ProfClasse
798 # self.Source = gparent
799 # if 'tableau' in dir(self.Source):
800 # self.tableau = self.Source.tableau
801 # self.Alceste = Alceste
805 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
807 # search_id = wx.NewId()
808 # searchall_id = wx.NewId()
809 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
810 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
811 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
812 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
813 # self.SetAcceleratorTable(self.accel_tbl)
815 # self.il = wx.ImageList(16, 16)
816 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
817 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
818 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
821 # self.list = ProfListctrl(self, tID,
824 # | wx.LC_EDIT_LABELS
825 # | wx.LC_SORT_ASCENDING
827 # line1 = classe.pop(0)
832 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
833 # if len(classen) == 0 :
838 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
841 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
843 # lenact = len(classen)
847 # lenet = len(classen)
850 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
852 # lensup = lensup[0] - lenact
853 # lenet = len(classen) - lensup
856 # lenet = len(classen)
859 # self.lenact = lenact
861 # debet = lenact + lensup
862 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
863 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
865 # self.PopulateList(dictdata, debet, debsup, Alceste)
867 # self.Bind(wx.EVT_SIZE, self.OnSize)
868 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
869 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
872 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
875 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
876 # self.itemDataMap = dictdata
877 # listmix.ColumnSorterMixin.__init__(self, 8)
879 ##-----------------------------------------------------------------------------------------
881 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
884 # # for normal, simple columns, you can add them like this:
885 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
886 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
887 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
888 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
889 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
890 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
891 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
892 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
894 # for key in dictdata : #.iteritems():
895 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
897 # for val in dictdata[key][1:]:
898 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
900 # self.list.SetItemData(index, key)
902 # self.list.SetColumnWidth(0, 60)
903 # self.list.SetColumnWidth(1, 70)
904 # self.list.SetColumnWidth(2, 80)
905 # self.list.SetColumnWidth(3, 100)
906 # self.list.SetColumnWidth(4, 70)
907 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
908 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
909 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
911 # # show how to change the colour of a couple items
912 # for i in range(limitsup, limit):
913 # item = self.list.GetItem(i)
914 # item.SetTextColour(wx.RED)
915 # self.list.SetItem(item)
917 # for i in range(limit, len(dictdata)):
918 # item = self.list.GetItem(i)
919 # item.SetTextColour(wx.BLUE)
920 # self.list.SetItem(item)
922 # if self.lenact != 0 :
923 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
924 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
925 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
931 # def do_greyline(self):
932 # for row in xrange(self.list.GetItemCount()):
934 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
936 # self.list.SetItemBackgroundColour(row, wx.WHITE)
939 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
940 # def GetListCtrl(self):
943 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
944 # def GetSortImages(self):
945 # return (self.sm_dn, self.sm_up)
948 # def OnRightDown(self, event):
951 # item, flags = self.list.HitTest((x, y))
953 # if flags & wx.LIST_HITTEST_ONITEM:
954 # self.list.Select(item)
959 # def getColumnText(self, index, col):
960 # item = self.list.GetItem(index, col)
961 # return item.GetText()
964 # def OnItemSelected(self, event):
965 # self.currentItem = event.m_itemIndex
968 # def onsearch(self, evt) :
969 # self.dial = SearchDial(self, self, 6, True)
970 # self.dial.CenterOnParent()
971 # self.dial.ShowModal()
972 # self.dial.Destroy()
974 # def onsearchall(self, evt) :
975 # if 'FrameSearch' not in dir(self.Source) :
976 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
977 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
978 # self.dial.CenterOnParent()
979 # self.dial.ShowModal()
980 # self.dial.Destroy()
982 # def OnRightClick(self, event):
984 # # only do this part the first time so the events are only bound once
986 # if not hasattr(self, "popupID1"):
987 # self.popupID1 = wx.NewId()
988 # self.popupID2 = wx.NewId()
989 # self.popupID3 = wx.NewId()
990 # self.popupID4 = wx.NewId()
991 # self.popupID5 = wx.NewId()
992 # self.popupID6 = wx.NewId()
993 # self.popupID7 = wx.NewId()
994 # self.popupID8 = wx.NewId()
995 # self.popupID9 = wx.NewId()
996 # #self.popupID10 = wx.NewId()
997 # self.popupIDgraph = wx.NewId()
998 # self.idseg = wx.NewId()
999 # self.iducecarac = wx.NewId()
1000 # self.idtablex = wx.NewId()
1001 # self.idchimod = wx.NewId()
1002 # self.idwordgraph = wx.NewId()
1003 # self.popup_proxe = wx.NewId()
1004 # self.idlexdendro = wx.NewId()
1005 # self.idexport = wx.NewId()
1006 # # self.export_classes = wx.NewId()
1008 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1009 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1010 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1011 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1012 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1013 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1014 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1015 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1016 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1017 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1018 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1019 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1020 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1021 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1022 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1023 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1024 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1025 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1026 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1027 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1028 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1032 # menu.Append(self.popupID1, u"Formes associées")
1033 # menu.Append(self.idtablex, u"Chi2 par classe")
1034 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1035 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1036 # menu.Append(self.idwordgraph, u"Graphe du mot")
1037 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1039 # #menu.Append(self.popupID10, u"Spécificités")
1041 # menu_conc = wx.Menu()
1042 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1043 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1044 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1045 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1046 # menu_cnrtl = wx.Menu()
1047 # menu_cnrtl.Append(self.popupID5, u"Définition")
1048 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1049 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1050 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1051 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1052 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1053 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1054 # menu.AppendSeparator()
1055 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1056 # menu.Append(self.idseg, u"Segments répétés")
1057 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1058 # menu.Append(self.idexport, 'Partitionner...')
1059 # #menu.Append(self.popupID2, u"Concordancier")
1060 # # menu.Append(self.popupID3, "recharger")
1062 # self.PopupMenu(menu)
1064 # elif 'tableau' in dir(self.Source) :
1065 # if not hasattr(self, "pop1"):
1066 # self.pop1 = wx.NewId()
1067 # self.pop2 = wx.NewId()
1068 # self.pop3 = wx.NewId()
1069 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1070 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1071 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1074 # menu.Append(self.pop2, u"Chi2 par classe")
1075 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1076 # menu.AppendSeparator()
1077 # menu.Append(self.pop1, u"Graph de la classe")
1078 # self.PopupMenu(menu)
1081 # def onexport(self, evt) :
1082 # if 'corpus' in dir(self.Source):
1083 # corpus = self.Source.corpus
1084 # ClasseCHD(self.parent, corpus, self.cl)
1086 # def quest_var_mod(self, evt) :
1087 # if 'corpus' in dir(self.Source):
1088 # corpus = self.Source.corpus
1089 # if self.var_mod == {} :
1090 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1092 # corpus = self.Source.tableau
1093 # if self.var_mod == {} :
1094 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1095 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1096 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1097 # title = chistable[0]
1100 # vchistable = [line[1:] for line in chistable]
1101 # fchistable = [line[0] for line in chistable]
1102 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1103 # if len(word.split('_')) > 1 :
1104 # var = word.split('_')[0]
1105 # words = [word for word in self.var_mod[var]]
1109 # for word in words :
1110 # if word in fchistable :
1111 # tableout.append(vchistable[fchistable.index(word)])
1112 # kwords.append(word)
1113 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1114 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1115 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1116 # file = open(tmpscript,'w')
1119 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1120 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1121 # win.addsaveimage(tmpgraph)
1122 # txt = "<img src='%s'>" % tmpgraph
1123 # win.HtmlPage.SetPage(txt)
1126 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1127 # dial.CenterOnParent()
1131 # def quest_simi(self, evt) :
1132 # tableau = self.Source.tableau
1133 # tab = tableau.make_table_from_classe(self.cl, self.la)
1134 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1135 # self.filename = os.path.join(pathout,'mat01.csv')
1136 # tableau.printtable(self.filename, tab)
1138 # paramsimi = {'coeff' : 0,
1143 # 'coeff_tv_nb' : 0,
1148 # 'coeff_temin' : 1,
1149 # 'coeff_temax' : 10,
1156 # 'cexfromchi' : True,
1157 # 'sfromchi': False,
1160 # 'cols' : (255,0,0),
1161 # 'cola' : (200,200,200),
1165 # 'keep_coord' : True,
1169 ## self.tableau.actives = {}
1170 ## self.tableau.lchi = self.lchi
1171 ## self.tableau.chi = {}
1172 ## for i, val in enumerate(self.la) :
1173 ## self.tableau.actives[val] = [self.lfreq[i]]
1174 ## self.tableau.chi[val] = [self.lchi[i]]
1177 # self.tableau.chi = {}
1178 # self.tableau.lchi = self.lchi
1179 # self.tableau.parametre['fromprof'] = True
1180 # for i, val in enumerate(self.la) :
1181 # act[val] = [self.lfreq[i]]
1182 # self.tableau.chi[val] = [self.lchi[i]]
1183 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1185 # def onwordgraph(self, evt):
1186 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1187 # dlg = progressbar(self, 2)
1188 # corpus = self.Source.corpus
1189 # uces = corpus.lc[self.cl-1]
1190 # dlg.Update(1, u'Tableau...')
1191 # #tab = corpus.make_table_with_classe(uces, self.la)
1192 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1193 # self.filename = os.path.join(pathout,'mat01.csv')
1194 # dlg.Update(2, u'Ecriture...')
1195 # #corpus.write_tab(tab, self.filename)
1197 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1199 # paramsimi = {'coeff' : 0,
1204 # 'coeff_tv_nb' : 0,
1209 # 'coeff_temin' : 1,
1210 # 'coeff_temax' : 10,
1219 # 'cols' : (255,0,0),
1220 # 'cola' : (200,200,200),
1224 # 'keep_coord' : True,
1228 # self.tableau = Tableau(self.parent, '')
1229 # self.tableau.listactives = self.la
1230 # self.tableau.actives = {}
1231 # for i, val in enumerate(self.la) :
1232 # self.tableau.actives[val] = [self.lfreq[i]]
1233 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1236 def OnPopupOne(self, event):
1237 corpus = self.Source.corpus
1238 #print 'ATTENTION PRINT ET TABLE'
1239 #corpus.make_et_table()
1240 word = self.getColumnText(self.GetFirstSelected(), 6)
1241 lems = corpus.getlems()
1242 uces = corpus.lc[self.cl-1]
1244 #FIXME : donner aussi eff reel a la place de nb uce
1245 for forme in lems[word].formes :
1246 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1247 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1250 rep.append([corpus.getforme(forme).forme, nb])
1251 win = message(self, u"Formes associées", wx.Size(300, 200))
1252 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1253 win.HtmlPage.SetPage(win.html)
1256 # def on_graph(self, evt):
1257 # dlg = progressbar(self, 2)
1258 # corpus = self.Source.corpus
1259 # uces = corpus.lc[self.cl-1]
1260 # dlg.Update(1, u'Tableau...')
1261 # #tab = corpus.make_table_with_classe(uces, self.la)
1262 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1263 # self.filename = os.path.join(pathout,'mat01.csv')
1264 # dlg.Update(2, u'Ecriture...')
1265 # #corpus.write_tab(tab, self.filename)
1267 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1269 # paramsimi = {'coeff' : 0,
1274 # 'coeff_tv_nb' : 0,
1279 # 'coeff_temin' : 1,
1280 # 'coeff_temax' : 10,
1287 # 'cexfromchi' : True,
1288 # 'sfromchi': False,
1291 # 'cols' : (255,0,0),
1292 # 'cola' : (200,200,200),
1296 # 'keep_coord' : True,
1300 # self.tableau = Tableau(self.parent, '')
1301 # self.tableau.listactives = self.la
1302 # self.tableau.actives = {}
1303 # self.tableau.lchi = self.lchi
1304 # self.tableau.chi = {}
1305 # self.tableau.parametre['fromprof'] = True
1306 # for i, val in enumerate(self.la) :
1307 # self.tableau.actives[val] = [self.lfreq[i]]
1308 # self.tableau.chi[val] = [self.lchi[i]]
1309 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1311 # def on_segments(self,evt) :
1312 # dlg = progressbar(self, 2)
1313 # corpus = self.Source.corpus
1314 # uces = corpus.lc[self.cl-1]
1316 # dlg.Update(1, u'Segments...')
1317 # for i in range(2,10) :
1318 # li = corpus.find_segments_in_classe(uces, i, 1000)
1323 # l.sort(reverse = True)
1325 # dlg.Update(2, 'Tri...')
1326 # for i, line in enumerate(l) :
1327 # d[i] = [line[1],line[0], line[2]]
1328 # first = ['','','']
1329 # para={'dico': d,'fline':first}
1331 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1334 # def on_uce_carac(self,evt) :
1335 # dial = PrefUCECarac(self, self.parent)
1336 # dial.CenterOnParent()
1337 # if dial.ShowModal() == wx.ID_OK :
1338 # limite = dial.spin_eff.GetValue()
1339 # atype = dial.radio_type.GetSelection()
1340 # dlg = progressbar(self,maxi = 4)
1341 # corpus = self.Source.corpus
1342 # uces = corpus.lc[self.cl-1]
1343 # tab = corpus.make_table_with_classe(uces, self.la)
1345 # dlg.Update(2, u'score...')
1347 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1349 # 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]
1350 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1352 # ntab2.sort(reverse = True)
1353 # ntab2 = ntab2[:limite]
1354 # nuces = [val[1] for val in ntab2]
1355 # dlg.Update(3, u'concordancier...')
1356 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1357 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1360 # for uce in ucestxt1 :
1361 # ucetxt = ' '+uce[1]+' '
1362 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1363 # for lem in self.la :
1364 # listmot = corpus.getlems()[lem].formes
1365 # for id in listmot :
1366 # forme = corpus.getforme(id).forme
1367 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1368 # ucestxt.append(ucetxt)
1369 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1370 # dlg.Update(4, u'texte...')
1371 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1372 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1373 # 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>'
1374 # win.HtmlPage.SetPage(win.html)
1378 # def on_tablex(self, evt):
1379 # if 'corpus' in dir(self.Source):
1380 # corpus = self.Source.corpus
1382 # corpus = self.Source.tableau
1383 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1384 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1385 # title = chistable[0]
1388 # vchistable = [line[1:] for line in chistable]
1389 # fchistable = [line[0] for line in chistable]
1390 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1391 # tableout = [vchistable[fchistable.index(words[0])]]
1392 # last = self.list.GetFirstSelected()
1393 # while self.list.GetNextSelected(last) != -1:
1394 # last = self.list.GetNextSelected(last)
1395 # word = self.getColumnText(last, 6)
1396 # words.append(word)
1397 # tableout.append(vchistable[fchistable.index(word)])
1398 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1400 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1401 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1402 # file = open(tmpscript,'w')
1406 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1407 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1408 # win.addsaveimage(tmpgraph)
1409 # txt = "<img src='%s'>" % tmpgraph
1410 # win.HtmlPage.SetPage(txt)
1413 # def onlexdendro(self, evt):
1414 # if 'corpus' in dir(self.Source):
1415 # corpus = self.Source.corpus
1417 # corpus = self.Source.tableau
1418 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1419 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1420 # title = chistable[0]
1423 # vchistable = [line[1:] for line in chistable]
1424 # fchistable = [line[0] for line in chistable]
1425 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1426 # tableout = [vchistable[fchistable.index(words[0])]]
1427 # last = self.list.GetFirstSelected()
1428 # while self.list.GetNextSelected(last) != -1:
1429 # last = self.list.GetNextSelected(last)
1430 # word = self.getColumnText(last, 6)
1431 # words.append(word)
1432 # tableout.append(vchistable[fchistable.index(word)])
1433 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1434 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1435 # rownames = 'c("' + '","'.join(words) + '")'
1436 # colnames = 'c("' + '","'.join(title) + '")'
1438 # rownb = len(words)
1441 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1443 # colnames(di) <- %s
1446 # height <- (30*ncol(di)) + (15*nrow(di))
1447 # height <- ifelse(height <= 400, 400, height)
1449 # open_file_graph("%s", width=width, height=height)
1450 # plot.dendro.lex(tree.cut1$tree.cl, di)
1451 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1452 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1453 # file = open(tmpscript,'w')
1456 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1457 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1458 # win.addsaveimage(tmpgraph)
1459 # txt = "<img src='%s'>" % tmpgraph
1460 # win.HtmlPage.SetPage(txt)
1464 # def make_concord(self, uces, title, color = 'red') :
1465 # corpus = self.Source.corpus
1466 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1467 # last = self.list.GetFirstSelected()
1468 # while self.list.GetNextSelected(last) != -1:
1469 # last = self.list.GetNextSelected(last)
1470 # ListWord.append(self.getColumnText(last, 6))
1471 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1472 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1473 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1474 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1477 # for word in ListWord :
1478 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1479 # ucef = list(set(ucef))
1481 # res = corpus.getconcorde(ucef)
1482 # txt = '<br>'.join(toshow) +'<br><br>'
1484 # ucetxt = ' '+uce[1]+' '
1485 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1486 # for forme in listmot:
1487 # forme = corpus.getforme(forme).forme
1488 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1489 # txt += ucetxt + '<br><br>'
1490 # win.HtmlPage.SetPage(txt)
1493 # def OnPopupTwo(self, event):
1494 # corpus = self.Source.corpus
1495 # uces = corpus.lc[self.cl-1]
1496 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1499 # def OnPopupThree(self, event):
1500 # corpus = self.Source.corpus
1501 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1502 # win = self.make_concord(uces, "Concordancier - UCE classées")
1505 # def OnPopupFour(self, event):
1506 # corpus = self.Source.corpus
1507 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1508 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1511 # def OnPopupFive(self, event):
1512 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1513 # lk = "http://www.cnrtl.fr/definition/" + word
1514 # webbrowser.open(lk)
1516 # def OnPopupSix(self, event):
1517 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1518 # lk = "http://www.cnrtl.fr/etymologie/" + word
1519 # webbrowser.open(lk)
1521 # def OnPopupSeven(self, event):
1522 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1523 # lk = "http://www.cnrtl.fr/synonymie/" + word
1524 # webbrowser.open(lk)
1526 # def OnPopupHeight(self, event):
1527 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1528 # lk = "http://www.cnrtl.fr/antonymie/" + word
1529 # webbrowser.open(lk)
1531 # def OnPopupNine(self, event):
1532 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1533 # lk = "http://www.cnrtl.fr/morphologie/" + word
1534 # webbrowser.open(lk)
1536 # def onproxe(self, evt) :
1537 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1538 # lk = "http://www.cnrtl.fr/proxemie/" + word
1539 # webbrowser.open(lk)
1541 # def OnSize(self, event):
1542 # w, h = self.GetClientSizeTuple()
1543 # self.list.SetDimensions(0, 0, w, h)
1545 # def OnColClick(self, event):
1546 # self.do_greyline()
1549 #class wliste(wx.Frame):
1550 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1551 # wx.Frame.__init__(self, parent, id)
1552 # self.liste = ListForSpec(self, parent, d, fline)
1553 # self.button_1 = wx.Button(self, -1, "Fermer")
1554 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1555 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1556 # self.__do_layout()
1558 # def __do_layout(self):
1559 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1560 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1561 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1562 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1563 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1564 # self.SetAutoLayout(True)
1565 # self.SetSizer(sizer_1)
1568 # def OnCloseMe(self, event):
1571 # def OnCloseWindow(self, event):
1574 #class message(wx.Dialog):
1575 # def __init__(self, parent, title, size, save = True):
1576 # wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1578 # self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1581 # self.HtmlPage=wx.html.HtmlWindow(self, -1)
1582 # self.HtmlPage.SetMinSize( size )
1583 # if "gtk2" in wx.PlatformInfo:
1584 # self.HtmlPage.SetStandardFonts()
1585 # self.HtmlPage.SetFonts('Courier','Courier')
1587 # self.button_1 = wx.Button(self, wx.ID_CANCEL)
1589 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1591 # self.button_2 = wx.Button(self, wx.ID_SAVE)
1592 # self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1593 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1594 # self.__do_layout()
1596 # def __do_layout(self):
1597 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1598 # sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1599 # m_sdbSizer1 = wx.StdDialogButtonSizer()
1600 # m_sdbSizer1.AddButton( self.button_1 )
1602 # m_sdbSizer1.AddButton( self.button_2 )
1603 # m_sdbSizer1.Realize()
1604 # sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1605 # self.SetSizer(sizer_2)
1607 # sizer_2.Fit( self )
1609 # def OnSavePage(self, evt) :
1610 # dlg = wx.FileDialog(
1611 # self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1612 # defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1614 # dlg.SetFilterIndex(2)
1615 # dlg.CenterOnParent()
1616 # if dlg.ShowModal() == wx.ID_OK:
1617 # path = dlg.GetPath()
1618 # with open(path, 'w') as f :
1619 # f.write(self.html)
1621 # def OnCloseMe(self, event):
1624 # def OnCloseWindow(self, event):