1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
19 import wx.lib.mixins.listctrl as listmix
20 from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial, message
24 from tableau import Tableau
25 from search_tools import SearchFrame
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
41 self.Alceste = Alceste
46 line1 = profclasse.pop(0)
47 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
49 self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
50 profclasse.pop(self.lenact)
52 self.lenact = len(profclasse)
54 self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
55 self.lensup = self.lensup - self.lenact
56 profclasse.pop(self.lensup)
59 self.lenet = len(profclasse) - (self.lenact + self.lensup)
60 # print self.lenact, self.lensup, self.lenet
61 for i, line in enumerate(classen) :
63 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
66 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
67 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
68 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
75 self.il = wx.ImageList(16, 16)
76 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
78 s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
80 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
82 #adding some attributes (colourful background for each item rows)
83 self.attr1 = wx.ListItemAttr()
84 self.attr1.SetBackgroundColour((220, 220, 220))
85 self.attrsg = wx.ListItemAttr()
86 self.attrsg.SetBackgroundColour((230, 230, 230))
87 self.attr2 = wx.ListItemAttr()
88 self.attr2.SetBackgroundColour((190, 249, 236))
89 self.attr2s = wx.ListItemAttr()
90 self.attr2s.SetBackgroundColour((211, 252, 244))
91 self.attr3 = wx.ListItemAttr()
92 self.attr3.SetBackgroundColour((245, 180, 180))
93 self.attr3s = wx.ListItemAttr()
94 self.attr3s.SetBackgroundColour((245, 190, 190))
97 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
98 self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
99 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
100 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
101 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
102 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
103 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
104 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
107 self.SetColumnWidth(0, 60)
108 self.SetColumnWidth(1, 70)
109 self.SetColumnWidth(2, 80)
110 self.SetColumnWidth(3, 100)
111 self.SetColumnWidth(4, 70)
112 self.SetColumnWidth(5, 60)
113 self.SetColumnWidth(6, 140)
114 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
116 #These two should probably be passed to init more cleanly
117 #setting the numbers of items = number of elements in the dictionary
118 self.itemDataMap = dictdata
119 self.itemIndexMap = dictdata.keys()
120 self.SetItemCount(len(dictdata))
123 listmix.ListCtrlAutoWidthMixin.__init__(self)
124 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
126 #sort by genre (column 2), A->Z ascending order (1)
127 self.SortListItems(0, 1)
130 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
131 #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
132 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
133 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
136 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
139 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
142 search_id = wx.NewId()
143 searchall_id = wx.NewId()
144 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
145 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
146 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
147 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
148 self.SetAcceleratorTable(self.accel_tbl)
152 def OnColClick(self,event):
155 def OnItemSelected(self, event):
156 self.currentItem = event.m_itemIndex
158 def OnItemActivated(self, event):
159 self.currentItem = event.m_itemIndex
161 def getColumnText(self, index, col):
162 item = self.GetItem(index, col)
163 return item.GetText()
165 def OnItemDeselected(self, evt):
167 #---------------------------------------------------
168 # These methods are callbacks for implementing the
169 # "virtualness" of the list...
171 def OnGetItemText(self, item, col):
172 index=self.itemIndexMap[item]
173 s = self.itemDataMap[index][col]
176 def OnGetItemImage(self, item):
177 index=self.itemIndexMap[item]
178 genre=self.itemDataMap[index][2]
184 elif genre=="New Age":
189 def OnGetItemAttr(self, item):
190 index=self.itemIndexMap[item]
191 if index < self.lenact :
196 elif index >= self.lenact and index < (self.lenact + self.lensup) :
201 elif index >= (self.lenact + self.lensup) :
209 #---------------------------------------------------
211 # Here's a better SortItems() method --
212 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
213 # and it knows to sort on another column if the chosen columns have the same value.
215 def SortItems(self,sorter=cmp):
216 items = list(self.itemDataMap.keys())
218 self.itemIndexMap = items
223 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
224 def GetListCtrl(self):
227 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
228 def GetSortImages(self):
229 return (self.sm_dn, self.sm_up)
231 def onsearch(self, evt) :
232 self.dial = SearchDial(self, self, 6, True)
233 self.dial.CenterOnParent()
234 self.dial.ShowModal()
237 def onsearchall(self, evt) :
238 if 'FrameSearch' not in dir(self.Source) :
239 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
240 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
241 self.dial.CenterOnParent()
242 self.dial.ShowModal()
245 def OnRightClick(self, event):
247 # only do this part the first time so the events are only bound once
249 if not hasattr(self, "popupID1"):
250 self.popupID1 = wx.NewId()
251 self.popupID2 = wx.NewId()
252 self.popupID3 = wx.NewId()
253 self.popupID4 = wx.NewId()
254 self.popupID5 = wx.NewId()
255 self.popupID6 = wx.NewId()
256 self.popupID7 = wx.NewId()
257 self.popupID8 = wx.NewId()
258 self.popupID9 = wx.NewId()
259 #self.popupID10 = wx.NewId()
260 self.popupIDgraph = wx.NewId()
261 self.idseg = wx.NewId()
262 self.iducecarac = wx.NewId()
263 self.idtablex = wx.NewId()
264 self.idchimod = wx.NewId()
265 self.idwordgraph = wx.NewId()
266 self.popup_proxe = wx.NewId()
267 self.idlexdendro = wx.NewId()
268 self.idexport = wx.NewId()
269 # self.export_classes = wx.NewId()
271 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
272 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
273 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
274 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
275 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
276 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
277 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
278 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
279 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
280 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
281 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
282 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
283 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
284 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
285 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
286 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
287 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
288 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
289 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
290 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
291 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
295 menu.Append(self.popupID1, u"Formes associées")
296 menu.Append(self.idtablex, u"Chi2 par classe")
297 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
298 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
299 menu.Append(self.idwordgraph, u"Graphe du mot")
300 #menu.Append(self.export_classes, u"Exporter le corpus...")
302 #menu.Append(self.popupID10, u"Spécificités")
304 menu_conc = wx.Menu()
305 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
306 menu_conc.Append(self.popupID3, u"dans les uce classées")
307 menu_conc.Append(self.popupID4, u"dans toutes les uce")
308 menu.AppendMenu(-1, u"Concordancier", menu_conc)
309 menu_cnrtl = wx.Menu()
310 menu_cnrtl.Append(self.popupID5, u"Définition")
311 menu_cnrtl.Append(self.popupID6, u"Etymologie")
312 menu_cnrtl.Append(self.popupID7, u"Synonymie")
313 menu_cnrtl.Append(self.popupID8, u"Antonymie")
314 menu_cnrtl.Append(self.popupID9, u"Morphologie")
315 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
316 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
317 menu.AppendSeparator()
318 menu.Append(self.popupIDgraph, u"Graphe de la classe")
319 menu.Append(self.idseg, u"Segments répétés")
320 menu.Append(self.iducecarac, u"UCE caractéristiques")
321 menu.Append(self.idexport, 'Partitionner...')
322 #menu.Append(self.popupID2, u"Concordancier")
323 # menu.Append(self.popupID3, "recharger")
327 elif 'tableau' in dir(self.Source) :
328 if not hasattr(self, "pop1"):
329 self.pop1 = wx.NewId()
330 self.pop2 = wx.NewId()
331 self.pop3 = wx.NewId()
332 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
333 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
334 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
337 menu.Append(self.pop2, u"Chi2 par classe")
338 menu.Append(self.pop3, u"Chi2 modalités de la variable")
339 menu.AppendSeparator()
340 menu.Append(self.pop1, u"Graph de la classe")
344 def onexport(self, evt) :
345 if 'corpus' in dir(self.Source):
346 corpus = self.Source.corpus
347 ClasseCHD(self.parent, corpus, self.cl)
349 def getselectedwords(self) :
350 words = [self.getColumnText(self.GetFirstSelected(), 6)]
351 last = self.GetFirstSelected()
352 while self.GetNextSelected(last) != -1:
353 last = self.GetNextSelected(last)
354 words.append(self.getColumnText(last, 6))
357 def quest_var_mod(self, evt) :
358 if 'corpus' in dir(self.Source):
359 corpus = self.Source.corpus
360 if self.var_mod == {} :
361 self.var_mod = self.Source.corpus.make_etoiles_dict()
363 corpus = self.Source.tableau
364 if self.var_mod == {} :
365 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
366 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
367 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
371 vchistable = [line[1:] for line in chistable]
372 fchistable = [line[0] for line in chistable]
373 word = self.getselectedwords()[0]
374 if len(word.split('_')) > 1 :
375 var = word.split('_')
376 words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
381 if word in fchistable :
382 tableout.append(vchistable[fchistable.index(word)])
384 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
385 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
386 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
387 file = open(tmpscript,'w')
390 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
391 win = MessageImage(self,u"Graphique", size=(700, 500))
392 win.addsaveimage(tmpgraph)
393 txt = "<img src='%s'>" % tmpgraph
394 win.HtmlPage.SetPage(txt)
397 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
398 dial.CenterOnParent()
402 def quest_simi(self, evt) :
403 tableau = self.Source.tableau
404 tab = tableau.make_table_from_classe(self.cl, self.la)
405 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
406 self.filename = os.path.join(pathout,'mat01.csv')
407 tableau.printtable(self.filename, tab)
409 paramsimi = {'coeff' : 0,
432 'cola' : (200,200,200),
440 # self.tableau.actives = {}
441 # self.tableau.lchi = self.lchi
442 # self.tableau.chi = {}
443 # for i, val in enumerate(self.la) :
444 # self.tableau.actives[val] = [self.lfreq[i]]
445 # self.tableau.chi[val] = [self.lchi[i]]
448 self.tableau.chi = {}
449 self.tableau.lchi = self.lchi
450 self.tableau.parametre['fromprof'] = True
451 for i, val in enumerate(self.la) :
452 act[val] = [self.lfreq[i]]
453 self.tableau.chi[val] = [self.lchi[i]]
454 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
456 def onwordgraph(self, evt):
457 word = self.getColumnText(self.GetFirstSelected(), 6)
458 dlg = progressbar(self, 2)
459 corpus = self.Source.corpus
460 uces = corpus.lc[self.cl-1]
461 dlg.Update(1, u'Tableau...')
462 #tab = corpus.make_table_with_classe(uces, self.la)
463 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
464 self.filename = os.path.join(pathout,'mat01.csv')
465 dlg.Update(2, u'Ecriture...')
466 #corpus.write_tab(tab, self.filename)
468 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
470 paramsimi = {'coeff' : 0,
491 'cola' : (200,200,200),
499 self.tableau = Tableau(self.parent, '')
500 self.tableau.listactives = self.la
501 self.tableau.actives = {}
502 for i, val in enumerate(self.la) :
503 self.tableau.actives[val] = [self.lfreq[i]]
504 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
506 def on_graph(self, evt):
507 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = {'type' : 'clustersimitxt', 'pathout' : self.Source.parametres['pathout']}, dlg = progressbar(self, 4))
508 #dlg = progressbar(self, 2)
509 #corpus = self.Source.corpus
510 #uces = corpus.lc[self.cl-1]
511 #dlg.Update(1, u'Tableau...')
512 ##tab = corpus.make_table_with_classe(uces, self.la)
513 #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
514 #self.filename = os.path.join(pathout,'mat01.csv')
515 #dlg.Update(2, u'Ecriture...')
516 ##corpus.write_tab(tab, self.filename)
518 #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
520 #paramsimi = {'coeff' : 0,
531 # 'coeff_temax' : 10,
538 # 'cexfromchi' : True,
542 # 'cols' : (255,0,0),
543 # 'cola' : (200,200,200),
547 # 'keep_coord' : True,
551 #self.tableau = Tableau(self.parent, '')
552 #self.tableau.listactives = self.la
553 #self.tableau.actives = {}
554 #self.tableau.lchi = self.lchi
555 #self.tableau.chi = {}
556 #self.tableau.parametre['fromprof'] = True
557 #for i, val in enumerate(self.la) :
558 # self.tableau.actives[val] = [self.lfreq[i]]
559 # self.tableau.chi[val] = [self.lchi[i]]
560 #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
562 def on_segments(self,evt) :
563 dlg = progressbar(self, 2)
564 corpus = self.Source.corpus
565 uces = corpus.lc[self.cl-1]
567 dlg.Update(1, u'Segments...')
568 for i in range(2,10) :
569 li = corpus.find_segments_in_classe(uces, i, 1000)
574 l.sort(reverse = True)
576 dlg.Update(2, 'Tri...')
577 for i, line in enumerate(l) :
578 d[i] = [line[1],line[0], line[2]]
580 para={'dico': d,'fline':first}
582 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
585 def on_uce_carac(self,evt) :
586 dial = PrefUCECarac(self, self.parent)
587 dial.CenterOnParent()
588 if dial.ShowModal() == wx.ID_OK :
589 limite = dial.spin_eff.GetValue()
590 atype = dial.radio_type.GetSelection()
591 dlg = progressbar(self,maxi = 4)
592 corpus = self.Source.corpus
593 uces = corpus.lc[self.cl-1]
594 tab = corpus.make_table_with_classe(uces, self.la)
596 dlg.Update(2, u'score...')
598 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
600 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]
601 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
603 ntab2.sort(reverse = True)
604 ntab2 = ntab2[:limite]
605 nuces = [val[1] for val in ntab2]
606 dlg.Update(3, u'concordancier...')
607 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
608 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
611 for uce in ucestxt1 :
612 ucetxt = ' '+uce[1]+' '
613 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
615 listmot = corpus.getlems()[lem].formes
617 forme = corpus.getforme(id).forme
618 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
619 ucestxt.append(ucetxt)
620 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
621 dlg.Update(4, u'texte...')
622 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
623 win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
624 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>'
625 win.HtmlPage.SetPage(win.html)
629 def on_tablex(self, evt):
630 if 'corpus' in dir(self.Source):
631 corpus = self.Source.corpus
633 corpus = self.Source.tableau
634 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
635 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
639 vchistable = [line[1:] for line in chistable]
640 fchistable = [line[0] for line in chistable]
641 words = self.getselectedwords()
642 tableout = [vchistable[fchistable.index(word)] for word in words]
643 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
646 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
647 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
648 file = open(tmpscript,'w')
651 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
652 w = 100 + (20 * nbwords) + (100 * nbcl)
653 h = 100 + (nbwords * 15)
654 if w > 1100 : w = 1100
657 win = MessageImage(self, u"Graphique", size=(w, h))
658 win.addsaveimage(tmpgraph)
659 txt = "<img src='%s'>" % tmpgraph
660 win.HtmlPage.SetPage(txt)
663 def onlexdendro(self, evt):
664 if 'corpus' in dir(self.Source):
665 corpus = self.Source.corpus
667 corpus = self.Source.tableau
668 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
669 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
673 vchistable = [line[1:] for line in chistable]
674 fchistable = [line[0] for line in chistable]
675 words = self.getselectedwords()
676 tableout = [vchistable[fchistable.index(word)] for word in words]
677 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
678 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
679 rownames = 'c("' + '","'.join(words) + '")'
680 colnames = 'c("' + '","'.join(title) + '")'
685 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
690 height <- (30*ncol(di)) + (15*nrow(di))
691 height <- ifelse(height <= 400, 400, height)
693 open_file_graph("%s", width=width, height=height)
694 plot.dendro.lex(tree.cut1$tree.cl, di)
695 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
696 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
697 file = open(tmpscript,'w')
700 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
701 win = MessageImage(self, u"Graphique", size=(700, 500))
702 win.addsaveimage(tmpgraph)
703 txt = "<img src='%s'>" % tmpgraph
704 win.HtmlPage.SetPage(txt)
708 def make_concord(self, uces, title, color = 'red') :
709 corpus = self.Source.corpus
710 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
711 last = self.GetFirstSelected()
712 while self.GetNextSelected(last) != -1:
713 last = self.GetNextSelected(last)
714 ListWord.append(self.getColumnText(last, 6))
715 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
716 win = message(self, title, size=(750, 600))
717 toshow = ['<html>\n<H1>Concordancier</H1>\n']
718 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
721 for word in ListWord :
722 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
723 ucef = list(set(ucef))
725 res = corpus.getconcorde(ucef)
726 txt = '<br>'.join(toshow) +'<br><br>'
728 ucetxt = ' '+uce[1]+' '
729 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
730 for forme in listmot:
731 forme = corpus.getforme(forme).forme
732 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
733 txt += ucetxt + '<br><br>'
734 win.HtmlPage.SetPage(txt)
737 def OnPopupTwo(self, event):
738 corpus = self.Source.corpus
739 uces = corpus.lc[self.cl-1]
740 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
743 def OnPopupThree(self, event):
744 corpus = self.Source.corpus
745 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
746 win = self.make_concord(uces, "Concordancier - UCE classées")
749 def OnPopupFour(self, event):
750 corpus = self.Source.corpus
751 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
752 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
755 def OnPopupFive(self, event):
756 word = self.getColumnText(self.GetFirstSelected(), 6)
757 lk = "http://www.cnrtl.fr/definition/" + word
760 def OnPopupSix(self, event):
761 word = self.getColumnText(self.GetFirstSelected(), 6)
762 lk = "http://www.cnrtl.fr/etymologie/" + word
765 def OnPopupSeven(self, event):
766 word = self.getColumnText(self.GetFirstSelected(), 6)
767 lk = "http://www.cnrtl.fr/synonymie/" + word
770 def OnPopupHeight(self, event):
771 word = self.getColumnText(self.GetFirstSelected(), 6)
772 lk = "http://www.cnrtl.fr/antonymie/" + word
775 def OnPopupNine(self, event):
776 word = self.getColumnText(self.GetFirstSelected(), 6)
777 lk = "http://www.cnrtl.fr/morphologie/" + word
780 def onproxe(self, evt) :
781 word = self.getColumnText(self.GetFirstSelected(), 6)
782 lk = "http://www.cnrtl.fr/proxemie/" + word
786 #---------------------------------------------------------------------------
787 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
788 # def __init__(self, parent, ID, pos=wx.DefaultPosition,
789 # size=wx.DefaultSize, style=0):
790 # wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
791 # listmix.ListCtrlAutoWidthMixin.__init__(self)
794 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
795 # def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
796 # self.parent = parent
797 # classe = ProfClasse
799 # self.Source = gparent
800 # if 'tableau' in dir(self.Source):
801 # self.tableau = self.Source.tableau
802 # self.Alceste = Alceste
806 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
808 # search_id = wx.NewId()
809 # searchall_id = wx.NewId()
810 # self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
811 # self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
812 # self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
813 # (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
814 # self.SetAcceleratorTable(self.accel_tbl)
816 # self.il = wx.ImageList(16, 16)
817 ## self.idx1 = self.il.Add(images.getSmilesBitmap())
818 # self.sm_up = self.il.Add(getSmallUpArrowBitmap())
819 # self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
822 # self.list = ProfListctrl(self, tID,
825 # | wx.LC_EDIT_LABELS
826 # | wx.LC_SORT_ASCENDING
828 # line1 = classe.pop(0)
833 # classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
834 # if len(classen) == 0 :
839 # lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
842 # lenact = [i for i,b in enumerate(classe) if b[0] == '*']
844 # lenact = len(classen)
848 # lenet = len(classen)
851 # lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
853 # lensup = lensup[0] - lenact
854 # lenet = len(classen) - lensup
857 # lenet = len(classen)
860 # self.lenact = lenact
862 # debet = lenact + lensup
863 # dictdata = dict(zip([i for i in range(0,len(classen))], classen))
864 # self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
866 # self.PopulateList(dictdata, debet, debsup, Alceste)
868 # self.Bind(wx.EVT_SIZE, self.OnSize)
869 # self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
870 # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
873 # self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
876 # self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
877 # self.itemDataMap = dictdata
878 # listmix.ColumnSorterMixin.__init__(self, 8)
880 ##-----------------------------------------------------------------------------------------
882 # def PopulateList(self, dictdata, limit, limitsup, Alceste):
885 # # for normal, simple columns, you can add them like this:
886 # self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
887 # self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
888 # self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
889 # self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
890 # self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
891 # self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
892 # self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
893 # self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
895 # for key in dictdata : #.iteritems():
896 # index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
898 # for val in dictdata[key][1:]:
899 # self.list.SetStringItem(index, i, str(dictdata[key][i]))
901 # self.list.SetItemData(index, key)
903 # self.list.SetColumnWidth(0, 60)
904 # self.list.SetColumnWidth(1, 70)
905 # self.list.SetColumnWidth(2, 80)
906 # self.list.SetColumnWidth(3, 100)
907 # self.list.SetColumnWidth(4, 70)
908 # self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
909 # self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
910 # self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
912 # # show how to change the colour of a couple items
913 # for i in range(limitsup, limit):
914 # item = self.list.GetItem(i)
915 # item.SetTextColour(wx.RED)
916 # self.list.SetItem(item)
918 # for i in range(limit, len(dictdata)):
919 # item = self.list.GetItem(i)
920 # item.SetTextColour(wx.BLUE)
921 # self.list.SetItem(item)
923 # if self.lenact != 0 :
924 # self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
925 # self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
926 # self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
932 # def do_greyline(self):
933 # for row in xrange(self.list.GetItemCount()):
935 # self.list.SetItemBackgroundColour(row, (230, 230, 230))
937 # self.list.SetItemBackgroundColour(row, wx.WHITE)
940 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
941 # def GetListCtrl(self):
944 # # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
945 # def GetSortImages(self):
946 # return (self.sm_dn, self.sm_up)
949 # def OnRightDown(self, event):
952 # item, flags = self.list.HitTest((x, y))
954 # if flags & wx.LIST_HITTEST_ONITEM:
955 # self.list.Select(item)
960 # def getColumnText(self, index, col):
961 # item = self.list.GetItem(index, col)
962 # return item.GetText()
965 # def OnItemSelected(self, event):
966 # self.currentItem = event.m_itemIndex
969 # def onsearch(self, evt) :
970 # self.dial = SearchDial(self, self, 6, True)
971 # self.dial.CenterOnParent()
972 # self.dial.ShowModal()
973 # self.dial.Destroy()
975 # def onsearchall(self, evt) :
976 # if 'FrameSearch' not in dir(self.Source) :
977 # self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
978 # self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
979 # self.dial.CenterOnParent()
980 # self.dial.ShowModal()
981 # self.dial.Destroy()
983 # def OnRightClick(self, event):
985 # # only do this part the first time so the events are only bound once
987 # if not hasattr(self, "popupID1"):
988 # self.popupID1 = wx.NewId()
989 # self.popupID2 = wx.NewId()
990 # self.popupID3 = wx.NewId()
991 # self.popupID4 = wx.NewId()
992 # self.popupID5 = wx.NewId()
993 # self.popupID6 = wx.NewId()
994 # self.popupID7 = wx.NewId()
995 # self.popupID8 = wx.NewId()
996 # self.popupID9 = wx.NewId()
997 # #self.popupID10 = wx.NewId()
998 # self.popupIDgraph = wx.NewId()
999 # self.idseg = wx.NewId()
1000 # self.iducecarac = wx.NewId()
1001 # self.idtablex = wx.NewId()
1002 # self.idchimod = wx.NewId()
1003 # self.idwordgraph = wx.NewId()
1004 # self.popup_proxe = wx.NewId()
1005 # self.idlexdendro = wx.NewId()
1006 # self.idexport = wx.NewId()
1007 # # self.export_classes = wx.NewId()
1009 # self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
1010 # self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
1011 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1012 # self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1013 # self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1014 # self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1015 # self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1016 # self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1017 # self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1018 # #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1019 # self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1020 # self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1021 # self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1022 # self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1023 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1024 # self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1025 # self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1026 # self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1027 # self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1028 # # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1029 # # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1033 # menu.Append(self.popupID1, u"Formes associées")
1034 # menu.Append(self.idtablex, u"Chi2 par classe")
1035 # menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1036 # menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1037 # menu.Append(self.idwordgraph, u"Graphe du mot")
1038 # #menu.Append(self.export_classes, u"Exporter le corpus...")
1040 # #menu.Append(self.popupID10, u"Spécificités")
1042 # menu_conc = wx.Menu()
1043 # menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1044 # menu_conc.Append(self.popupID3, u"dans les uce classées")
1045 # menu_conc.Append(self.popupID4, u"dans toutes les uce")
1046 # menu.AppendMenu(-1, u"Concordancier", menu_conc)
1047 # menu_cnrtl = wx.Menu()
1048 # menu_cnrtl.Append(self.popupID5, u"Définition")
1049 # menu_cnrtl.Append(self.popupID6, u"Etymologie")
1050 # menu_cnrtl.Append(self.popupID7, u"Synonymie")
1051 # menu_cnrtl.Append(self.popupID8, u"Antonymie")
1052 # menu_cnrtl.Append(self.popupID9, u"Morphologie")
1053 # menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1054 # menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1055 # menu.AppendSeparator()
1056 # menu.Append(self.popupIDgraph, u"Graphe de la classe")
1057 # menu.Append(self.idseg, u"Segments répétés")
1058 # menu.Append(self.iducecarac, u"UCE caractéristiques")
1059 # menu.Append(self.idexport, 'Partitionner...')
1060 # #menu.Append(self.popupID2, u"Concordancier")
1061 # # menu.Append(self.popupID3, "recharger")
1063 # self.PopupMenu(menu)
1065 # elif 'tableau' in dir(self.Source) :
1066 # if not hasattr(self, "pop1"):
1067 # self.pop1 = wx.NewId()
1068 # self.pop2 = wx.NewId()
1069 # self.pop3 = wx.NewId()
1070 # self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1071 # self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1072 # self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1075 # menu.Append(self.pop2, u"Chi2 par classe")
1076 # menu.Append(self.pop3, u"Chi2 modalités de la variable")
1077 # menu.AppendSeparator()
1078 # menu.Append(self.pop1, u"Graph de la classe")
1079 # self.PopupMenu(menu)
1082 # def onexport(self, evt) :
1083 # if 'corpus' in dir(self.Source):
1084 # corpus = self.Source.corpus
1085 # ClasseCHD(self.parent, corpus, self.cl)
1087 # def quest_var_mod(self, evt) :
1088 # if 'corpus' in dir(self.Source):
1089 # corpus = self.Source.corpus
1090 # if self.var_mod == {} :
1091 # self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1093 # corpus = self.Source.tableau
1094 # if self.var_mod == {} :
1095 # self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1096 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1097 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1098 # title = chistable[0]
1101 # vchistable = [line[1:] for line in chistable]
1102 # fchistable = [line[0] for line in chistable]
1103 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1104 # if len(word.split('_')) > 1 :
1105 # var = word.split('_')[0]
1106 # words = [word for word in self.var_mod[var]]
1110 # for word in words :
1111 # if word in fchistable :
1112 # tableout.append(vchistable[fchistable.index(word)])
1113 # kwords.append(word)
1114 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1115 # txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1116 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1117 # file = open(tmpscript,'w')
1120 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1121 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1122 # win.addsaveimage(tmpgraph)
1123 # txt = "<img src='%s'>" % tmpgraph
1124 # win.HtmlPage.SetPage(txt)
1127 # dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1128 # dial.CenterOnParent()
1132 # def quest_simi(self, evt) :
1133 # tableau = self.Source.tableau
1134 # tab = tableau.make_table_from_classe(self.cl, self.la)
1135 # pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1136 # self.filename = os.path.join(pathout,'mat01.csv')
1137 # tableau.printtable(self.filename, tab)
1139 # paramsimi = {'coeff' : 0,
1144 # 'coeff_tv_nb' : 0,
1149 # 'coeff_temin' : 1,
1150 # 'coeff_temax' : 10,
1157 # 'cexfromchi' : True,
1158 # 'sfromchi': False,
1161 # 'cols' : (255,0,0),
1162 # 'cola' : (200,200,200),
1166 # 'keep_coord' : True,
1170 ## self.tableau.actives = {}
1171 ## self.tableau.lchi = self.lchi
1172 ## self.tableau.chi = {}
1173 ## for i, val in enumerate(self.la) :
1174 ## self.tableau.actives[val] = [self.lfreq[i]]
1175 ## self.tableau.chi[val] = [self.lchi[i]]
1178 # self.tableau.chi = {}
1179 # self.tableau.lchi = self.lchi
1180 # self.tableau.parametre['fromprof'] = True
1181 # for i, val in enumerate(self.la) :
1182 # act[val] = [self.lfreq[i]]
1183 # self.tableau.chi[val] = [self.lchi[i]]
1184 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1186 # def onwordgraph(self, evt):
1187 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1188 # dlg = progressbar(self, 2)
1189 # corpus = self.Source.corpus
1190 # uces = corpus.lc[self.cl-1]
1191 # dlg.Update(1, u'Tableau...')
1192 # #tab = corpus.make_table_with_classe(uces, self.la)
1193 # pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1194 # self.filename = os.path.join(pathout,'mat01.csv')
1195 # dlg.Update(2, u'Ecriture...')
1196 # #corpus.write_tab(tab, self.filename)
1198 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1200 # paramsimi = {'coeff' : 0,
1205 # 'coeff_tv_nb' : 0,
1210 # 'coeff_temin' : 1,
1211 # 'coeff_temax' : 10,
1220 # 'cols' : (255,0,0),
1221 # 'cola' : (200,200,200),
1225 # 'keep_coord' : True,
1229 # self.tableau = Tableau(self.parent, '')
1230 # self.tableau.listactives = self.la
1231 # self.tableau.actives = {}
1232 # for i, val in enumerate(self.la) :
1233 # self.tableau.actives[val] = [self.lfreq[i]]
1234 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1237 def OnPopupOne(self, event):
1238 corpus = self.Source.corpus
1239 #print 'ATTENTION PRINT ET TABLE'
1240 #corpus.make_et_table()
1241 word = self.getColumnText(self.GetFirstSelected(), 6)
1242 lems = corpus.getlems()
1243 uces = corpus.lc[self.cl-1]
1245 #FIXME : donner aussi eff reel a la place de nb uce
1246 for forme in lems[word].formes :
1247 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1248 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1251 rep.append([corpus.getforme(forme).forme, nb])
1252 win = message(self, u"Formes associées", wx.Size(300, 200))
1253 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1254 win.HtmlPage.SetPage(win.html)
1257 # def on_graph(self, evt):
1258 # dlg = progressbar(self, 2)
1259 # corpus = self.Source.corpus
1260 # uces = corpus.lc[self.cl-1]
1261 # dlg.Update(1, u'Tableau...')
1262 # #tab = corpus.make_table_with_classe(uces, self.la)
1263 # pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1264 # self.filename = os.path.join(pathout,'mat01.csv')
1265 # dlg.Update(2, u'Ecriture...')
1266 # #corpus.write_tab(tab, self.filename)
1268 # corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1270 # paramsimi = {'coeff' : 0,
1275 # 'coeff_tv_nb' : 0,
1280 # 'coeff_temin' : 1,
1281 # 'coeff_temax' : 10,
1288 # 'cexfromchi' : True,
1289 # 'sfromchi': False,
1292 # 'cols' : (255,0,0),
1293 # 'cola' : (200,200,200),
1297 # 'keep_coord' : True,
1301 # self.tableau = Tableau(self.parent, '')
1302 # self.tableau.listactives = self.la
1303 # self.tableau.actives = {}
1304 # self.tableau.lchi = self.lchi
1305 # self.tableau.chi = {}
1306 # self.tableau.parametre['fromprof'] = True
1307 # for i, val in enumerate(self.la) :
1308 # self.tableau.actives[val] = [self.lfreq[i]]
1309 # self.tableau.chi[val] = [self.lchi[i]]
1310 # DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1312 # def on_segments(self,evt) :
1313 # dlg = progressbar(self, 2)
1314 # corpus = self.Source.corpus
1315 # uces = corpus.lc[self.cl-1]
1317 # dlg.Update(1, u'Segments...')
1318 # for i in range(2,10) :
1319 # li = corpus.find_segments_in_classe(uces, i, 1000)
1324 # l.sort(reverse = True)
1326 # dlg.Update(2, 'Tri...')
1327 # for i, line in enumerate(l) :
1328 # d[i] = [line[1],line[0], line[2]]
1329 # first = ['','','']
1330 # para={'dico': d,'fline':first}
1332 # win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1335 # def on_uce_carac(self,evt) :
1336 # dial = PrefUCECarac(self, self.parent)
1337 # dial.CenterOnParent()
1338 # if dial.ShowModal() == wx.ID_OK :
1339 # limite = dial.spin_eff.GetValue()
1340 # atype = dial.radio_type.GetSelection()
1341 # dlg = progressbar(self,maxi = 4)
1342 # corpus = self.Source.corpus
1343 # uces = corpus.lc[self.cl-1]
1344 # tab = corpus.make_table_with_classe(uces, self.la)
1346 # dlg.Update(2, u'score...')
1348 # ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1350 # 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]
1351 # ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1353 # ntab2.sort(reverse = True)
1354 # ntab2 = ntab2[:limite]
1355 # nuces = [val[1] for val in ntab2]
1356 # dlg.Update(3, u'concordancier...')
1357 # #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1358 # ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1361 # for uce in ucestxt1 :
1362 # ucetxt = ' '+uce[1]+' '
1363 # ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1364 # for lem in self.la :
1365 # listmot = corpus.getlems()[lem].formes
1366 # for id in listmot :
1367 # forme = corpus.getforme(id).forme
1368 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1369 # ucestxt.append(ucetxt)
1370 # #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1371 # dlg.Update(4, u'texte...')
1372 # #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1373 # win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1374 # 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>'
1375 # win.HtmlPage.SetPage(win.html)
1379 # def on_tablex(self, evt):
1380 # if 'corpus' in dir(self.Source):
1381 # corpus = self.Source.corpus
1383 # corpus = self.Source.tableau
1384 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1385 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1386 # title = chistable[0]
1389 # vchistable = [line[1:] for line in chistable]
1390 # fchistable = [line[0] for line in chistable]
1391 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1392 # tableout = [vchistable[fchistable.index(words[0])]]
1393 # last = self.list.GetFirstSelected()
1394 # while self.list.GetNextSelected(last) != -1:
1395 # last = self.list.GetNextSelected(last)
1396 # word = self.getColumnText(last, 6)
1397 # words.append(word)
1398 # tableout.append(vchistable[fchistable.index(word)])
1399 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1401 # txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1402 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1403 # file = open(tmpscript,'w')
1407 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1408 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1409 # win.addsaveimage(tmpgraph)
1410 # txt = "<img src='%s'>" % tmpgraph
1411 # win.HtmlPage.SetPage(txt)
1414 # def onlexdendro(self, evt):
1415 # if 'corpus' in dir(self.Source):
1416 # corpus = self.Source.corpus
1418 # corpus = self.Source.tableau
1419 # with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1420 # chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1421 # title = chistable[0]
1424 # vchistable = [line[1:] for line in chistable]
1425 # fchistable = [line[0] for line in chistable]
1426 # words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1427 # tableout = [vchistable[fchistable.index(words[0])]]
1428 # last = self.list.GetFirstSelected()
1429 # while self.list.GetNextSelected(last) != -1:
1430 # last = self.list.GetNextSelected(last)
1431 # word = self.getColumnText(last, 6)
1432 # words.append(word)
1433 # tableout.append(vchistable[fchistable.index(word)])
1434 # tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1435 # txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1436 # rownames = 'c("' + '","'.join(words) + '")'
1437 # colnames = 'c("' + '","'.join(title) + '")'
1439 # rownb = len(words)
1442 # di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1444 # colnames(di) <- %s
1447 # height <- (30*ncol(di)) + (15*nrow(di))
1448 # height <- ifelse(height <= 400, 400, height)
1450 # open_file_graph("%s", width=width, height=height)
1451 # plot.dendro.lex(tree.cut1$tree.cl, di)
1452 # """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1453 # tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1454 # file = open(tmpscript,'w')
1457 # exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1458 # win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1459 # win.addsaveimage(tmpgraph)
1460 # txt = "<img src='%s'>" % tmpgraph
1461 # win.HtmlPage.SetPage(txt)
1465 # def make_concord(self, uces, title, color = 'red') :
1466 # corpus = self.Source.corpus
1467 # ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1468 # last = self.list.GetFirstSelected()
1469 # while self.list.GetNextSelected(last) != -1:
1470 # last = self.list.GetNextSelected(last)
1471 # ListWord.append(self.getColumnText(last, 6))
1472 # listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1473 # win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1474 # toshow = ['<html>\n<H1>Concordancier</H1>\n']
1475 # toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1478 # for word in ListWord :
1479 # ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1480 # ucef = list(set(ucef))
1482 # res = corpus.getconcorde(ucef)
1483 # txt = '<br>'.join(toshow) +'<br><br>'
1485 # ucetxt = ' '+uce[1]+' '
1486 # txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1487 # for forme in listmot:
1488 # forme = corpus.getforme(forme).forme
1489 # ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1490 # txt += ucetxt + '<br><br>'
1491 # win.HtmlPage.SetPage(txt)
1494 # def OnPopupTwo(self, event):
1495 # corpus = self.Source.corpus
1496 # uces = corpus.lc[self.cl-1]
1497 # win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1500 # def OnPopupThree(self, event):
1501 # corpus = self.Source.corpus
1502 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1503 # win = self.make_concord(uces, "Concordancier - UCE classées")
1506 # def OnPopupFour(self, event):
1507 # corpus = self.Source.corpus
1508 # uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1509 # win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1512 # def OnPopupFive(self, event):
1513 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1514 # lk = "http://www.cnrtl.fr/definition/" + word
1515 # webbrowser.open(lk)
1517 # def OnPopupSix(self, event):
1518 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1519 # lk = "http://www.cnrtl.fr/etymologie/" + word
1520 # webbrowser.open(lk)
1522 # def OnPopupSeven(self, event):
1523 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1524 # lk = "http://www.cnrtl.fr/synonymie/" + word
1525 # webbrowser.open(lk)
1527 # def OnPopupHeight(self, event):
1528 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1529 # lk = "http://www.cnrtl.fr/antonymie/" + word
1530 # webbrowser.open(lk)
1532 # def OnPopupNine(self, event):
1533 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1534 # lk = "http://www.cnrtl.fr/morphologie/" + word
1535 # webbrowser.open(lk)
1537 # def onproxe(self, evt) :
1538 # word = self.getColumnText(self.list.GetFirstSelected(), 6)
1539 # lk = "http://www.cnrtl.fr/proxemie/" + word
1540 # webbrowser.open(lk)
1542 # def OnSize(self, event):
1543 # w, h = self.GetClientSizeTuple()
1544 # self.list.SetDimensions(0, 0, w, h)
1546 # def OnColClick(self, event):
1547 # self.do_greyline()
1550 #class wliste(wx.Frame):
1551 # def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1552 # wx.Frame.__init__(self, parent, id)
1553 # self.liste = ListForSpec(self, parent, d, fline)
1554 # self.button_1 = wx.Button(self, -1, "Fermer")
1555 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1556 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1557 # self.__do_layout()
1559 # def __do_layout(self):
1560 # sizer_1 = wx.BoxSizer(wx.VERTICAL)
1561 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1562 # sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1563 # sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1564 # sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1565 # self.SetAutoLayout(True)
1566 # self.SetSizer(sizer_1)
1569 # def OnCloseMe(self, event):
1572 # def OnCloseWindow(self, event):
1575 #class message(wx.Dialog):
1576 # def __init__(self, parent, title, size, save = True):
1577 # wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1579 # self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1582 # self.HtmlPage=wx.html.HtmlWindow(self, -1)
1583 # self.HtmlPage.SetMinSize( size )
1584 # if "gtk2" in wx.PlatformInfo:
1585 # self.HtmlPage.SetStandardFonts()
1586 # self.HtmlPage.SetFonts('Courier','Courier')
1588 # self.button_1 = wx.Button(self, wx.ID_CANCEL)
1590 # self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1592 # self.button_2 = wx.Button(self, wx.ID_SAVE)
1593 # self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1594 # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1595 # self.__do_layout()
1597 # def __do_layout(self):
1598 # sizer_2 = wx.BoxSizer(wx.VERTICAL)
1599 # sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1600 # m_sdbSizer1 = wx.StdDialogButtonSizer()
1601 # m_sdbSizer1.AddButton( self.button_1 )
1603 # m_sdbSizer1.AddButton( self.button_2 )
1604 # m_sdbSizer1.Realize()
1605 # sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1606 # self.SetSizer(sizer_2)
1608 # sizer_2.Fit( self )
1610 # def OnSavePage(self, evt) :
1611 # dlg = wx.FileDialog(
1612 # self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1613 # defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1615 # dlg.SetFilterIndex(2)
1616 # dlg.CenterOnParent()
1617 # if dlg.ShowModal() == wx.ID_OK:
1618 # path = dlg.GetPath()
1619 # with open(path, 'w') as f :
1620 # f.write(self.html)
1622 # def OnCloseMe(self, event):
1625 # def OnCloseWindow(self, event):