1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
19 import wx.lib.mixins.listctrl as listmix
20 from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial, message
24 from tableau import Tableau
25 from search_tools import SearchFrame
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
41 self.Alceste = Alceste
46 line1 = profclasse.pop(0)
47 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
49 self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
50 profclasse.pop(self.lenact)
53 self.lenact = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
54 profclasse.pop(self.lenact)
56 self.lenact = len(profclasse)
58 self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
59 self.lensup = self.lensup - self.lenact
60 profclasse.pop(self.lensup)
62 self.lensup = len(profclasse) - self.lenact
63 self.lenet = len(profclasse) - (self.lenact + self.lensup)
64 # print self.lenact, self.lensup, self.lenet
65 for i, line in enumerate(classen) :
67 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
70 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
71 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
72 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
80 self.il = wx.ImageList(16, 16)
81 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
83 s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
85 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
87 #adding some attributes (colourful background for each item rows)
88 self.attr1 = wx.ListItemAttr()
89 self.attr1.SetBackgroundColour((220, 220, 220))
90 self.attrsg = wx.ListItemAttr()
91 self.attrsg.SetBackgroundColour((230, 230, 230))
92 self.attr2 = wx.ListItemAttr()
93 self.attr2.SetBackgroundColour((190, 249, 236))
94 self.attr2s = wx.ListItemAttr()
95 self.attr2s.SetBackgroundColour((211, 252, 244))
96 self.attr3 = wx.ListItemAttr()
97 self.attr3.SetBackgroundColour((245, 180, 180))
98 self.attr3s = wx.ListItemAttr()
99 self.attr3s.SetBackgroundColour((245, 190, 190))
102 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
103 self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
104 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
105 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
106 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
107 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
108 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
109 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
112 self.SetColumnWidth(0, 60)
113 self.SetColumnWidth(1, 70)
114 self.SetColumnWidth(2, 80)
115 self.SetColumnWidth(3, 100)
116 self.SetColumnWidth(4, 70)
117 self.SetColumnWidth(5, 60)
118 self.SetColumnWidth(6, 140)
119 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
121 #These two should probably be passed to init more cleanly
122 #setting the numbers of items = number of elements in the dictionary
123 self.itemDataMap = dictdata
124 self.itemIndexMap = dictdata.keys()
125 self.SetItemCount(len(dictdata))
128 listmix.ListCtrlAutoWidthMixin.__init__(self)
129 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
131 #sort by genre (column 2), A->Z ascending order (1)
132 self.SortListItems(0, 1)
135 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
136 #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
137 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
138 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
141 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
144 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
147 search_id = wx.NewId()
148 searchall_id = wx.NewId()
149 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
150 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
151 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
152 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
153 self.SetAcceleratorTable(self.accel_tbl)
157 def OnColClick(self,event):
160 def OnItemSelected(self, event):
161 self.currentItem = event.m_itemIndex
163 def OnItemActivated(self, event):
164 self.currentItem = event.m_itemIndex
166 def getColumnText(self, index, col):
167 item = self.GetItem(index, col)
168 return item.GetText()
170 def OnItemDeselected(self, evt):
172 #---------------------------------------------------
173 # These methods are callbacks for implementing the
174 # "virtualness" of the list...
176 def OnGetItemText(self, item, col):
177 index=self.itemIndexMap[item]
178 s = self.itemDataMap[index][col]
181 def OnGetItemImage(self, item):
182 index=self.itemIndexMap[item]
183 genre=self.itemDataMap[index][2]
189 elif genre=="New Age":
194 def OnGetItemAttr(self, item):
195 index=self.itemIndexMap[item]
196 if index < self.lenact :
201 elif index >= self.lenact and index < (self.lenact + self.lensup) :
206 elif index >= (self.lenact + self.lensup) :
214 #---------------------------------------------------
216 # Here's a better SortItems() method --
217 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
218 # and it knows to sort on another column if the chosen columns have the same value.
220 def SortItems(self,sorter=cmp):
221 items = list(self.itemDataMap.keys())
223 self.itemIndexMap = items
228 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
229 def GetListCtrl(self):
232 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
233 def GetSortImages(self):
234 return (self.sm_dn, self.sm_up)
236 def onsearch(self, evt) :
237 self.dial = SearchDial(self, self, 6, True)
238 self.dial.CenterOnParent()
239 self.dial.ShowModal()
242 def onsearchall(self, evt) :
243 if 'FrameSearch' not in dir(self.Source) :
244 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
245 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
246 self.dial.CenterOnParent()
247 self.dial.ShowModal()
250 def OnRightClick(self, event):
252 # only do this part the first time so the events are only bound once
254 if not hasattr(self, "popupID1"):
255 self.popupID1 = wx.NewId()
256 self.popupID2 = wx.NewId()
257 self.popupID3 = wx.NewId()
258 self.popupID4 = wx.NewId()
259 self.popupID5 = wx.NewId()
260 self.popupID6 = wx.NewId()
261 self.popupID7 = wx.NewId()
262 self.popupID8 = wx.NewId()
263 self.popupID9 = wx.NewId()
264 #self.popupID10 = wx.NewId()
265 self.popupIDgraph = wx.NewId()
266 self.idseg = wx.NewId()
267 self.iducecarac = wx.NewId()
268 self.idtablex = wx.NewId()
269 self.idchimod = wx.NewId()
270 self.idwordgraph = wx.NewId()
271 self.popup_proxe = wx.NewId()
272 self.idlexdendro = wx.NewId()
273 self.idexport = wx.NewId()
274 # self.export_classes = wx.NewId()
276 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
277 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
278 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
279 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
280 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
281 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
282 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
283 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
284 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
285 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
286 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
287 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
288 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
289 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
290 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
291 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
292 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
293 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
294 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
295 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
296 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
300 menu.Append(self.popupID1, u"Formes associées")
301 menu.Append(self.idtablex, u"Chi2 par classe")
302 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
303 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
304 menu.Append(self.idwordgraph, u"Graphe du mot")
305 #menu.Append(self.export_classes, u"Exporter le corpus...")
307 #menu.Append(self.popupID10, u"Spécificités")
309 menu_conc = wx.Menu()
310 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
311 menu_conc.Append(self.popupID3, u"dans les uce classées")
312 menu_conc.Append(self.popupID4, u"dans toutes les uce")
313 menu.AppendMenu(-1, u"Concordancier", menu_conc)
314 menu_cnrtl = wx.Menu()
315 menu_cnrtl.Append(self.popupID5, u"Définition")
316 menu_cnrtl.Append(self.popupID6, u"Etymologie")
317 menu_cnrtl.Append(self.popupID7, u"Synonymie")
318 menu_cnrtl.Append(self.popupID8, u"Antonymie")
319 menu_cnrtl.Append(self.popupID9, u"Morphologie")
320 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
321 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
322 menu.AppendSeparator()
323 menu.Append(self.popupIDgraph, u"Graphe de la classe")
324 menu.Append(self.idseg, u"Segments répétés")
325 menu.Append(self.iducecarac, u"UCE caractéristiques")
326 menu.Append(self.idexport, 'Partitionner...')
327 #menu.Append(self.popupID2, u"Concordancier")
328 # menu.Append(self.popupID3, "recharger")
332 elif 'tableau' in dir(self.Source) :
333 if not hasattr(self, "pop1"):
334 self.pop1 = wx.NewId()
335 self.pop2 = wx.NewId()
336 self.pop3 = wx.NewId()
337 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
338 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
339 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
342 menu.Append(self.pop2, u"Chi2 par classe")
343 menu.Append(self.pop3, u"Chi2 modalités de la variable")
344 menu.AppendSeparator()
345 menu.Append(self.pop1, u"Graph de la classe")
349 def onexport(self, evt) :
350 if 'corpus' in dir(self.Source):
351 corpus = self.Source.corpus
352 ClasseCHD(self.parent, corpus, self.cl)
354 def getselectedwords(self) :
355 words = [self.getColumnText(self.GetFirstSelected(), 6)]
356 last = self.GetFirstSelected()
357 while self.GetNextSelected(last) != -1:
358 last = self.GetNextSelected(last)
359 words.append(self.getColumnText(last, 6))
362 def quest_var_mod(self, evt) :
363 if 'corpus' in dir(self.Source):
364 corpus = self.Source.corpus
365 if self.var_mod == {} :
366 self.var_mod = self.Source.corpus.make_etoiles_dict()
368 corpus = self.Source.tableau
369 if self.var_mod == {} :
370 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
371 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
372 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
376 vchistable = [line[1:] for line in chistable]
377 fchistable = [line[0] for line in chistable]
378 word = self.getselectedwords()[0]
379 if len(word.split('_')) > 1 :
380 var = word.split('_')
381 words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
386 if word in fchistable :
387 tableout.append(vchistable[fchistable.index(word)])
389 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
390 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
391 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
392 file = open(tmpscript,'w')
395 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
396 win = MessageImage(self,u"Graphique", size=(700, 500))
397 win.addsaveimage(tmpgraph)
398 txt = "<img src='%s'>" % tmpgraph
399 win.HtmlPage.SetPage(txt)
402 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
403 dial.CenterOnParent()
407 def quest_simi(self, evt) :
408 tableau = self.Source.tableau
409 tab = tableau.make_table_from_classe(self.cl, self.la)
410 pathout = ConstructPathOut(os.path.join(self.Source.pathout, 'simi_classe_%i' %self.cl))
411 self.filename = os.path.join(pathout,'mat01.csv')
412 tableau.printtable(self.filename, tab)
414 paramsimi = {'coeff' : 0,
437 'cola' : (200,200,200),
445 # self.tableau.actives = {}
446 # self.tableau.lchi = self.lchi
447 # self.tableau.chi = {}
448 # for i, val in enumerate(self.la) :
449 # self.tableau.actives[val] = [self.lfreq[i]]
450 # self.tableau.chi[val] = [self.lchi[i]]
453 self.tableau.chi = {}
454 self.tableau.lchi = self.lchi
455 self.tableau.parametre['fromprof'] = True
456 for i, val in enumerate(self.la) :
457 act[val] = [self.lfreq[i]]
458 self.tableau.chi[val] = [self.lchi[i]]
459 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
461 def onwordgraph(self, evt):
462 word = self.getColumnText(self.GetFirstSelected(), 6)
463 if self.tmpchi is None :
464 self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
465 with open(self.tmpchi, 'w') as f:
466 f.write('\n'.join([str(val) for val in self.lchi]))
467 index = self.la.index(word)
468 parametres = {'type' : 'clustersimitxt',
469 'pathout' : self.Source.parametres['pathout'],
471 'lem' : self.Source.parametres['lem'],
472 'tmpchi' : self.tmpchi}
474 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
478 def on_graph(self, evt):
479 if self.tmpchi is None :
480 self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
481 with open(self.tmpchi, 'w') as f:
482 f.write('\n'.join([str(val) for val in self.lchi]))
483 parametres = {'type' : 'clustersimitxt',
484 'pathout' : self.Source.parametres['pathout'],
485 'lem' : self.Source.parametres['lem'],
486 'tmpchi' : self.tmpchi}
488 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
489 #dlg = progressbar(self, 2)
490 #corpus = self.Source.corpus
491 #uces = corpus.lc[self.cl-1]
492 #dlg.Update(1, u'Tableau...')
493 ##tab = corpus.make_table_with_classe(uces, self.la)
494 #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
495 #self.filename = os.path.join(pathout,'mat01.csv')
496 #dlg.Update(2, u'Ecriture...')
497 ##corpus.write_tab(tab, self.filename)
499 #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
501 #paramsimi = {'coeff' : 0,
512 # 'coeff_temax' : 10,
519 # 'cexfromchi' : True,
523 # 'cols' : (255,0,0),
524 # 'cola' : (200,200,200),
528 # 'keep_coord' : True,
532 #self.tableau = Tableau(self.parent, '')
533 #self.tableau.listactives = self.la
534 #self.tableau.actives = {}
535 #self.tableau.lchi = self.lchi
536 #self.tableau.chi = {}
537 #self.tableau.parametre['fromprof'] = True
538 #for i, val in enumerate(self.la) :
539 # self.tableau.actives[val] = [self.lfreq[i]]
540 # self.tableau.chi[val] = [self.lchi[i]]
541 #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
543 def on_segments(self,evt) :
544 dlg = progressbar(self, 2)
545 corpus = self.Source.corpus
546 uces = corpus.lc[self.cl-1]
548 dlg.Update(1, u'Segments...')
549 for i in range(2,10) :
550 li = corpus.find_segments_in_classe(uces, i, 1000)
555 l.sort(reverse = True)
557 dlg.Update(2, 'Tri...')
558 for i, line in enumerate(l) :
559 d[i] = [line[1],line[0], line[2]]
561 para={'dico': d,'fline':first}
563 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
566 def on_uce_carac(self,evt) :
567 dial = PrefUCECarac(self, self.parent)
568 dial.CenterOnParent()
569 if dial.ShowModal() == wx.ID_OK :
570 limite = dial.spin_eff.GetValue()
571 atype = dial.radio_type.GetSelection()
572 dlg = progressbar(self,maxi = 4)
573 corpus = self.Source.corpus
574 uces = corpus.lc[self.cl-1]
575 tab = corpus.make_table_with_classe(uces, self.la)
577 dlg.Update(2, u'score...')
579 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
581 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]
582 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
584 ntab2.sort(reverse = True)
585 ntab2 = ntab2[:limite]
586 nuces = [val[1] for val in ntab2]
587 dlg.Update(3, u'concordancier...')
588 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
589 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
592 for uce in ucestxt1 :
593 ucetxt = ' '+uce[1]+' '
594 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
596 listmot = corpus.getlems()[lem].formes
598 forme = corpus.getforme(id).forme
599 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
600 ucestxt.append(ucetxt)
601 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
602 dlg.Update(4, u'texte...')
603 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
604 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
605 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>'
606 win.HtmlPage.SetPage(win.html)
610 def on_tablex(self, evt):
611 if 'corpus' in dir(self.Source):
612 corpus = self.Source.corpus
614 corpus = self.Source.tableau
615 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
616 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
620 vchistable = [line[1:] for line in chistable]
621 fchistable = [line[0] for line in chistable]
622 words = self.getselectedwords()
623 tableout = [vchistable[fchistable.index(word)] for word in words]
624 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
627 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
628 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
629 file = open(tmpscript,'w')
632 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
633 w = 100 + (20 * nbwords) + (100 * nbcl)
634 h = 100 + (nbwords * 15)
635 if w > 1100 : w = 1100
638 win = MessageImage(self, u"Graphique", size=(w, h))
639 win.addsaveimage(tmpgraph)
640 txt = "<img src='%s'>" % tmpgraph
641 win.HtmlPage.SetPage(txt)
644 def onlexdendro(self, evt):
645 if 'corpus' in dir(self.Source):
646 corpus = self.Source.corpus
648 corpus = self.Source.tableau
649 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
650 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
654 vchistable = [line[1:] for line in chistable]
655 fchistable = [line[0] for line in chistable]
656 words = self.getselectedwords()
657 tableout = [vchistable[fchistable.index(word)] for word in words]
658 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
659 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
660 rownames = 'c("' + '","'.join(words) + '")'
661 colnames = 'c("' + '","'.join(title) + '")'
666 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
671 height <- (30*ncol(di)) + (15*nrow(di))
672 height <- ifelse(height <= 400, 400, height)
674 open_file_graph("%s", width=width, height=height)
675 plot.dendro.lex(tree.cut1$tree.cl, di)
676 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
677 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
678 file = open(tmpscript,'w')
681 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
682 win = MessageImage(self, u"Graphique", size=(700, 500))
683 win.addsaveimage(tmpgraph)
684 txt = "<img src='%s'>" % tmpgraph
685 win.HtmlPage.SetPage(txt)
689 def make_concord(self, uces, title, color = 'red') :
690 corpus = self.Source.corpus
691 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
692 last = self.GetFirstSelected()
693 while self.GetNextSelected(last) != -1:
694 last = self.GetNextSelected(last)
695 ListWord.append(self.getColumnText(last, 6))
696 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
697 win = message(self, title, size=(750, 600))
698 toshow = ['<html>\n<H1>Concordancier</H1>\n']
699 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
702 for word in ListWord :
703 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
704 ucef = list(set(ucef))
706 res = corpus.getconcorde(ucef)
707 txt = '<br>'.join(toshow) +'<br><br>'
709 ucetxt = ' '+uce[1]+' '
710 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
711 for forme in listmot:
712 forme = corpus.getforme(forme).forme
713 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
714 txt += ucetxt + '<br><br>'
715 win.HtmlPage.SetPage(txt)
718 def OnPopupTwo(self, event):
719 corpus = self.Source.corpus
720 uces = corpus.lc[self.cl-1]
721 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
724 def OnPopupThree(self, event):
725 corpus = self.Source.corpus
726 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
727 win = self.make_concord(uces, "Concordancier - UCE classées")
730 def OnPopupFour(self, event):
731 corpus = self.Source.corpus
732 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
733 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
736 def OnPopupFive(self, event):
737 word = self.getColumnText(self.GetFirstSelected(), 6)
738 lk = "http://www.cnrtl.fr/definition/" + word
741 def OnPopupSix(self, event):
742 word = self.getColumnText(self.GetFirstSelected(), 6)
743 lk = "http://www.cnrtl.fr/etymologie/" + word
746 def OnPopupSeven(self, event):
747 word = self.getColumnText(self.GetFirstSelected(), 6)
748 lk = "http://www.cnrtl.fr/synonymie/" + word
751 def OnPopupHeight(self, event):
752 word = self.getColumnText(self.GetFirstSelected(), 6)
753 lk = "http://www.cnrtl.fr/antonymie/" + word
756 def OnPopupNine(self, event):
757 word = self.getColumnText(self.GetFirstSelected(), 6)
758 lk = "http://www.cnrtl.fr/morphologie/" + word
761 def onproxe(self, evt) :
762 word = self.getColumnText(self.GetFirstSelected(), 6)
763 lk = "http://www.cnrtl.fr/proxemie/" + word
767 #---------------------------------------------------------------------------
768 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
769 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
770 # size=wx.DefaultSize, style=0):
771 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
772 # listmix.ListCtrlAutoWidthMixin.__init__(self)
775 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
776 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
777 # self.parent = parent
778 # classe = ProfClasse
780 # self.Source = gparent
781 # if 'tableau' in dir(self.Source):
782 # self.tableau = self.Source.tableau
783 # self.Alceste = Alceste
787 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
789 # search_id = wx.NewId()
790 # searchall_id = wx.NewId()
791 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
792 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
793 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
794 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
795 # self.SetAcceleratorTable(self.accel_tbl)
797 # self.il = wx.ImageList(16, 16)
798 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
799 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
800 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
803 # self.list = ProfListctrl(self, tID,
806 # | wx.LC_EDIT_LABELS
807 # | wx.LC_SORT_ASCENDING
809 # line1 = classe.pop(0)
814 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
815 # if len(classen) == 0 :
820 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
823 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
825 # lenact = len(classen)
829 # lenet = len(classen)
832 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
834 # lensup = lensup[0] - lenact
835 # lenet = len(classen) - lensup
838 # lenet = len(classen)
841 # self.lenact = lenact
843 # debet = lenact + lensup
844 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
845 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
847 # self.PopulateList(dictdata, debet, debsup, Alceste)
849 # self.Bind(wx.EVT_SIZE, self.OnSize)
850 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
851 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
854 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
857 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
858 # self.itemDataMap = dictdata
859 # listmix.ColumnSorterMixin.__init__(self, 8)
861 ##-----------------------------------------------------------------------------------------
863 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
866 # # for normal, simple columns, you can add them like this:
867 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
868 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
869 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
870 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
871 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
872 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
873 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
874 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
876 # for key in dictdata : #.iteritems():
877 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
879 # for val in dictdata[key][1:]:
880 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
882 # self.list.SetItemData(index, key)
884 # self.list.SetColumnWidth(0, 60)
885 # self.list.SetColumnWidth(1, 70)
886 # self.list.SetColumnWidth(2, 80)
887 # self.list.SetColumnWidth(3, 100)
888 # self.list.SetColumnWidth(4, 70)
889 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
890 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
891 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
893 # # show how to change the colour of a couple items
894 # for i in range(limitsup, limit):
895 # item = self.list.GetItem(i)
896 # item.SetTextColour(wx.RED)
897 # self.list.SetItem(item)
899 # for i in range(limit, len(dictdata)):
900 # item = self.list.GetItem(i)
901 # item.SetTextColour(wx.BLUE)
902 # self.list.SetItem(item)
904 # if self.lenact != 0 :
905 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
906 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
907 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
913 # def do_greyline(self):
914 # for row in xrange(self.list.GetItemCount()):
916 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
918 # self.list.SetItemBackgroundColour(row, wx.WHITE)
921 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
922 # def GetListCtrl(self):
925 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
926 # def GetSortImages(self):
927 # return (self.sm_dn, self.sm_up)
930 # def OnRightDown(self, event):
933 # item, flags = self.list.HitTest((x, y))
935 # if flags & wx.LIST_HITTEST_ONITEM:
936 # self.list.Select(item)
941 # def getColumnText(self, index, col):
942 # item = self.list.GetItem(index, col)
943 # return item.GetText()
946 # def OnItemSelected(self, event):
947 # self.currentItem = event.m_itemIndex
950 # def onsearch(self, evt) :
951 # self.dial = SearchDial(self, self, 6, True)
952 # self.dial.CenterOnParent()
953 # self.dial.ShowModal()
954 # self.dial.Destroy()
956 # def onsearchall(self, evt) :
957 # if 'FrameSearch' not in dir(self.Source) :
958 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
959 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
960 # self.dial.CenterOnParent()
961 # self.dial.ShowModal()
962 # self.dial.Destroy()
964 # def OnRightClick(self, event):
966 # # only do this part the first time so the events are only bound once
968 # if not hasattr(self, "popupID1"):
969 # self.popupID1 = wx.NewId()
970 # self.popupID2 = wx.NewId()
971 # self.popupID3 = wx.NewId()
972 # self.popupID4 = wx.NewId()
973 # self.popupID5 = wx.NewId()
974 # self.popupID6 = wx.NewId()
975 # self.popupID7 = wx.NewId()
976 # self.popupID8 = wx.NewId()
977 # self.popupID9 = wx.NewId()
978 # #self.popupID10 = wx.NewId()
979 # self.popupIDgraph = wx.NewId()
980 # self.idseg = wx.NewId()
981 # self.iducecarac = wx.NewId()
982 # self.idtablex = wx.NewId()
983 # self.idchimod = wx.NewId()
984 # self.idwordgraph = wx.NewId()
985 # self.popup_proxe = wx.NewId()
986 # self.idlexdendro = wx.NewId()
987 # self.idexport = wx.NewId()
988 # # self.export_classes = wx.NewId()
990 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
991 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
992 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
993 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
994 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
995 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
996 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
997 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
998 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
999 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1000 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1001 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1002 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1003 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1004 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1005 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1006 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1007 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1008 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1009 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1010 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1014 # menu.Append(self.popupID1, u"Formes associées")
1015 # menu.Append(self.idtablex, u"Chi2 par classe")
1016 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1017 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1018 # menu.Append(self.idwordgraph, u"Graphe du mot")
1019 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1021 # #menu.Append(self.popupID10, u"Spécificités")
1023 # menu_conc = wx.Menu()
1024 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1025 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1026 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1027 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1028 # menu_cnrtl = wx.Menu()
1029 # menu_cnrtl.Append(self.popupID5, u"Définition")
1030 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1031 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1032 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1033 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1034 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1035 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1036 # menu.AppendSeparator()
1037 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1038 # menu.Append(self.idseg, u"Segments répétés")
1039 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1040 # menu.Append(self.idexport, 'Partitionner...')
1041 # #menu.Append(self.popupID2, u"Concordancier")
1042 # # menu.Append(self.popupID3, "recharger")
1044 # self.PopupMenu(menu)
1046 # elif 'tableau' in dir(self.Source) :
1047 # if not hasattr(self, "pop1"):
1048 # self.pop1 = wx.NewId()
1049 # self.pop2 = wx.NewId()
1050 # self.pop3 = wx.NewId()
1051 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1052 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1053 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1056 # menu.Append(self.pop2, u"Chi2 par classe")
1057 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1058 # menu.AppendSeparator()
1059 # menu.Append(self.pop1, u"Graph de la classe")
1060 # self.PopupMenu(menu)
1063 # def onexport(self, evt) :
1064 # if 'corpus' in dir(self.Source):
1065 # corpus = self.Source.corpus
1066 # ClasseCHD(self.parent, corpus, self.cl)
1068 # def quest_var_mod(self, evt) :
1069 # if 'corpus' in dir(self.Source):
1070 # corpus = self.Source.corpus
1071 # if self.var_mod == {} :
1072 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1074 # corpus = self.Source.tableau
1075 # if self.var_mod == {} :
1076 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1077 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1078 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1079 # title = chistable[0]
1082 # vchistable = [line[1:] for line in chistable]
1083 # fchistable = [line[0] for line in chistable]
1084 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1085 # if len(word.split('_')) > 1 :
1086 # var = word.split('_')[0]
1087 # words = [word for word in self.var_mod[var]]
1091 # for word in words :
1092 # if word in fchistable :
1093 # tableout.append(vchistable[fchistable.index(word)])
1094 # kwords.append(word)
1095 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1096 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1097 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1098 # file = open(tmpscript,'w')
1101 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1102 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1103 # win.addsaveimage(tmpgraph)
1104 # txt = "<img src='%s'>" % tmpgraph
1105 # win.HtmlPage.SetPage(txt)
1108 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1109 # dial.CenterOnParent()
1113 # def quest_simi(self, evt) :
1114 # tableau = self.Source.tableau
1115 # tab = tableau.make_table_from_classe(self.cl, self.la)
1116 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1117 # self.filename = os.path.join(pathout,'mat01.csv')
1118 # tableau.printtable(self.filename, tab)
1120 # paramsimi = {'coeff' : 0,
1125 # 'coeff_tv_nb' : 0,
1130 # 'coeff_temin' : 1,
1131 # 'coeff_temax' : 10,
1138 # 'cexfromchi' : True,
1139 # 'sfromchi': False,
1142 # 'cols' : (255,0,0),
1143 # 'cola' : (200,200,200),
1147 # 'keep_coord' : True,
1151 ## self.tableau.actives = {}
1152 ## self.tableau.lchi = self.lchi
1153 ## self.tableau.chi = {}
1154 ## for i, val in enumerate(self.la) :
1155 ## self.tableau.actives[val] = [self.lfreq[i]]
1156 ## self.tableau.chi[val] = [self.lchi[i]]
1159 # self.tableau.chi = {}
1160 # self.tableau.lchi = self.lchi
1161 # self.tableau.parametre['fromprof'] = True
1162 # for i, val in enumerate(self.la) :
1163 # act[val] = [self.lfreq[i]]
1164 # self.tableau.chi[val] = [self.lchi[i]]
1165 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1167 # def onwordgraph(self, evt):
1168 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1169 # dlg = progressbar(self, 2)
1170 # corpus = self.Source.corpus
1171 # uces = corpus.lc[self.cl-1]
1172 # dlg.Update(1, u'Tableau...')
1173 # #tab = corpus.make_table_with_classe(uces, self.la)
1174 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1175 # self.filename = os.path.join(pathout,'mat01.csv')
1176 # dlg.Update(2, u'Ecriture...')
1177 # #corpus.write_tab(tab, self.filename)
1179 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1181 # paramsimi = {'coeff' : 0,
1186 # 'coeff_tv_nb' : 0,
1191 # 'coeff_temin' : 1,
1192 # 'coeff_temax' : 10,
1201 # 'cols' : (255,0,0),
1202 # 'cola' : (200,200,200),
1206 # 'keep_coord' : True,
1210 # self.tableau = Tableau(self.parent, '')
1211 # self.tableau.listactives = self.la
1212 # self.tableau.actives = {}
1213 # for i, val in enumerate(self.la) :
1214 # self.tableau.actives[val] = [self.lfreq[i]]
1215 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1218 def OnPopupOne(self, event):
1219 corpus = self.Source.corpus
1220 #print 'ATTENTION PRINT ET TABLE'
1221 #corpus.make_et_table()
1222 word = self.getColumnText(self.GetFirstSelected(), 6)
1223 lems = corpus.getlems()
1224 uces = corpus.lc[self.cl-1]
1226 #FIXME : donner aussi eff reel a la place de nb uce
1227 for forme in lems[word].formes :
1228 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1229 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1232 rep.append([corpus.getforme(forme).forme, nb])
1233 win = message(self, u"Formes associées", wx.Size(300, 200))
1234 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1235 win.HtmlPage.SetPage(win.html)
1238 # def on_graph(self, evt):
1239 # dlg = progressbar(self, 2)
1240 # corpus = self.Source.corpus
1241 # uces = corpus.lc[self.cl-1]
1242 # dlg.Update(1, u'Tableau...')
1243 # #tab = corpus.make_table_with_classe(uces, self.la)
1244 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1245 # self.filename = os.path.join(pathout,'mat01.csv')
1246 # dlg.Update(2, u'Ecriture...')
1247 # #corpus.write_tab(tab, self.filename)
1249 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1251 # paramsimi = {'coeff' : 0,
1256 # 'coeff_tv_nb' : 0,
1261 # 'coeff_temin' : 1,
1262 # 'coeff_temax' : 10,
1269 # 'cexfromchi' : True,
1270 # 'sfromchi': False,
1273 # 'cols' : (255,0,0),
1274 # 'cola' : (200,200,200),
1278 # 'keep_coord' : True,
1282 # self.tableau = Tableau(self.parent, '')
1283 # self.tableau.listactives = self.la
1284 # self.tableau.actives = {}
1285 # self.tableau.lchi = self.lchi
1286 # self.tableau.chi = {}
1287 # self.tableau.parametre['fromprof'] = True
1288 # for i, val in enumerate(self.la) :
1289 # self.tableau.actives[val] = [self.lfreq[i]]
1290 # self.tableau.chi[val] = [self.lchi[i]]
1291 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1293 # def on_segments(self,evt) :
1294 # dlg = progressbar(self, 2)
1295 # corpus = self.Source.corpus
1296 # uces = corpus.lc[self.cl-1]
1298 # dlg.Update(1, u'Segments...')
1299 # for i in range(2,10) :
1300 # li = corpus.find_segments_in_classe(uces, i, 1000)
1305 # l.sort(reverse = True)
1307 # dlg.Update(2, 'Tri...')
1308 # for i, line in enumerate(l) :
1309 # d[i] = [line[1],line[0], line[2]]
1310 # first = ['','','']
1311 # para={'dico': d,'fline':first}
1313 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1316 # def on_uce_carac(self,evt) :
1317 # dial = PrefUCECarac(self, self.parent)
1318 # dial.CenterOnParent()
1319 # if dial.ShowModal() == wx.ID_OK :
1320 # limite = dial.spin_eff.GetValue()
1321 # atype = dial.radio_type.GetSelection()
1322 # dlg = progressbar(self,maxi = 4)
1323 # corpus = self.Source.corpus
1324 # uces = corpus.lc[self.cl-1]
1325 # tab = corpus.make_table_with_classe(uces, self.la)
1327 # dlg.Update(2, u'score...')
1329 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1331 # 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]
1332 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1334 # ntab2.sort(reverse = True)
1335 # ntab2 = ntab2[:limite]
1336 # nuces = [val[1] for val in ntab2]
1337 # dlg.Update(3, u'concordancier...')
1338 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1339 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1342 # for uce in ucestxt1 :
1343 # ucetxt = ' '+uce[1]+' '
1344 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1345 # for lem in self.la :
1346 # listmot = corpus.getlems()[lem].formes
1347 # for id in listmot :
1348 # forme = corpus.getforme(id).forme
1349 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1350 # ucestxt.append(ucetxt)
1351 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1352 # dlg.Update(4, u'texte...')
1353 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1354 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1355 # 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>'
1356 # win.HtmlPage.SetPage(win.html)
1360 # def on_tablex(self, evt):
1361 # if 'corpus' in dir(self.Source):
1362 # corpus = self.Source.corpus
1364 # corpus = self.Source.tableau
1365 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1366 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1367 # title = chistable[0]
1370 # vchistable = [line[1:] for line in chistable]
1371 # fchistable = [line[0] for line in chistable]
1372 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1373 # tableout = [vchistable[fchistable.index(words[0])]]
1374 # last = self.list.GetFirstSelected()
1375 # while self.list.GetNextSelected(last) != -1:
1376 # last = self.list.GetNextSelected(last)
1377 # word = self.getColumnText(last, 6)
1378 # words.append(word)
1379 # tableout.append(vchistable[fchistable.index(word)])
1380 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1382 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1383 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1384 # file = open(tmpscript,'w')
1388 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1389 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1390 # win.addsaveimage(tmpgraph)
1391 # txt = "<img src='%s'>" % tmpgraph
1392 # win.HtmlPage.SetPage(txt)
1395 # def onlexdendro(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)
1416 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1417 # rownames = 'c("' + '","'.join(words) + '")'
1418 # colnames = 'c("' + '","'.join(title) + '")'
1420 # rownb = len(words)
1423 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1425 # colnames(di) <- %s
1428 # height <- (30*ncol(di)) + (15*nrow(di))
1429 # height <- ifelse(height <= 400, 400, height)
1431 # open_file_graph("%s", width=width, height=height)
1432 # plot.dendro.lex(tree.cut1$tree.cl, di)
1433 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1434 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1435 # file = open(tmpscript,'w')
1438 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1439 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1440 # win.addsaveimage(tmpgraph)
1441 # txt = "<img src='%s'>" % tmpgraph
1442 # win.HtmlPage.SetPage(txt)
1446 # def make_concord(self, uces, title, color = 'red') :
1447 # corpus = self.Source.corpus
1448 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1449 # last = self.list.GetFirstSelected()
1450 # while self.list.GetNextSelected(last) != -1:
1451 # last = self.list.GetNextSelected(last)
1452 # ListWord.append(self.getColumnText(last, 6))
1453 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1454 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1455 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1456 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1459 # for word in ListWord :
1460 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1461 # ucef = list(set(ucef))
1463 # res = corpus.getconcorde(ucef)
1464 # txt = '<br>'.join(toshow) +'<br><br>'
1466 # ucetxt = ' '+uce[1]+' '
1467 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1468 # for forme in listmot:
1469 # forme = corpus.getforme(forme).forme
1470 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1471 # txt += ucetxt + '<br><br>'
1472 # win.HtmlPage.SetPage(txt)
1475 # def OnPopupTwo(self, event):
1476 # corpus = self.Source.corpus
1477 # uces = corpus.lc[self.cl-1]
1478 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1481 # def OnPopupThree(self, event):
1482 # corpus = self.Source.corpus
1483 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1484 # win = self.make_concord(uces, "Concordancier - UCE classées")
1487 # def OnPopupFour(self, event):
1488 # corpus = self.Source.corpus
1489 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1490 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1493 # def OnPopupFive(self, event):
1494 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1495 # lk = "http://www.cnrtl.fr/definition/" + word
1496 # webbrowser.open(lk)
1498 # def OnPopupSix(self, event):
1499 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1500 # lk = "http://www.cnrtl.fr/etymologie/" + word
1501 # webbrowser.open(lk)
1503 # def OnPopupSeven(self, event):
1504 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1505 # lk = "http://www.cnrtl.fr/synonymie/" + word
1506 # webbrowser.open(lk)
1508 # def OnPopupHeight(self, event):
1509 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1510 # lk = "http://www.cnrtl.fr/antonymie/" + word
1511 # webbrowser.open(lk)
1513 # def OnPopupNine(self, event):
1514 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1515 # lk = "http://www.cnrtl.fr/morphologie/" + word
1516 # webbrowser.open(lk)
1518 # def onproxe(self, evt) :
1519 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1520 # lk = "http://www.cnrtl.fr/proxemie/" + word
1521 # webbrowser.open(lk)
1523 # def OnSize(self, event):
1524 # w, h = self.GetClientSizeTuple()
1525 # self.list.SetDimensions(0, 0, w, h)
1527 # def OnColClick(self, event):
1528 # self.do_greyline()
1531 #class wliste(wx.Frame):
1532 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1533 # wx.Frame.__init__(self, parent, id)
1534 # self.liste = ListForSpec(self, parent, d, fline)
1535 # self.button_1 = wx.Button(self, -1, "Fermer")
1536 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1537 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1538 # self.__do_layout()
1540 # def __do_layout(self):
1541 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1542 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1543 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1544 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1545 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1546 # self.SetAutoLayout(True)
1547 # self.SetSizer(sizer_1)
1550 # def OnCloseMe(self, event):
1553 # def OnCloseWindow(self, event):
1556 #class message(wx.Dialog):
1557 # def __init__(self, parent, title, size, save = True):
1558 # wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1560 # self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1563 # self.HtmlPage=wx.html.HtmlWindow(self, -1)
1564 # self.HtmlPage.SetMinSize( size )
1565 # if "gtk2" in wx.PlatformInfo:
1566 # self.HtmlPage.SetStandardFonts()
1567 # self.HtmlPage.SetFonts('Courier','Courier')
1569 # self.button_1 = wx.Button(self, wx.ID_CANCEL)
1571 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1573 # self.button_2 = wx.Button(self, wx.ID_SAVE)
1574 # self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1575 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1576 # self.__do_layout()
1578 # def __do_layout(self):
1579 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1580 # sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1581 # m_sdbSizer1 = wx.StdDialogButtonSizer()
1582 # m_sdbSizer1.AddButton( self.button_1 )
1584 # m_sdbSizer1.AddButton( self.button_2 )
1585 # m_sdbSizer1.Realize()
1586 # sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1587 # self.SetSizer(sizer_2)
1589 # sizer_2.Fit( self )
1591 # def OnSavePage(self, evt) :
1592 # dlg = wx.FileDialog(
1593 # self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1594 # defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1596 # dlg.SetFilterIndex(2)
1597 # dlg.CenterOnParent()
1598 # if dlg.ShowModal() == wx.ID_OK:
1599 # path = dlg.GetPath()
1600 # with open(path, 'w') as f :
1601 # f.write(self.html)
1603 # def OnCloseMe(self, event):
1606 # def OnCloseWindow(self, event):