1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
19 import wx.lib.mixins.listctrl as listmix
20 from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial
24 from tableau import Tableau
25 from search_tools import SearchFrame
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
41 self.Alceste = Alceste
45 line1 = profclasse.pop(0)
46 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
48 self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
49 profclasse.pop(self.lenact)
51 self.lenact = len(profclasse)
53 self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
54 self.lensup = self.lensup - self.lenact
55 profclasse.pop(self.lensup)
58 self.lenet = len(profclasse) - (self.lenact + self.lensup)
59 print self.lenact, self.lensup, self.lenet
60 for i, line in enumerate(classen) :
62 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
65 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
66 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
67 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
74 self.il = wx.ImageList(16, 16)
75 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
77 s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
79 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
81 #adding some attributes (colourful background for each item rows)
82 self.attr1 = wx.ListItemAttr()
83 self.attr1.SetBackgroundColour((220, 220, 220))
84 self.attrsg = wx.ListItemAttr()
85 self.attrsg.SetBackgroundColour((230, 230, 230))
86 self.attr2 = wx.ListItemAttr()
87 self.attr2.SetBackgroundColour((190, 249, 236))
88 self.attr2s = wx.ListItemAttr()
89 self.attr2s.SetBackgroundColour((211, 252, 244))
90 self.attr3 = wx.ListItemAttr()
91 self.attr3.SetBackgroundColour((245, 180, 180))
92 self.attr3s = wx.ListItemAttr()
93 self.attr3s.SetBackgroundColour((245, 190, 190))
96 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
97 self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
98 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
99 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
100 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
101 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
102 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
103 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
106 self.SetColumnWidth(0, 60)
107 self.SetColumnWidth(1, 70)
108 self.SetColumnWidth(2, 80)
109 self.SetColumnWidth(3, 100)
110 self.SetColumnWidth(4, 70)
111 self.SetColumnWidth(5, 60)
112 self.SetColumnWidth(6, 140)
113 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
115 #These two should probably be passed to init more cleanly
116 #setting the numbers of items = number of elements in the dictionary
117 self.itemDataMap = dictdata
118 self.itemIndexMap = dictdata.keys()
119 self.SetItemCount(len(dictdata))
122 listmix.ListCtrlAutoWidthMixin.__init__(self)
123 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
125 #sort by genre (column 2), A->Z ascending order (1)
126 self.SortListItems(0, 1)
129 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
130 #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
131 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
132 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
135 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
138 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
141 search_id = wx.NewId()
142 searchall_id = wx.NewId()
143 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
144 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
145 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
146 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
147 self.SetAcceleratorTable(self.accel_tbl)
151 def OnColClick(self,event):
154 def OnItemSelected(self, event):
155 self.currentItem = event.m_itemIndex
156 print 'OnItemSelected: "%s", "%s", "%s", "%s"\n' % (self.currentItem, self.GetItemText(self.currentItem), self.getColumnText(self.currentItem, 1), self.getColumnText(self.currentItem, 2))
157 #self.log.WriteText('OnItemSelected: "%s", "%s", "%s", "%s"\n' %
159 # self.GetItemText(self.currentItem),
160 # self.getColumnText(self.currentItem, 1),
161 # self.getColumnText(self.currentItem, 2)))
163 def OnItemActivated(self, event):
164 self.currentItem = event.m_itemIndex
165 print "OnItemActivated: %s\nTopItem: %s\n" % (self.GetItemText(self.currentItem), self.GetTopItem())
166 #self.log.WriteText("OnItemActivated: %s\nTopItem: %s\n" %
167 # (self.GetItemText(self.currentItem), self.GetTopItem()))
169 def getColumnText(self, index, col):
170 item = self.GetItem(index, col)
171 return item.GetText()
173 def OnItemDeselected(self, evt):
175 #self.log.WriteText("OnItemDeselected: %s" % evt.m_itemIndex)
178 #---------------------------------------------------
179 # These methods are callbacks for implementing the
180 # "virtualness" of the list...
182 def OnGetItemText(self, item, col):
183 index=self.itemIndexMap[item]
184 s = self.itemDataMap[index][col]
187 def OnGetItemImage(self, item):
188 index=self.itemIndexMap[item]
189 genre=self.itemDataMap[index][2]
195 elif genre=="New Age":
200 def OnGetItemAttr(self, item):
201 index=self.itemIndexMap[item]
202 #genre=self.itemDataMap[index][2]
203 if index < self.lenact :
208 elif index >= self.lenact and index < (self.lenact + self.lensup) :
213 elif index >= (self.lenact + self.lensup) :
223 # elif genre=="Jazz":
225 # elif genre=="New Age":
230 #---------------------------------------------------
232 # Here's a better SortItems() method --
233 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
234 # and it knows to sort on another column if the chosen columns have the same value.
236 def SortItems(self,sorter=cmp):
237 items = list(self.itemDataMap.keys())
239 self.itemIndexMap = items
244 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
245 def GetListCtrl(self):
248 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
249 def GetSortImages(self):
250 return (self.sm_dn, self.sm_up)
252 def onsearch(self, evt) :
253 self.dial = SearchDial(self, self, 6, True)
254 self.dial.CenterOnParent()
255 self.dial.ShowModal()
258 def onsearchall(self, evt) :
259 if 'FrameSearch' not in dir(self.Source) :
260 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
261 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
262 self.dial.CenterOnParent()
263 self.dial.ShowModal()
266 def OnRightClick(self, event):
268 # only do this part the first time so the events are only bound once
270 if not hasattr(self, "popupID1"):
271 self.popupID1 = wx.NewId()
272 self.popupID2 = wx.NewId()
273 self.popupID3 = wx.NewId()
274 self.popupID4 = wx.NewId()
275 self.popupID5 = wx.NewId()
276 self.popupID6 = wx.NewId()
277 self.popupID7 = wx.NewId()
278 self.popupID8 = wx.NewId()
279 self.popupID9 = wx.NewId()
280 #self.popupID10 = wx.NewId()
281 self.popupIDgraph = wx.NewId()
282 self.idseg = wx.NewId()
283 self.iducecarac = wx.NewId()
284 self.idtablex = wx.NewId()
285 self.idchimod = wx.NewId()
286 self.idwordgraph = wx.NewId()
287 self.popup_proxe = wx.NewId()
288 self.idlexdendro = wx.NewId()
289 self.idexport = wx.NewId()
290 # self.export_classes = wx.NewId()
292 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
293 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
294 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
295 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
296 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
297 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
298 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
299 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
300 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
301 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
302 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
303 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
304 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
305 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
306 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
307 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
308 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
309 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
310 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
311 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
312 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
316 menu.Append(self.popupID1, u"Formes associées")
317 menu.Append(self.idtablex, u"Chi2 par classe")
318 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
319 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
320 menu.Append(self.idwordgraph, u"Graphe du mot")
321 #menu.Append(self.export_classes, u"Exporter le corpus...")
323 #menu.Append(self.popupID10, u"Spécificités")
325 menu_conc = wx.Menu()
326 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
327 menu_conc.Append(self.popupID3, u"dans les uce classées")
328 menu_conc.Append(self.popupID4, u"dans toutes les uce")
329 menu.AppendMenu(-1, u"Concordancier", menu_conc)
330 menu_cnrtl = wx.Menu()
331 menu_cnrtl.Append(self.popupID5, u"Définition")
332 menu_cnrtl.Append(self.popupID6, u"Etymologie")
333 menu_cnrtl.Append(self.popupID7, u"Synonymie")
334 menu_cnrtl.Append(self.popupID8, u"Antonymie")
335 menu_cnrtl.Append(self.popupID9, u"Morphologie")
336 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
337 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
338 menu.AppendSeparator()
339 menu.Append(self.popupIDgraph, u"Graphe de la classe")
340 menu.Append(self.idseg, u"Segments répétés")
341 menu.Append(self.iducecarac, u"UCE caractéristiques")
342 menu.Append(self.idexport, 'Partitionner...')
343 #menu.Append(self.popupID2, u"Concordancier")
344 # menu.Append(self.popupID3, "recharger")
348 elif 'tableau' in dir(self.Source) :
349 if not hasattr(self, "pop1"):
350 self.pop1 = wx.NewId()
351 self.pop2 = wx.NewId()
352 self.pop3 = wx.NewId()
353 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
354 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
355 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
358 menu.Append(self.pop2, u"Chi2 par classe")
359 menu.Append(self.pop3, u"Chi2 modalités de la variable")
360 menu.AppendSeparator()
361 menu.Append(self.pop1, u"Graph de la classe")
365 def onexport(self, evt) :
366 if 'corpus' in dir(self.Source):
367 corpus = self.Source.corpus
368 ClasseCHD(self.parent, corpus, self.cl)
370 def quest_var_mod(self, evt) :
371 if 'corpus' in dir(self.Source):
372 corpus = self.Source.corpus
373 if self.var_mod == {} :
374 self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
376 corpus = self.Source.tableau
377 if self.var_mod == {} :
378 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
379 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
380 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
384 vchistable = [line[1:] for line in chistable]
385 fchistable = [line[0] for line in chistable]
386 word = self.getColumnText(self.GetFirstSelected(), 6)
387 if len(word.split('_')) > 1 :
388 var = word.split('_')[0]
389 words = [word for word in self.var_mod[var]]
394 if word in fchistable :
395 tableout.append(vchistable[fchistable.index(word)])
397 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
398 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
399 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
400 file = open(tmpscript,'w')
403 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
404 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
405 win.addsaveimage(tmpgraph)
406 txt = "<img src='%s'>" % tmpgraph
407 win.HtmlPage.SetPage(txt)
410 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
411 dial.CenterOnParent()
415 def quest_simi(self, evt) :
416 tableau = self.Source.tableau
417 tab = tableau.make_table_from_classe(self.cl, self.la)
418 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
419 self.filename = os.path.join(pathout,'mat01.csv')
420 tableau.printtable(self.filename, tab)
422 paramsimi = {'coeff' : 0,
445 'cola' : (200,200,200),
453 # self.tableau.actives = {}
454 # self.tableau.lchi = self.lchi
455 # self.tableau.chi = {}
456 # for i, val in enumerate(self.la) :
457 # self.tableau.actives[val] = [self.lfreq[i]]
458 # self.tableau.chi[val] = [self.lchi[i]]
461 self.tableau.chi = {}
462 self.tableau.lchi = self.lchi
463 self.tableau.parametre['fromprof'] = True
464 for i, val in enumerate(self.la) :
465 act[val] = [self.lfreq[i]]
466 self.tableau.chi[val] = [self.lchi[i]]
467 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
469 def onwordgraph(self, evt):
470 word = self.getColumnText(self.GetFirstSelected(), 6)
471 dlg = progressbar(self, 2)
472 corpus = self.Source.corpus
473 uces = corpus.lc[self.cl-1]
474 dlg.Update(1, u'Tableau...')
475 #tab = corpus.make_table_with_classe(uces, self.la)
476 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
477 self.filename = os.path.join(pathout,'mat01.csv')
478 dlg.Update(2, u'Ecriture...')
479 #corpus.write_tab(tab, self.filename)
481 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
483 paramsimi = {'coeff' : 0,
504 'cola' : (200,200,200),
512 self.tableau = Tableau(self.parent, '')
513 self.tableau.listactives = self.la
514 self.tableau.actives = {}
515 for i, val in enumerate(self.la) :
516 self.tableau.actives[val] = [self.lfreq[i]]
517 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
519 def on_graph(self, evt):
520 dlg = progressbar(self, 2)
521 corpus = self.Source.corpus
522 uces = corpus.lc[self.cl-1]
523 dlg.Update(1, u'Tableau...')
524 #tab = corpus.make_table_with_classe(uces, self.la)
525 pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
526 self.filename = os.path.join(pathout,'mat01.csv')
527 dlg.Update(2, u'Ecriture...')
528 #corpus.write_tab(tab, self.filename)
530 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
532 paramsimi = {'coeff' : 0,
555 'cola' : (200,200,200),
563 self.tableau = Tableau(self.parent, '')
564 self.tableau.listactives = self.la
565 self.tableau.actives = {}
566 self.tableau.lchi = self.lchi
567 self.tableau.chi = {}
568 self.tableau.parametre['fromprof'] = True
569 for i, val in enumerate(self.la) :
570 self.tableau.actives[val] = [self.lfreq[i]]
571 self.tableau.chi[val] = [self.lchi[i]]
572 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
574 def on_segments(self,evt) :
575 dlg = progressbar(self, 2)
576 corpus = self.Source.corpus
577 uces = corpus.lc[self.cl-1]
579 dlg.Update(1, u'Segments...')
580 for i in range(2,10) :
581 li = corpus.find_segments_in_classe(uces, i, 1000)
586 l.sort(reverse = True)
588 dlg.Update(2, 'Tri...')
589 for i, line in enumerate(l) :
590 d[i] = [line[1],line[0], line[2]]
592 para={'dico': d,'fline':first}
594 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
597 def on_uce_carac(self,evt) :
598 dial = PrefUCECarac(self, self.parent)
599 dial.CenterOnParent()
600 if dial.ShowModal() == wx.ID_OK :
601 limite = dial.spin_eff.GetValue()
602 atype = dial.radio_type.GetSelection()
603 dlg = progressbar(self,maxi = 4)
604 corpus = self.Source.corpus
605 uces = corpus.lc[self.cl-1]
606 tab = corpus.make_table_with_classe(uces, self.la)
608 dlg.Update(2, u'score...')
610 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
612 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]
613 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
615 ntab2.sort(reverse = True)
616 ntab2 = ntab2[:limite]
617 nuces = [val[1] for val in ntab2]
618 dlg.Update(3, u'concordancier...')
619 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
620 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
623 for uce in ucestxt1 :
624 ucetxt = ' '+uce[1]+' '
625 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
627 listmot = corpus.getlems()[lem].formes
629 forme = corpus.getforme(id).forme
630 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
631 ucestxt.append(ucetxt)
632 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
633 dlg.Update(4, u'texte...')
634 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
635 win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
636 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>'
637 win.HtmlPage.SetPage(win.html)
641 def on_tablex(self, evt):
642 if 'corpus' in dir(self.Source):
643 corpus = self.Source.corpus
645 corpus = self.Source.tableau
646 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
647 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
651 vchistable = [line[1:] for line in chistable]
652 fchistable = [line[0] for line in chistable]
653 words = [self.getColumnText(self.GetFirstSelected(), 6)]
654 tableout = [vchistable[fchistable.index(words[0])]]
655 last = self.GetFirstSelected()
656 while self.GetNextSelected(last) != -1:
657 last = self.GetNextSelected(last)
658 word = self.getColumnText(last, 6)
660 tableout.append(vchistable[fchistable.index(word)])
661 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
663 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
664 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
665 file = open(tmpscript,'w')
669 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
670 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
671 win.addsaveimage(tmpgraph)
672 txt = "<img src='%s'>" % tmpgraph
673 win.HtmlPage.SetPage(txt)
676 def onlexdendro(self, evt):
677 if 'corpus' in dir(self.Source):
678 corpus = self.Source.corpus
680 corpus = self.Source.tableau
681 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
682 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
686 vchistable = [line[1:] for line in chistable]
687 fchistable = [line[0] for line in chistable]
688 words = [self.getColumnText(self.GetFirstSelected(), 6)]
689 tableout = [vchistable[fchistable.index(words[0])]]
690 last = self.GetFirstSelected()
691 while self.GetNextSelected(last) != -1:
692 last = self.GetNextSelected(last)
693 word = self.getColumnText(last, 6)
695 tableout.append(vchistable[fchistable.index(word)])
696 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
697 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
698 rownames = 'c("' + '","'.join(words) + '")'
699 colnames = 'c("' + '","'.join(title) + '")'
704 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
709 height <- (30*ncol(di)) + (15*nrow(di))
710 height <- ifelse(height <= 400, 400, height)
712 open_file_graph("%s", width=width, height=height)
713 plot.dendro.lex(tree.cut1$tree.cl, di)
714 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
715 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
716 file = open(tmpscript,'w')
719 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
720 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
721 win.addsaveimage(tmpgraph)
722 txt = "<img src='%s'>" % tmpgraph
723 win.HtmlPage.SetPage(txt)
727 def make_concord(self, uces, title, color = 'red') :
728 corpus = self.Source.corpus
729 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
730 last = self.GetFirstSelected()
731 while self.GetNextSelected(last) != -1:
732 last = self.GetNextSelected(last)
733 ListWord.append(self.getColumnText(last, 6))
734 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
735 win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
736 toshow = ['<html>\n<H1>Concordancier</H1>\n']
737 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
740 for word in ListWord :
741 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
742 ucef = list(set(ucef))
744 res = corpus.getconcorde(ucef)
745 txt = '<br>'.join(toshow) +'<br><br>'
747 ucetxt = ' '+uce[1]+' '
748 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
749 for forme in listmot:
750 forme = corpus.getforme(forme).forme
751 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
752 txt += ucetxt + '<br><br>'
753 win.HtmlPage.SetPage(txt)
756 def OnPopupTwo(self, event):
757 corpus = self.Source.corpus
758 uces = corpus.lc[self.cl-1]
759 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
762 def OnPopupThree(self, event):
763 corpus = self.Source.corpus
764 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
765 win = self.make_concord(uces, "Concordancier - UCE classées")
768 def OnPopupFour(self, event):
769 corpus = self.Source.corpus
770 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
771 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
774 def OnPopupFive(self, event):
775 word = self.getColumnText(self.GetFirstSelected(), 6)
776 lk = "http://www.cnrtl.fr/definition/" + word
779 def OnPopupSix(self, event):
780 word = self.getColumnText(self.GetFirstSelected(), 6)
781 lk = "http://www.cnrtl.fr/etymologie/" + word
784 def OnPopupSeven(self, event):
785 word = self.getColumnText(self.GetFirstSelected(), 6)
786 lk = "http://www.cnrtl.fr/synonymie/" + word
789 def OnPopupHeight(self, event):
790 word = self.getColumnText(self.GetFirstSelected(), 6)
791 lk = "http://www.cnrtl.fr/antonymie/" + word
794 def OnPopupNine(self, event):
795 word = self.getColumnText(self.GetFirstSelected(), 6)
796 lk = "http://www.cnrtl.fr/morphologie/" + word
799 def onproxe(self, evt) :
800 word = self.getColumnText(self.GetFirstSelected(), 6)
801 lk = "http://www.cnrtl.fr/proxemie/" + word
805 #---------------------------------------------------------------------------
806 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
807 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
808 # size=wx.DefaultSize, style=0):
809 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
810 # listmix.ListCtrlAutoWidthMixin.__init__(self)
813 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
814 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
815 # self.parent = parent
816 # classe = ProfClasse
818 # self.Source = gparent
819 # if 'tableau' in dir(self.Source):
820 # self.tableau = self.Source.tableau
821 # self.Alceste = Alceste
825 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
827 # search_id = wx.NewId()
828 # searchall_id = wx.NewId()
829 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
830 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
831 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
832 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
833 # self.SetAcceleratorTable(self.accel_tbl)
835 # self.il = wx.ImageList(16, 16)
836 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
837 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
838 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
841 # self.list = ProfListctrl(self, tID,
844 # | wx.LC_EDIT_LABELS
845 # | wx.LC_SORT_ASCENDING
847 # line1 = classe.pop(0)
852 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
853 # if len(classen) == 0 :
858 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
861 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
863 # lenact = len(classen)
867 # lenet = len(classen)
870 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
872 # lensup = lensup[0] - lenact
873 # lenet = len(classen) - lensup
876 # lenet = len(classen)
879 # self.lenact = lenact
881 # debet = lenact + lensup
882 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
883 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
885 # self.PopulateList(dictdata, debet, debsup, Alceste)
887 # self.Bind(wx.EVT_SIZE, self.OnSize)
888 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
889 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
892 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
895 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
896 # self.itemDataMap = dictdata
897 # listmix.ColumnSorterMixin.__init__(self, 8)
899 ##-----------------------------------------------------------------------------------------
901 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
904 # # for normal, simple columns, you can add them like this:
905 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
906 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
907 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
908 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
909 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
910 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
911 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
912 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
914 # for key in dictdata : #.iteritems():
915 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
917 # for val in dictdata[key][1:]:
918 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
920 # self.list.SetItemData(index, key)
922 # self.list.SetColumnWidth(0, 60)
923 # self.list.SetColumnWidth(1, 70)
924 # self.list.SetColumnWidth(2, 80)
925 # self.list.SetColumnWidth(3, 100)
926 # self.list.SetColumnWidth(4, 70)
927 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
928 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
929 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
931 # # show how to change the colour of a couple items
932 # for i in range(limitsup, limit):
933 # item = self.list.GetItem(i)
934 # item.SetTextColour(wx.RED)
935 # self.list.SetItem(item)
937 # for i in range(limit, len(dictdata)):
938 # item = self.list.GetItem(i)
939 # item.SetTextColour(wx.BLUE)
940 # self.list.SetItem(item)
942 # if self.lenact != 0 :
943 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
944 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
945 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
951 # def do_greyline(self):
952 # for row in xrange(self.list.GetItemCount()):
954 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
956 # self.list.SetItemBackgroundColour(row, wx.WHITE)
959 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
960 # def GetListCtrl(self):
963 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
964 # def GetSortImages(self):
965 # return (self.sm_dn, self.sm_up)
968 # def OnRightDown(self, event):
971 # item, flags = self.list.HitTest((x, y))
973 # if flags & wx.LIST_HITTEST_ONITEM:
974 # self.list.Select(item)
979 # def getColumnText(self, index, col):
980 # item = self.list.GetItem(index, col)
981 # return item.GetText()
984 # def OnItemSelected(self, event):
985 # self.currentItem = event.m_itemIndex
988 # def onsearch(self, evt) :
989 # self.dial = SearchDial(self, self, 6, True)
990 # self.dial.CenterOnParent()
991 # self.dial.ShowModal()
992 # self.dial.Destroy()
994 # def onsearchall(self, evt) :
995 # if 'FrameSearch' not in dir(self.Source) :
996 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
997 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
998 # self.dial.CenterOnParent()
999 # self.dial.ShowModal()
1000 # self.dial.Destroy()
1002 # def OnRightClick(self, event):
1004 # # only do this part the first time so the events are only bound once
1006 # if not hasattr(self, "popupID1"):
1007 # self.popupID1 = wx.NewId()
1008 # self.popupID2 = wx.NewId()
1009 # self.popupID3 = wx.NewId()
1010 # self.popupID4 = wx.NewId()
1011 # self.popupID5 = wx.NewId()
1012 # self.popupID6 = wx.NewId()
1013 # self.popupID7 = wx.NewId()
1014 # self.popupID8 = wx.NewId()
1015 # self.popupID9 = wx.NewId()
1016 # #self.popupID10 = wx.NewId()
1017 # self.popupIDgraph = wx.NewId()
1018 # self.idseg = wx.NewId()
1019 # self.iducecarac = wx.NewId()
1020 # self.idtablex = wx.NewId()
1021 # self.idchimod = wx.NewId()
1022 # self.idwordgraph = wx.NewId()
1023 # self.popup_proxe = wx.NewId()
1024 # self.idlexdendro = wx.NewId()
1025 # self.idexport = wx.NewId()
1026 # # self.export_classes = wx.NewId()
1028 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1029 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1030 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1031 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1032 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1033 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1034 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1035 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1036 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1037 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1038 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1039 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1040 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1041 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1042 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1043 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1044 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1045 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1046 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1047 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1048 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1052 # menu.Append(self.popupID1, u"Formes associées")
1053 # menu.Append(self.idtablex, u"Chi2 par classe")
1054 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1055 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1056 # menu.Append(self.idwordgraph, u"Graphe du mot")
1057 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1059 # #menu.Append(self.popupID10, u"Spécificités")
1061 # menu_conc = wx.Menu()
1062 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1063 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1064 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1065 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1066 # menu_cnrtl = wx.Menu()
1067 # menu_cnrtl.Append(self.popupID5, u"Définition")
1068 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1069 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1070 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1071 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1072 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1073 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1074 # menu.AppendSeparator()
1075 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1076 # menu.Append(self.idseg, u"Segments répétés")
1077 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1078 # menu.Append(self.idexport, 'Partitionner...')
1079 # #menu.Append(self.popupID2, u"Concordancier")
1080 # # menu.Append(self.popupID3, "recharger")
1082 # self.PopupMenu(menu)
1084 # elif 'tableau' in dir(self.Source) :
1085 # if not hasattr(self, "pop1"):
1086 # self.pop1 = wx.NewId()
1087 # self.pop2 = wx.NewId()
1088 # self.pop3 = wx.NewId()
1089 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1090 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1091 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1094 # menu.Append(self.pop2, u"Chi2 par classe")
1095 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1096 # menu.AppendSeparator()
1097 # menu.Append(self.pop1, u"Graph de la classe")
1098 # self.PopupMenu(menu)
1101 # def onexport(self, evt) :
1102 # if 'corpus' in dir(self.Source):
1103 # corpus = self.Source.corpus
1104 # ClasseCHD(self.parent, corpus, self.cl)
1106 # def quest_var_mod(self, evt) :
1107 # if 'corpus' in dir(self.Source):
1108 # corpus = self.Source.corpus
1109 # if self.var_mod == {} :
1110 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1112 # corpus = self.Source.tableau
1113 # if self.var_mod == {} :
1114 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1115 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1116 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1117 # title = chistable[0]
1120 # vchistable = [line[1:] for line in chistable]
1121 # fchistable = [line[0] for line in chistable]
1122 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1123 # if len(word.split('_')) > 1 :
1124 # var = word.split('_')[0]
1125 # words = [word for word in self.var_mod[var]]
1129 # for word in words :
1130 # if word in fchistable :
1131 # tableout.append(vchistable[fchistable.index(word)])
1132 # kwords.append(word)
1133 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1134 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1135 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1136 # file = open(tmpscript,'w')
1139 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1140 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1141 # win.addsaveimage(tmpgraph)
1142 # txt = "<img src='%s'>" % tmpgraph
1143 # win.HtmlPage.SetPage(txt)
1146 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1147 # dial.CenterOnParent()
1151 # def quest_simi(self, evt) :
1152 # tableau = self.Source.tableau
1153 # tab = tableau.make_table_from_classe(self.cl, self.la)
1154 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1155 # self.filename = os.path.join(pathout,'mat01.csv')
1156 # tableau.printtable(self.filename, tab)
1158 # paramsimi = {'coeff' : 0,
1163 # 'coeff_tv_nb' : 0,
1168 # 'coeff_temin' : 1,
1169 # 'coeff_temax' : 10,
1176 # 'cexfromchi' : True,
1177 # 'sfromchi': False,
1180 # 'cols' : (255,0,0),
1181 # 'cola' : (200,200,200),
1185 # 'keep_coord' : True,
1189 ## self.tableau.actives = {}
1190 ## self.tableau.lchi = self.lchi
1191 ## self.tableau.chi = {}
1192 ## for i, val in enumerate(self.la) :
1193 ## self.tableau.actives[val] = [self.lfreq[i]]
1194 ## self.tableau.chi[val] = [self.lchi[i]]
1197 # self.tableau.chi = {}
1198 # self.tableau.lchi = self.lchi
1199 # self.tableau.parametre['fromprof'] = True
1200 # for i, val in enumerate(self.la) :
1201 # act[val] = [self.lfreq[i]]
1202 # self.tableau.chi[val] = [self.lchi[i]]
1203 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1205 # def onwordgraph(self, evt):
1206 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1207 # dlg = progressbar(self, 2)
1208 # corpus = self.Source.corpus
1209 # uces = corpus.lc[self.cl-1]
1210 # dlg.Update(1, u'Tableau...')
1211 # #tab = corpus.make_table_with_classe(uces, self.la)
1212 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1213 # self.filename = os.path.join(pathout,'mat01.csv')
1214 # dlg.Update(2, u'Ecriture...')
1215 # #corpus.write_tab(tab, self.filename)
1217 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1219 # paramsimi = {'coeff' : 0,
1224 # 'coeff_tv_nb' : 0,
1229 # 'coeff_temin' : 1,
1230 # 'coeff_temax' : 10,
1239 # 'cols' : (255,0,0),
1240 # 'cola' : (200,200,200),
1244 # 'keep_coord' : True,
1248 # self.tableau = Tableau(self.parent, '')
1249 # self.tableau.listactives = self.la
1250 # self.tableau.actives = {}
1251 # for i, val in enumerate(self.la) :
1252 # self.tableau.actives[val] = [self.lfreq[i]]
1253 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1256 def OnPopupOne(self, event):
1257 corpus = self.Source.corpus
1258 #print 'ATTENTION PRINT ET TABLE'
1259 #corpus.make_et_table()
1260 word = self.getColumnText(self.GetFirstSelected(), 6)
1261 lems = corpus.getlems()
1262 uces = corpus.lc[self.cl-1]
1264 #FIXME : donner aussi eff reel a la place de nb uce
1265 for forme in lems[word].formes :
1266 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1267 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1270 rep.append([corpus.getforme(forme).forme, nb])
1271 win = message(self, -1, u"Formes associées", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
1272 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1273 win.HtmlPage.SetPage(win.html)
1276 # def on_graph(self, evt):
1277 # dlg = progressbar(self, 2)
1278 # corpus = self.Source.corpus
1279 # uces = corpus.lc[self.cl-1]
1280 # dlg.Update(1, u'Tableau...')
1281 # #tab = corpus.make_table_with_classe(uces, self.la)
1282 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1283 # self.filename = os.path.join(pathout,'mat01.csv')
1284 # dlg.Update(2, u'Ecriture...')
1285 # #corpus.write_tab(tab, self.filename)
1287 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1289 # paramsimi = {'coeff' : 0,
1294 # 'coeff_tv_nb' : 0,
1299 # 'coeff_temin' : 1,
1300 # 'coeff_temax' : 10,
1307 # 'cexfromchi' : True,
1308 # 'sfromchi': False,
1311 # 'cols' : (255,0,0),
1312 # 'cola' : (200,200,200),
1316 # 'keep_coord' : True,
1320 # self.tableau = Tableau(self.parent, '')
1321 # self.tableau.listactives = self.la
1322 # self.tableau.actives = {}
1323 # self.tableau.lchi = self.lchi
1324 # self.tableau.chi = {}
1325 # self.tableau.parametre['fromprof'] = True
1326 # for i, val in enumerate(self.la) :
1327 # self.tableau.actives[val] = [self.lfreq[i]]
1328 # self.tableau.chi[val] = [self.lchi[i]]
1329 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1331 # def on_segments(self,evt) :
1332 # dlg = progressbar(self, 2)
1333 # corpus = self.Source.corpus
1334 # uces = corpus.lc[self.cl-1]
1336 # dlg.Update(1, u'Segments...')
1337 # for i in range(2,10) :
1338 # li = corpus.find_segments_in_classe(uces, i, 1000)
1343 # l.sort(reverse = True)
1345 # dlg.Update(2, 'Tri...')
1346 # for i, line in enumerate(l) :
1347 # d[i] = [line[1],line[0], line[2]]
1348 # first = ['','','']
1349 # para={'dico': d,'fline':first}
1351 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1354 # def on_uce_carac(self,evt) :
1355 # dial = PrefUCECarac(self, self.parent)
1356 # dial.CenterOnParent()
1357 # if dial.ShowModal() == wx.ID_OK :
1358 # limite = dial.spin_eff.GetValue()
1359 # atype = dial.radio_type.GetSelection()
1360 # dlg = progressbar(self,maxi = 4)
1361 # corpus = self.Source.corpus
1362 # uces = corpus.lc[self.cl-1]
1363 # tab = corpus.make_table_with_classe(uces, self.la)
1365 # dlg.Update(2, u'score...')
1367 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1369 # 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]
1370 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1372 # ntab2.sort(reverse = True)
1373 # ntab2 = ntab2[:limite]
1374 # nuces = [val[1] for val in ntab2]
1375 # dlg.Update(3, u'concordancier...')
1376 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1377 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1380 # for uce in ucestxt1 :
1381 # ucetxt = ' '+uce[1]+' '
1382 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1383 # for lem in self.la :
1384 # listmot = corpus.getlems()[lem].formes
1385 # for id in listmot :
1386 # forme = corpus.getforme(id).forme
1387 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1388 # ucestxt.append(ucetxt)
1389 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1390 # dlg.Update(4, u'texte...')
1391 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1392 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1393 # 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>'
1394 # win.HtmlPage.SetPage(win.html)
1398 # def on_tablex(self, evt):
1399 # if 'corpus' in dir(self.Source):
1400 # corpus = self.Source.corpus
1402 # corpus = self.Source.tableau
1403 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1404 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1405 # title = chistable[0]
1408 # vchistable = [line[1:] for line in chistable]
1409 # fchistable = [line[0] for line in chistable]
1410 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1411 # tableout = [vchistable[fchistable.index(words[0])]]
1412 # last = self.list.GetFirstSelected()
1413 # while self.list.GetNextSelected(last) != -1:
1414 # last = self.list.GetNextSelected(last)
1415 # word = self.getColumnText(last, 6)
1416 # words.append(word)
1417 # tableout.append(vchistable[fchistable.index(word)])
1418 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1420 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1421 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1422 # file = open(tmpscript,'w')
1426 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1427 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1428 # win.addsaveimage(tmpgraph)
1429 # txt = "<img src='%s'>" % tmpgraph
1430 # win.HtmlPage.SetPage(txt)
1433 # def onlexdendro(self, evt):
1434 # if 'corpus' in dir(self.Source):
1435 # corpus = self.Source.corpus
1437 # corpus = self.Source.tableau
1438 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1439 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1440 # title = chistable[0]
1443 # vchistable = [line[1:] for line in chistable]
1444 # fchistable = [line[0] for line in chistable]
1445 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1446 # tableout = [vchistable[fchistable.index(words[0])]]
1447 # last = self.list.GetFirstSelected()
1448 # while self.list.GetNextSelected(last) != -1:
1449 # last = self.list.GetNextSelected(last)
1450 # word = self.getColumnText(last, 6)
1451 # words.append(word)
1452 # tableout.append(vchistable[fchistable.index(word)])
1453 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1454 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1455 # rownames = 'c("' + '","'.join(words) + '")'
1456 # colnames = 'c("' + '","'.join(title) + '")'
1458 # rownb = len(words)
1461 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1463 # colnames(di) <- %s
1466 # height <- (30*ncol(di)) + (15*nrow(di))
1467 # height <- ifelse(height <= 400, 400, height)
1469 # open_file_graph("%s", width=width, height=height)
1470 # plot.dendro.lex(tree.cut1$tree.cl, di)
1471 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1472 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1473 # file = open(tmpscript,'w')
1476 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1477 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1478 # win.addsaveimage(tmpgraph)
1479 # txt = "<img src='%s'>" % tmpgraph
1480 # win.HtmlPage.SetPage(txt)
1484 # def make_concord(self, uces, title, color = 'red') :
1485 # corpus = self.Source.corpus
1486 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1487 # last = self.list.GetFirstSelected()
1488 # while self.list.GetNextSelected(last) != -1:
1489 # last = self.list.GetNextSelected(last)
1490 # ListWord.append(self.getColumnText(last, 6))
1491 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1492 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1493 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1494 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1497 # for word in ListWord :
1498 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1499 # ucef = list(set(ucef))
1501 # res = corpus.getconcorde(ucef)
1502 # txt = '<br>'.join(toshow) +'<br><br>'
1504 # ucetxt = ' '+uce[1]+' '
1505 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1506 # for forme in listmot:
1507 # forme = corpus.getforme(forme).forme
1508 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1509 # txt += ucetxt + '<br><br>'
1510 # win.HtmlPage.SetPage(txt)
1513 # def OnPopupTwo(self, event):
1514 # corpus = self.Source.corpus
1515 # uces = corpus.lc[self.cl-1]
1516 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1519 # def OnPopupThree(self, event):
1520 # corpus = self.Source.corpus
1521 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1522 # win = self.make_concord(uces, "Concordancier - UCE classées")
1525 # def OnPopupFour(self, event):
1526 # corpus = self.Source.corpus
1527 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1528 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1531 # def OnPopupFive(self, event):
1532 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1533 # lk = "http://www.cnrtl.fr/definition/" + word
1534 # webbrowser.open(lk)
1536 # def OnPopupSix(self, event):
1537 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1538 # lk = "http://www.cnrtl.fr/etymologie/" + word
1539 # webbrowser.open(lk)
1541 # def OnPopupSeven(self, event):
1542 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1543 # lk = "http://www.cnrtl.fr/synonymie/" + word
1544 # webbrowser.open(lk)
1546 # def OnPopupHeight(self, event):
1547 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1548 # lk = "http://www.cnrtl.fr/antonymie/" + word
1549 # webbrowser.open(lk)
1551 # def OnPopupNine(self, event):
1552 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1553 # lk = "http://www.cnrtl.fr/morphologie/" + word
1554 # webbrowser.open(lk)
1556 # def onproxe(self, evt) :
1557 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1558 # lk = "http://www.cnrtl.fr/proxemie/" + word
1559 # webbrowser.open(lk)
1561 # def OnSize(self, event):
1562 # w, h = self.GetClientSizeTuple()
1563 # self.list.SetDimensions(0, 0, w, h)
1565 # def OnColClick(self, event):
1566 # self.do_greyline()
1569 #class wliste(wx.Frame):
1570 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1571 # wx.Frame.__init__(self, parent, id)
1572 # self.liste = ListForSpec(self, parent, d, fline)
1573 # self.button_1 = wx.Button(self, -1, "Fermer")
1574 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1575 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1576 # self.__do_layout()
1578 # def __do_layout(self):
1579 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1580 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1581 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1582 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1583 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1584 # self.SetAutoLayout(True)
1585 # self.SetSizer(sizer_1)
1588 # def OnCloseMe(self, event):
1591 # def OnCloseWindow(self, event):
1594 class message(wx.Frame):
1595 def __init__(self, *args, **kwds):
1596 kwds["style"] = wx.DEFAULT_FRAME_STYLE
1597 wx.Frame.__init__(self, *args, **kwds)
1599 self.HtmlPage=wx.html.HtmlWindow(self, -1)
1600 if "gtk2" in wx.PlatformInfo:
1601 self.HtmlPage.SetStandardFonts()
1602 self.HtmlPage.SetFonts('Courier','Courier')
1603 self.button_1 = wx.Button(self, -1, "Fermer")
1604 self.button_2 = wx.Button(self, -1, u"Enregistrer...")
1606 self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1607 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1608 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1611 def __do_layout(self):
1612 sizer_1 = wx.BoxSizer(wx.VERTICAL)
1613 sizer_2 = wx.BoxSizer(wx.VERTICAL)
1614 sizer_2.Add(self.HtmlPage, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1615 sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
1616 sizer_2.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
1617 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1618 self.SetAutoLayout(True)
1619 self.SetSizer(sizer_1)
1622 def OnSavePage(self, evt) :
1623 dlg = wx.FileDialog(
1624 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1625 defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1627 dlg.SetFilterIndex(2)
1628 dlg.CenterOnParent()
1629 if dlg.ShowModal() == wx.ID_OK:
1630 path = dlg.GetPath()
1631 with open(path, 'w') as f :
1634 def OnCloseMe(self, event):
1637 def OnCloseWindow(self, event):
1640 #def getSmallUpArrowData():
1642 #'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
1643 #\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
1644 #\x00\x00<IDAT8\x8dcddbf\xa0\x040Q\xa4{h\x18\xf0\xff\xdf\xdf\xffd\x1b\x00\xd3\
1645 #\x8c\xcf\x10\x9c\x06\xa0k\xc2e\x08m\xc2\x00\x97m\xd8\xc41\x0c \x14h\xe8\xf2\
1646 #\x8c\xa3)q\x10\x18\x00\x00R\xd8#\xec\xb2\xcd\xc1Y\x00\x00\x00\x00IEND\xaeB`\
1649 #def getSmallUpArrowBitmap():
1650 # return wx.BitmapFromImage(getSmallUpArrowImage())
1652 #def getSmallUpArrowImage():
1653 # stream = cStringIO.StringIO(getSmallUpArrowData())
1654 # return wx.ImageFromStream(stream)
1656 ##----------------------------------------------------------------------
1657 #def getSmallDnArrowData():
1659 #"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
1660 #\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
1661 #\x00\x00HIDAT8\x8dcddbf\xa0\x040Q\xa4{\xd4\x00\x06\x06\x06\x06\x06\x16t\x81\
1662 #\xff\xff\xfe\xfe'\xa4\x89\x91\x89\x99\x11\xa7\x0b\x90%\ti\xc6j\x00>C\xb0\x89\
1663 #\xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\
1664 #?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82"
1666 #def getSmallDnArrowBitmap():
1667 # return wx.BitmapFromImage(getSmallDnArrowImage())
1669 #def getSmallDnArrowImage():
1670 # stream = cStringIO.StringIO(getSmallDnArrowData())
1671 # return wx.ImageFromStream(stream)