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]
380 if len(word.split('_')) > 1 :
381 var = word.split('_')
382 #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
383 words = [word for word in self.var_mod[var[0]]]
389 if word in fchistable :
390 tableout.append(vchistable[fchistable.index(word)])
392 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
394 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
395 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
396 file = open(tmpscript,'w')
399 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
400 win = MessageImage(self,u"Graphique", size=(700, 500))
401 win.addsaveimage(tmpgraph)
402 txt = "<img src='%s'>" % tmpgraph
403 win.HtmlPage.SetPage(txt)
406 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
407 dial.CenterOnParent()
411 def quest_simi(self, evt) :
412 tableau = self.Source.tableau
413 tab = tableau.make_table_from_classe(self.cl, self.la)
414 pathout = ConstructPathOut(os.path.join(self.Source.pathout, 'simi_classe_%i' %self.cl))
415 self.filename = os.path.join(pathout,'mat01.csv')
416 tableau.printtable(self.filename, tab)
418 paramsimi = {'coeff' : 0,
441 'cola' : (200,200,200),
449 # self.tableau.actives = {}
450 # self.tableau.lchi = self.lchi
451 # self.tableau.chi = {}
452 # for i, val in enumerate(self.la) :
453 # self.tableau.actives[val] = [self.lfreq[i]]
454 # self.tableau.chi[val] = [self.lchi[i]]
457 self.tableau.chi = {}
458 self.tableau.lchi = self.lchi
459 self.tableau.parametre['fromprof'] = True
460 for i, val in enumerate(self.la) :
461 act[val] = [self.lfreq[i]]
462 self.tableau.chi[val] = [self.lchi[i]]
463 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
465 def onwordgraph(self, evt):
466 word = self.getColumnText(self.GetFirstSelected(), 6)
467 if self.tmpchi is None :
468 self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
469 with open(self.tmpchi, 'w') as f:
470 f.write('\n'.join([str(val) for val in self.lchi]))
471 index = self.la.index(word)
472 parametres = {'type' : 'clustersimitxt',
473 'pathout' : self.Source.parametres['pathout'],
475 'lem' : self.Source.parametres['lem'],
476 'tmpchi' : self.tmpchi}
478 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
482 def on_graph(self, evt):
483 if self.tmpchi is None :
484 self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
485 with open(self.tmpchi, 'w') as f:
486 f.write('\n'.join([str(val) for val in self.lchi]))
487 parametres = {'type' : 'clustersimitxt',
488 'pathout' : self.Source.parametres['pathout'],
489 'lem' : self.Source.parametres['lem'],
490 'tmpchi' : self.tmpchi}
492 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
493 #dlg = progressbar(self, 2)
494 #corpus = self.Source.corpus
495 #uces = corpus.lc[self.cl-1]
496 #dlg.Update(1, u'Tableau...')
497 ##tab = corpus.make_table_with_classe(uces, self.la)
498 #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
499 #self.filename = os.path.join(pathout,'mat01.csv')
500 #dlg.Update(2, u'Ecriture...')
501 ##corpus.write_tab(tab, self.filename)
503 #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
505 #paramsimi = {'coeff' : 0,
516 # 'coeff_temax' : 10,
523 # 'cexfromchi' : True,
527 # 'cols' : (255,0,0),
528 # 'cola' : (200,200,200),
532 # 'keep_coord' : True,
536 #self.tableau = Tableau(self.parent, '')
537 #self.tableau.listactives = self.la
538 #self.tableau.actives = {}
539 #self.tableau.lchi = self.lchi
540 #self.tableau.chi = {}
541 #self.tableau.parametre['fromprof'] = True
542 #for i, val in enumerate(self.la) :
543 # self.tableau.actives[val] = [self.lfreq[i]]
544 # self.tableau.chi[val] = [self.lchi[i]]
545 #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
547 def on_segments(self,evt) :
548 dlg = progressbar(self, 2)
549 corpus = self.Source.corpus
550 uces = corpus.lc[self.cl-1]
552 dlg.Update(1, u'Segments...')
553 for i in range(2,10) :
554 li = corpus.find_segments_in_classe(uces, i, 1000)
559 l.sort(reverse = True)
561 dlg.Update(2, 'Tri...')
562 for i, line in enumerate(l) :
563 d[i] = [line[1],line[0], line[2]]
565 para={'dico': d,'fline':first}
567 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
570 def on_uce_carac(self,evt) :
571 dial = PrefUCECarac(self, self.parent)
572 dial.CenterOnParent()
573 if dial.ShowModal() == wx.ID_OK :
574 limite = dial.spin_eff.GetValue()
575 atype = dial.radio_type.GetSelection()
576 dlg = progressbar(self,maxi = 4)
577 corpus = self.Source.corpus
578 uces = corpus.lc[self.cl-1]
579 tab = corpus.make_table_with_classe(uces, self.la)
581 dlg.Update(2, u'score...')
583 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
585 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]
586 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
588 ntab2.sort(reverse = True)
589 ntab2 = ntab2[:limite]
590 nuces = [val[1] for val in ntab2]
591 dlg.Update(3, u'concordancier...')
592 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
593 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
596 for uce in ucestxt1 :
597 ucetxt = ' '+uce[1]+' '
598 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
600 listmot = corpus.getlems()[lem].formes
602 forme = corpus.getforme(id).forme
603 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
604 ucestxt.append(ucetxt)
605 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
606 dlg.Update(4, u'texte...')
607 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
608 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
609 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>'
610 win.HtmlPage.SetPage(win.html)
614 def on_tablex(self, evt):
615 if 'corpus' in dir(self.Source):
616 corpus = self.Source.corpus
618 corpus = self.Source.tableau
619 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
620 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
624 vchistable = [line[1:] for line in chistable]
625 fchistable = [line[0] for line in chistable]
626 words = self.getselectedwords()
627 tableout = [vchistable[fchistable.index(word)] for word in words]
628 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
631 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
632 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
633 file = open(tmpscript,'w')
636 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
637 w = 100 + (20 * nbwords) + (100 * nbcl)
638 h = 100 + (nbwords * 15)
639 if w > 1100 : w = 1100
642 win = MessageImage(self, u"Graphique", size=(w, h))
643 win.addsaveimage(tmpgraph)
644 txt = "<img src='%s'>" % tmpgraph
645 win.HtmlPage.SetPage(txt)
648 def onlexdendro(self, evt):
649 if 'corpus' in dir(self.Source):
650 corpus = self.Source.corpus
652 corpus = self.Source.tableau
653 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
654 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
658 vchistable = [line[1:] for line in chistable]
659 fchistable = [line[0] for line in chistable]
660 words = self.getselectedwords()
661 tableout = [vchistable[fchistable.index(word)] for word in words]
662 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
663 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
664 rownames = 'c("' + '","'.join(words) + '")'
665 colnames = 'c("' + '","'.join(title) + '")'
670 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
675 height <- (30*ncol(di)) + (15*nrow(di))
676 height <- ifelse(height <= 400, 400, height)
678 open_file_graph("%s", width=width, height=height)
679 plot.dendro.lex(tree.cut1$tree.cl, di)
680 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
681 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
682 file = open(tmpscript,'w')
685 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
686 win = MessageImage(self, u"Graphique", size=(700, 500))
687 win.addsaveimage(tmpgraph)
688 txt = "<img src='%s'>" % tmpgraph
689 win.HtmlPage.SetPage(txt)
693 def make_concord(self, uces, title, color = 'red') :
694 corpus = self.Source.corpus
695 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
696 last = self.GetFirstSelected()
697 while self.GetNextSelected(last) != -1:
698 last = self.GetNextSelected(last)
699 ListWord.append(self.getColumnText(last, 6))
700 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
701 win = message(self, title, size=(750, 600))
702 toshow = ['<html>\n<H1>Concordancier</H1>\n']
703 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
706 for word in ListWord :
707 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
708 ucef = list(set(ucef))
710 res = corpus.getconcorde(ucef)
711 txt = '<br>'.join(toshow) +'<br><br>'
713 ucetxt = ' '+uce[1]+' '
714 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
715 for forme in listmot:
716 forme = corpus.getforme(forme).forme
717 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
718 txt += ucetxt + '<br><br>'
719 win.HtmlPage.SetPage(txt)
722 def OnPopupTwo(self, event):
723 corpus = self.Source.corpus
724 uces = corpus.lc[self.cl-1]
725 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
728 def OnPopupThree(self, event):
729 corpus = self.Source.corpus
730 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
731 win = self.make_concord(uces, "Concordancier - UCE classées")
734 def OnPopupFour(self, event):
735 corpus = self.Source.corpus
736 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
737 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
740 def OnPopupFive(self, event):
741 word = self.getColumnText(self.GetFirstSelected(), 6)
742 lk = "http://www.cnrtl.fr/definition/" + word
745 def OnPopupSix(self, event):
746 word = self.getColumnText(self.GetFirstSelected(), 6)
747 lk = "http://www.cnrtl.fr/etymologie/" + word
750 def OnPopupSeven(self, event):
751 word = self.getColumnText(self.GetFirstSelected(), 6)
752 lk = "http://www.cnrtl.fr/synonymie/" + word
755 def OnPopupHeight(self, event):
756 word = self.getColumnText(self.GetFirstSelected(), 6)
757 lk = "http://www.cnrtl.fr/antonymie/" + word
760 def OnPopupNine(self, event):
761 word = self.getColumnText(self.GetFirstSelected(), 6)
762 lk = "http://www.cnrtl.fr/morphologie/" + word
765 def onproxe(self, evt) :
766 word = self.getColumnText(self.GetFirstSelected(), 6)
767 lk = "http://www.cnrtl.fr/proxemie/" + word
771 #---------------------------------------------------------------------------
772 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
773 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
774 # size=wx.DefaultSize, style=0):
775 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
776 # listmix.ListCtrlAutoWidthMixin.__init__(self)
779 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
780 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
781 # self.parent = parent
782 # classe = ProfClasse
784 # self.Source = gparent
785 # if 'tableau' in dir(self.Source):
786 # self.tableau = self.Source.tableau
787 # self.Alceste = Alceste
791 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
793 # search_id = wx.NewId()
794 # searchall_id = wx.NewId()
795 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
796 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
797 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
798 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
799 # self.SetAcceleratorTable(self.accel_tbl)
801 # self.il = wx.ImageList(16, 16)
802 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
803 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
804 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
807 # self.list = ProfListctrl(self, tID,
810 # | wx.LC_EDIT_LABELS
811 # | wx.LC_SORT_ASCENDING
813 # line1 = classe.pop(0)
818 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
819 # if len(classen) == 0 :
824 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
827 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
829 # lenact = len(classen)
833 # lenet = len(classen)
836 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
838 # lensup = lensup[0] - lenact
839 # lenet = len(classen) - lensup
842 # lenet = len(classen)
845 # self.lenact = lenact
847 # debet = lenact + lensup
848 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
849 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
851 # self.PopulateList(dictdata, debet, debsup, Alceste)
853 # self.Bind(wx.EVT_SIZE, self.OnSize)
854 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
855 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
858 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
861 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
862 # self.itemDataMap = dictdata
863 # listmix.ColumnSorterMixin.__init__(self, 8)
865 ##-----------------------------------------------------------------------------------------
867 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
870 # # for normal, simple columns, you can add them like this:
871 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
872 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
873 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
874 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
875 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
876 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
877 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
878 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
880 # for key in dictdata : #.iteritems():
881 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
883 # for val in dictdata[key][1:]:
884 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
886 # self.list.SetItemData(index, key)
888 # self.list.SetColumnWidth(0, 60)
889 # self.list.SetColumnWidth(1, 70)
890 # self.list.SetColumnWidth(2, 80)
891 # self.list.SetColumnWidth(3, 100)
892 # self.list.SetColumnWidth(4, 70)
893 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
894 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
895 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
897 # # show how to change the colour of a couple items
898 # for i in range(limitsup, limit):
899 # item = self.list.GetItem(i)
900 # item.SetTextColour(wx.RED)
901 # self.list.SetItem(item)
903 # for i in range(limit, len(dictdata)):
904 # item = self.list.GetItem(i)
905 # item.SetTextColour(wx.BLUE)
906 # self.list.SetItem(item)
908 # if self.lenact != 0 :
909 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
910 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
911 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
917 # def do_greyline(self):
918 # for row in xrange(self.list.GetItemCount()):
920 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
922 # self.list.SetItemBackgroundColour(row, wx.WHITE)
925 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
926 # def GetListCtrl(self):
929 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
930 # def GetSortImages(self):
931 # return (self.sm_dn, self.sm_up)
934 # def OnRightDown(self, event):
937 # item, flags = self.list.HitTest((x, y))
939 # if flags & wx.LIST_HITTEST_ONITEM:
940 # self.list.Select(item)
945 # def getColumnText(self, index, col):
946 # item = self.list.GetItem(index, col)
947 # return item.GetText()
950 # def OnItemSelected(self, event):
951 # self.currentItem = event.m_itemIndex
954 # def onsearch(self, evt) :
955 # self.dial = SearchDial(self, self, 6, True)
956 # self.dial.CenterOnParent()
957 # self.dial.ShowModal()
958 # self.dial.Destroy()
960 # def onsearchall(self, evt) :
961 # if 'FrameSearch' not in dir(self.Source) :
962 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
963 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
964 # self.dial.CenterOnParent()
965 # self.dial.ShowModal()
966 # self.dial.Destroy()
968 # def OnRightClick(self, event):
970 # # only do this part the first time so the events are only bound once
972 # if not hasattr(self, "popupID1"):
973 # self.popupID1 = wx.NewId()
974 # self.popupID2 = wx.NewId()
975 # self.popupID3 = wx.NewId()
976 # self.popupID4 = wx.NewId()
977 # self.popupID5 = wx.NewId()
978 # self.popupID6 = wx.NewId()
979 # self.popupID7 = wx.NewId()
980 # self.popupID8 = wx.NewId()
981 # self.popupID9 = wx.NewId()
982 # #self.popupID10 = wx.NewId()
983 # self.popupIDgraph = wx.NewId()
984 # self.idseg = wx.NewId()
985 # self.iducecarac = wx.NewId()
986 # self.idtablex = wx.NewId()
987 # self.idchimod = wx.NewId()
988 # self.idwordgraph = wx.NewId()
989 # self.popup_proxe = wx.NewId()
990 # self.idlexdendro = wx.NewId()
991 # self.idexport = wx.NewId()
992 # # self.export_classes = wx.NewId()
994 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
995 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
996 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
997 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
998 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
999 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1000 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1001 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1002 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1003 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1004 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1005 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1006 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1007 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1008 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1009 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1010 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1011 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1012 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1013 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1014 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1018 # menu.Append(self.popupID1, u"Formes associées")
1019 # menu.Append(self.idtablex, u"Chi2 par classe")
1020 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1021 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1022 # menu.Append(self.idwordgraph, u"Graphe du mot")
1023 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1025 # #menu.Append(self.popupID10, u"Spécificités")
1027 # menu_conc = wx.Menu()
1028 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1029 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1030 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1031 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1032 # menu_cnrtl = wx.Menu()
1033 # menu_cnrtl.Append(self.popupID5, u"Définition")
1034 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1035 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1036 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1037 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1038 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1039 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1040 # menu.AppendSeparator()
1041 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1042 # menu.Append(self.idseg, u"Segments répétés")
1043 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1044 # menu.Append(self.idexport, 'Partitionner...')
1045 # #menu.Append(self.popupID2, u"Concordancier")
1046 # # menu.Append(self.popupID3, "recharger")
1048 # self.PopupMenu(menu)
1050 # elif 'tableau' in dir(self.Source) :
1051 # if not hasattr(self, "pop1"):
1052 # self.pop1 = wx.NewId()
1053 # self.pop2 = wx.NewId()
1054 # self.pop3 = wx.NewId()
1055 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1056 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1057 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1060 # menu.Append(self.pop2, u"Chi2 par classe")
1061 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1062 # menu.AppendSeparator()
1063 # menu.Append(self.pop1, u"Graph de la classe")
1064 # self.PopupMenu(menu)
1067 # def onexport(self, evt) :
1068 # if 'corpus' in dir(self.Source):
1069 # corpus = self.Source.corpus
1070 # ClasseCHD(self.parent, corpus, self.cl)
1072 # def quest_var_mod(self, evt) :
1073 # if 'corpus' in dir(self.Source):
1074 # corpus = self.Source.corpus
1075 # if self.var_mod == {} :
1076 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1078 # corpus = self.Source.tableau
1079 # if self.var_mod == {} :
1080 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1081 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1082 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1083 # title = chistable[0]
1086 # vchistable = [line[1:] for line in chistable]
1087 # fchistable = [line[0] for line in chistable]
1088 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1089 # if len(word.split('_')) > 1 :
1090 # var = word.split('_')[0]
1091 # words = [word for word in self.var_mod[var]]
1095 # for word in words :
1096 # if word in fchistable :
1097 # tableout.append(vchistable[fchistable.index(word)])
1098 # kwords.append(word)
1099 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1100 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1101 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1102 # file = open(tmpscript,'w')
1105 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1106 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1107 # win.addsaveimage(tmpgraph)
1108 # txt = "<img src='%s'>" % tmpgraph
1109 # win.HtmlPage.SetPage(txt)
1112 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1113 # dial.CenterOnParent()
1117 # def quest_simi(self, evt) :
1118 # tableau = self.Source.tableau
1119 # tab = tableau.make_table_from_classe(self.cl, self.la)
1120 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1121 # self.filename = os.path.join(pathout,'mat01.csv')
1122 # tableau.printtable(self.filename, tab)
1124 # paramsimi = {'coeff' : 0,
1129 # 'coeff_tv_nb' : 0,
1134 # 'coeff_temin' : 1,
1135 # 'coeff_temax' : 10,
1142 # 'cexfromchi' : True,
1143 # 'sfromchi': False,
1146 # 'cols' : (255,0,0),
1147 # 'cola' : (200,200,200),
1151 # 'keep_coord' : True,
1155 ## self.tableau.actives = {}
1156 ## self.tableau.lchi = self.lchi
1157 ## self.tableau.chi = {}
1158 ## for i, val in enumerate(self.la) :
1159 ## self.tableau.actives[val] = [self.lfreq[i]]
1160 ## self.tableau.chi[val] = [self.lchi[i]]
1163 # self.tableau.chi = {}
1164 # self.tableau.lchi = self.lchi
1165 # self.tableau.parametre['fromprof'] = True
1166 # for i, val in enumerate(self.la) :
1167 # act[val] = [self.lfreq[i]]
1168 # self.tableau.chi[val] = [self.lchi[i]]
1169 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1171 # def onwordgraph(self, evt):
1172 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1173 # dlg = progressbar(self, 2)
1174 # corpus = self.Source.corpus
1175 # uces = corpus.lc[self.cl-1]
1176 # dlg.Update(1, u'Tableau...')
1177 # #tab = corpus.make_table_with_classe(uces, self.la)
1178 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1179 # self.filename = os.path.join(pathout,'mat01.csv')
1180 # dlg.Update(2, u'Ecriture...')
1181 # #corpus.write_tab(tab, self.filename)
1183 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1185 # paramsimi = {'coeff' : 0,
1190 # 'coeff_tv_nb' : 0,
1195 # 'coeff_temin' : 1,
1196 # 'coeff_temax' : 10,
1205 # 'cols' : (255,0,0),
1206 # 'cola' : (200,200,200),
1210 # 'keep_coord' : True,
1214 # self.tableau = Tableau(self.parent, '')
1215 # self.tableau.listactives = self.la
1216 # self.tableau.actives = {}
1217 # for i, val in enumerate(self.la) :
1218 # self.tableau.actives[val] = [self.lfreq[i]]
1219 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1222 def OnPopupOne(self, event):
1223 corpus = self.Source.corpus
1224 #print 'ATTENTION PRINT ET TABLE'
1225 #corpus.make_et_table()
1226 word = self.getColumnText(self.GetFirstSelected(), 6)
1227 lems = corpus.getlems()
1228 uces = corpus.lc[self.cl-1]
1230 #FIXME : donner aussi eff reel a la place de nb uce
1231 for forme in lems[word].formes :
1232 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1233 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1236 rep.append([corpus.getforme(forme).forme, nb])
1237 win = message(self, u"Formes associées", wx.Size(300, 200))
1238 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1239 win.HtmlPage.SetPage(win.html)
1242 # def on_graph(self, evt):
1243 # dlg = progressbar(self, 2)
1244 # corpus = self.Source.corpus
1245 # uces = corpus.lc[self.cl-1]
1246 # dlg.Update(1, u'Tableau...')
1247 # #tab = corpus.make_table_with_classe(uces, self.la)
1248 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1249 # self.filename = os.path.join(pathout,'mat01.csv')
1250 # dlg.Update(2, u'Ecriture...')
1251 # #corpus.write_tab(tab, self.filename)
1253 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1255 # paramsimi = {'coeff' : 0,
1260 # 'coeff_tv_nb' : 0,
1265 # 'coeff_temin' : 1,
1266 # 'coeff_temax' : 10,
1273 # 'cexfromchi' : True,
1274 # 'sfromchi': False,
1277 # 'cols' : (255,0,0),
1278 # 'cola' : (200,200,200),
1282 # 'keep_coord' : True,
1286 # self.tableau = Tableau(self.parent, '')
1287 # self.tableau.listactives = self.la
1288 # self.tableau.actives = {}
1289 # self.tableau.lchi = self.lchi
1290 # self.tableau.chi = {}
1291 # self.tableau.parametre['fromprof'] = True
1292 # for i, val in enumerate(self.la) :
1293 # self.tableau.actives[val] = [self.lfreq[i]]
1294 # self.tableau.chi[val] = [self.lchi[i]]
1295 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1297 # def on_segments(self,evt) :
1298 # dlg = progressbar(self, 2)
1299 # corpus = self.Source.corpus
1300 # uces = corpus.lc[self.cl-1]
1302 # dlg.Update(1, u'Segments...')
1303 # for i in range(2,10) :
1304 # li = corpus.find_segments_in_classe(uces, i, 1000)
1309 # l.sort(reverse = True)
1311 # dlg.Update(2, 'Tri...')
1312 # for i, line in enumerate(l) :
1313 # d[i] = [line[1],line[0], line[2]]
1314 # first = ['','','']
1315 # para={'dico': d,'fline':first}
1317 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1320 # def on_uce_carac(self,evt) :
1321 # dial = PrefUCECarac(self, self.parent)
1322 # dial.CenterOnParent()
1323 # if dial.ShowModal() == wx.ID_OK :
1324 # limite = dial.spin_eff.GetValue()
1325 # atype = dial.radio_type.GetSelection()
1326 # dlg = progressbar(self,maxi = 4)
1327 # corpus = self.Source.corpus
1328 # uces = corpus.lc[self.cl-1]
1329 # tab = corpus.make_table_with_classe(uces, self.la)
1331 # dlg.Update(2, u'score...')
1333 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1335 # 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]
1336 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1338 # ntab2.sort(reverse = True)
1339 # ntab2 = ntab2[:limite]
1340 # nuces = [val[1] for val in ntab2]
1341 # dlg.Update(3, u'concordancier...')
1342 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1343 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1346 # for uce in ucestxt1 :
1347 # ucetxt = ' '+uce[1]+' '
1348 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1349 # for lem in self.la :
1350 # listmot = corpus.getlems()[lem].formes
1351 # for id in listmot :
1352 # forme = corpus.getforme(id).forme
1353 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1354 # ucestxt.append(ucetxt)
1355 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1356 # dlg.Update(4, u'texte...')
1357 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1358 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1359 # 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>'
1360 # win.HtmlPage.SetPage(win.html)
1364 # def on_tablex(self, evt):
1365 # if 'corpus' in dir(self.Source):
1366 # corpus = self.Source.corpus
1368 # corpus = self.Source.tableau
1369 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1370 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1371 # title = chistable[0]
1374 # vchistable = [line[1:] for line in chistable]
1375 # fchistable = [line[0] for line in chistable]
1376 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1377 # tableout = [vchistable[fchistable.index(words[0])]]
1378 # last = self.list.GetFirstSelected()
1379 # while self.list.GetNextSelected(last) != -1:
1380 # last = self.list.GetNextSelected(last)
1381 # word = self.getColumnText(last, 6)
1382 # words.append(word)
1383 # tableout.append(vchistable[fchistable.index(word)])
1384 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1386 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1387 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1388 # file = open(tmpscript,'w')
1392 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1393 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1394 # win.addsaveimage(tmpgraph)
1395 # txt = "<img src='%s'>" % tmpgraph
1396 # win.HtmlPage.SetPage(txt)
1399 # def onlexdendro(self, evt):
1400 # if 'corpus' in dir(self.Source):
1401 # corpus = self.Source.corpus
1403 # corpus = self.Source.tableau
1404 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1405 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1406 # title = chistable[0]
1409 # vchistable = [line[1:] for line in chistable]
1410 # fchistable = [line[0] for line in chistable]
1411 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1412 # tableout = [vchistable[fchistable.index(words[0])]]
1413 # last = self.list.GetFirstSelected()
1414 # while self.list.GetNextSelected(last) != -1:
1415 # last = self.list.GetNextSelected(last)
1416 # word = self.getColumnText(last, 6)
1417 # words.append(word)
1418 # tableout.append(vchistable[fchistable.index(word)])
1419 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1420 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1421 # rownames = 'c("' + '","'.join(words) + '")'
1422 # colnames = 'c("' + '","'.join(title) + '")'
1424 # rownb = len(words)
1427 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1429 # colnames(di) <- %s
1432 # height <- (30*ncol(di)) + (15*nrow(di))
1433 # height <- ifelse(height <= 400, 400, height)
1435 # open_file_graph("%s", width=width, height=height)
1436 # plot.dendro.lex(tree.cut1$tree.cl, di)
1437 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1438 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1439 # file = open(tmpscript,'w')
1442 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1443 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1444 # win.addsaveimage(tmpgraph)
1445 # txt = "<img src='%s'>" % tmpgraph
1446 # win.HtmlPage.SetPage(txt)
1450 # def make_concord(self, uces, title, color = 'red') :
1451 # corpus = self.Source.corpus
1452 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1453 # last = self.list.GetFirstSelected()
1454 # while self.list.GetNextSelected(last) != -1:
1455 # last = self.list.GetNextSelected(last)
1456 # ListWord.append(self.getColumnText(last, 6))
1457 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1458 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1459 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1460 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1463 # for word in ListWord :
1464 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1465 # ucef = list(set(ucef))
1467 # res = corpus.getconcorde(ucef)
1468 # txt = '<br>'.join(toshow) +'<br><br>'
1470 # ucetxt = ' '+uce[1]+' '
1471 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1472 # for forme in listmot:
1473 # forme = corpus.getforme(forme).forme
1474 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1475 # txt += ucetxt + '<br><br>'
1476 # win.HtmlPage.SetPage(txt)
1479 # def OnPopupTwo(self, event):
1480 # corpus = self.Source.corpus
1481 # uces = corpus.lc[self.cl-1]
1482 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1485 # def OnPopupThree(self, event):
1486 # corpus = self.Source.corpus
1487 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1488 # win = self.make_concord(uces, "Concordancier - UCE classées")
1491 # def OnPopupFour(self, event):
1492 # corpus = self.Source.corpus
1493 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1494 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1497 # def OnPopupFive(self, event):
1498 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1499 # lk = "http://www.cnrtl.fr/definition/" + word
1500 # webbrowser.open(lk)
1502 # def OnPopupSix(self, event):
1503 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1504 # lk = "http://www.cnrtl.fr/etymologie/" + word
1505 # webbrowser.open(lk)
1507 # def OnPopupSeven(self, event):
1508 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1509 # lk = "http://www.cnrtl.fr/synonymie/" + word
1510 # webbrowser.open(lk)
1512 # def OnPopupHeight(self, event):
1513 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1514 # lk = "http://www.cnrtl.fr/antonymie/" + word
1515 # webbrowser.open(lk)
1517 # def OnPopupNine(self, event):
1518 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1519 # lk = "http://www.cnrtl.fr/morphologie/" + word
1520 # webbrowser.open(lk)
1522 # def onproxe(self, evt) :
1523 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1524 # lk = "http://www.cnrtl.fr/proxemie/" + word
1525 # webbrowser.open(lk)
1527 # def OnSize(self, event):
1528 # w, h = self.GetClientSizeTuple()
1529 # self.list.SetDimensions(0, 0, w, h)
1531 # def OnColClick(self, event):
1532 # self.do_greyline()
1535 #class wliste(wx.Frame):
1536 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1537 # wx.Frame.__init__(self, parent, id)
1538 # self.liste = ListForSpec(self, parent, d, fline)
1539 # self.button_1 = wx.Button(self, -1, "Fermer")
1540 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1541 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1542 # self.__do_layout()
1544 # def __do_layout(self):
1545 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1546 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1547 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1548 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1549 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1550 # self.SetAutoLayout(True)
1551 # self.SetSizer(sizer_1)
1554 # def OnCloseMe(self, event):
1557 # def OnCloseWindow(self, event):
1560 #class message(wx.Dialog):
1561 # def __init__(self, parent, title, size, save = True):
1562 # wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1564 # self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1567 # self.HtmlPage=wx.html.HtmlWindow(self, -1)
1568 # self.HtmlPage.SetMinSize( size )
1569 # if "gtk2" in wx.PlatformInfo:
1570 # self.HtmlPage.SetStandardFonts()
1571 # self.HtmlPage.SetFonts('Courier','Courier')
1573 # self.button_1 = wx.Button(self, wx.ID_CANCEL)
1575 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1577 # self.button_2 = wx.Button(self, wx.ID_SAVE)
1578 # self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1579 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1580 # self.__do_layout()
1582 # def __do_layout(self):
1583 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1584 # sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1585 # m_sdbSizer1 = wx.StdDialogButtonSizer()
1586 # m_sdbSizer1.AddButton( self.button_1 )
1588 # m_sdbSizer1.AddButton( self.button_2 )
1589 # m_sdbSizer1.Realize()
1590 # sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1591 # self.SetSizer(sizer_2)
1593 # sizer_2.Fit( self )
1595 # def OnSavePage(self, evt) :
1596 # dlg = wx.FileDialog(
1597 # self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1598 # defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1600 # dlg.SetFilterIndex(2)
1601 # dlg.CenterOnParent()
1602 # if dlg.ShowModal() == wx.ID_OK:
1603 # path = dlg.GetPath()
1604 # with open(path, 'w') as f :
1605 # f.write(self.html)
1607 # def OnCloseMe(self, event):
1610 # def OnCloseWindow(self, event):