1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #----------------------------------------------------------------------------
9 # comes from ListCtrl.py from the demo tool of wxPython:
10 # Author: Robin Dunn & Gary Dumer
13 # Copyright: (c) 1998 by Total Control Software
14 # Licence: wxWindows license
15 #----------------------------------------------------------------------------
17 #------------------------------------
18 # import des modules python
19 #------------------------------------
22 from operator import itemgetter
30 #------------------------------------
31 # import des modules wx
32 #------------------------------------
34 import wx.lib.mixins.listctrl as listmix
36 #------------------------------------
37 # import des fichiers du projet
38 #------------------------------------
39 from listlex import ListForSpec
40 from chemins import ConstructPathOut, ffr
41 from dialog import PrefUCECarac, SearchDial, message, BarFrame, ChronoFrame
42 from tableau import copymatrix
43 from search_tools import SearchFrame
44 from functions import progressbar, treat_var_mod, doconcorde
47 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
49 def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0, translation = False):
50 wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
52 self.Alceste = Alceste
54 self.translation = translation
58 self.ira = wx.GetApp().GetTopWindow()
59 line1 = profclasse.pop(0)
60 classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
62 self.lenact = profclasse.index(['*****', '*', '*', '*', '*', '*', '', ''])
63 profclasse.pop(self.lenact)
66 self.lenact = profclasse.index(['*', '*', '*', '*', '*', '*', '', ''])
67 profclasse.pop(self.lenact)
69 self.lenact = len(profclasse)
71 self.lensup = profclasse.index(['*', '*', '*', '*', '*', '*', '', ''])
72 self.lensup = self.lensup - self.lenact
73 profclasse.pop(self.lensup)
75 self.lensup = len(profclasse) - self.lenact
76 self.lenet = len(profclasse) - (self.lenact + self.lensup)
77 # print self.lenact, self.lensup, self.lenet
78 for i, line in enumerate(classen) :
80 dictdata = dict(list(zip([i for i in range(0,len(classen))], classen)))
82 self.la = [dictdata[i][6] for i in range(0, self.lenact)]
83 self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
84 self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
91 self.il = wx.ImageList(16, 16)
92 a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
93 for k,v in list(a.items()):
94 s="self.%s= self.il.Add(wx.ArtProvider.GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
96 self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
97 #adding some attributes (colourful background for each item rows)
98 self.attr1 = wx.ListItemAttr()
99 self.attr1.SetBackgroundColour((220, 220, 220))
100 self.attrsg = wx.ListItemAttr()
101 self.attrsg.SetBackgroundColour((230, 230, 230))
102 self.attr2 = wx.ListItemAttr()
103 self.attr2.SetBackgroundColour((190, 249, 236))
104 self.attr2s = wx.ListItemAttr()
105 self.attr2s.SetBackgroundColour((211, 252, 244))
106 self.attr3 = wx.ListItemAttr()
107 self.attr3.SetBackgroundColour((245, 180, 180))
108 self.attr3s = wx.ListItemAttr()
109 self.attr3s.SetBackgroundColour((245, 190, 190))
110 self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
111 self.InsertColumn(1, "eff. s.t.", wx.LIST_FORMAT_RIGHT)
112 self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
113 self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
114 self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
115 self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
116 self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
117 self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
118 self.SetColumnWidth(0, 60)
119 self.SetColumnWidth(1, 100)
120 self.SetColumnWidth(2, 100)
121 self.SetColumnWidth(3, 120)
122 self.SetColumnWidth(4, 150)
123 self.SetColumnWidth(5, 100)
124 self.SetColumnWidth(6, 300)
125 self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
126 #These two should probably be passed to init more cleanly
127 #setting the numbers of items = number of elements in the dictionary
128 self.itemDataMap = dictdata
129 self.itemIndexMap = list(dictdata.keys())
130 self.SetItemCount(len(dictdata))
132 listmix.ListCtrlAutoWidthMixin.__init__(self)
133 listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
134 self.SortListItems(0, True)
135 #sort by genre (column 2), A->Z ascending order (1)
139 #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
140 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnPopupTwo, self)
141 #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
142 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
144 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
146 self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
148 search_id = wx.NewId()
149 searchall_id = wx.NewId()
150 concord_id = wx.NewId()
151 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
152 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
153 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
154 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
155 self.SetAcceleratorTable(self.accel_tbl)
157 def OnGetItemColumnImage(self, item, col):
160 def OnGetItemImage(self, item):
163 def OnColClick(self,event):
166 def OnItemSelected(self, event):
167 self.currentItem = event.GetIndex() #event.m_itemIndex
169 def OnItemActivated(self, event):
170 self.currentItem = event.GetIndex() #event.m_itemIndex
172 def getColumnText(self, index, col):
173 item = self.GetItem(index, col)
174 return item.GetText()
176 def OnItemDeselected(self, evt):
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]
185 if isinstance(s, (int, float)):
188 return s #modification pour python 3
190 def OnGetItemAttr(self, item):
191 index=self.itemIndexMap[item]
192 if index < self.lenact :
197 elif index >= self.lenact and index < (self.lenact + self.lensup) :
202 elif index >= (self.lenact + self.lensup) :
210 #---------------------------------------------------
212 # Here's a better SortItems() method --
213 # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
214 # and it knows to sort on another column if the chosen columns have the same value.
216 # def SortItems(self,sorter=cmp): en version python2
217 def SortItems(self, sorter=None):
218 listTemp = sorted(self.itemDataMap.items(),
219 key=lambda x:x[1][self._col], reverse= (self._colSortFlag[self._col]!=True))
220 dlist = dict([[line[0],line[1]] for line in listTemp])
221 self.itemDataMap = dlist
222 self.itemIndexMap = list(dlist.keys())
223 self.Refresh() # redraw the list
225 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
226 def GetListCtrl(self):
229 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
230 def GetSortImages(self):
231 return (self.sm_dn, self.sm_up)
233 def onsearch(self, evt) :
234 self.dial = SearchDial(self, self, 6, True)
235 self.dial.CenterOnParent()
239 def onsearchall(self, evt) :
240 if 'FrameSearch' not in dir(self.Source) :
241 self.Source.FrameSearch = SearchFrame(self.parent, -1, _("Search..."), self.Source.corpus)
242 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
243 self.dial.CenterOnParent()
247 def OnRightClick(self, event):
248 # only do this part the first time so the events are only bound once
250 if not hasattr(self, "popupID1"):
251 self.popupID1 = wx.NewId()
252 self.popupID2 = wx.NewId()
253 self.popupID3 = wx.NewId()
254 self.popupID4 = wx.NewId()
255 self.popupID5 = wx.NewId()
256 self.popupID6 = wx.NewId()
257 self.popupID7 = wx.NewId()
258 self.popupID8 = wx.NewId()
259 self.popupID9 = wx.NewId()
260 #self.popupID10 = wx.NewId()
261 self.popupIDgraph = wx.NewId()
262 self.idseg = wx.NewId()
263 self.iducecarac = wx.NewId()
264 self.idtablex = wx.NewId()
265 self.idchimod = wx.NewId()
266 self.idwordgraph = wx.NewId()
267 self.popup_proxe = wx.NewId()
268 self.idlexdendro = wx.NewId()
269 self.idcloud = wx.NewId()
270 self.idexport = wx.NewId()
271 self.idexporttropes = wx.NewId()
272 self.idexportowledge = wx.NewId()
273 self.onmaketgen = wx.NewId()
274 self.onchronochi2 = wx.NewId()
275 self.onchronoprop = wx.NewId()
276 #self.export_classes = wx.NewId()
277 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
278 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
279 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
280 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
281 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
282 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
283 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
284 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
285 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
286 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
287 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
288 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
289 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
290 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
291 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
292 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
293 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
294 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
295 self.Bind(wx.EVT_MENU, self.oncloud, id = self.idcloud)
296 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
297 self.Bind(wx.EVT_MENU, self.onexporttropes, id = self.idexporttropes)
298 self.Bind(wx.EVT_MENU, self.onexportowledge, id = self.idexportowledge)
299 self.Bind(wx.EVT_MENU, self.OnMakeTgen, id=self.onmaketgen)
300 self.Bind(wx.EVT_MENU, self.OnChronoChi2, id=self.onchronochi2)
301 self.Bind(wx.EVT_MENU, self.OnChronoProp, id=self.onchronoprop)
302 #self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
303 #self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
306 menu.Append(self.popupID1, _("Associated forms"))
307 menu.Append(self.idtablex, _("Chi2 by cluster"))
308 menu.Append(self.idlexdendro, _("Chi2 by cluster on dendrogram"))
309 menu.Append(self.idchimod, _("Chi2 modalities of variable"))
310 menu_chrono = wx.Menu()
311 menu_chrono.Append(self.onchronochi2, _('Chi2'))
312 menu_chrono.Append(self.onchronoprop, _('Proportion'))
313 menu.Append(-1, _("Chronological view"), menu_chrono)
314 menu.Append(self.idwordgraph, _("Word graph"))
315 #menu.Append(self.export_classes, u"Exporter le corpus...")
316 #menu.Append(self.popupID10, u"Spécificités")
317 menu_conc = wx.Menu()
318 menu_conc.Append(self.popupID2, _("In segments of this cluster"))
319 menu_conc.Append(self.popupID3, _("In segments of this clustering"))
320 menu_conc.Append(self.popupID4, _("In all segments"))
321 menu.Append(-1, _("Concordance"), menu_conc)
322 menu.Append(self.onmaketgen, _("Make Tgen"))
323 menu_cnrtl = wx.Menu()
324 menu_cnrtl.Append(self.popupID5, _("Definition"))
325 menu_cnrtl.Append(self.popupID6, _("Etymology"))
326 menu_cnrtl.Append(self.popupID7, _("Synonymous"))
327 menu_cnrtl.Append(self.popupID8, _("Antonym"))
328 menu_cnrtl.Append(self.popupID9, _("Morphology"))
329 menu_cnrtl.Append(self.popup_proxe, _("Proxemy"))
330 menu.Append(-1, _("Tools from CNRTL (french only)"), menu_cnrtl)
331 menu.AppendSeparator()
332 menu.Append(self.popupIDgraph, _("Graph of cluster"))
333 menu.Append(self.idseg, _("Repeated segments"))
334 menu.Append(self.iducecarac, _("Typical text segments"))
335 menu.Append(self.idcloud, _("Word cloud of cluster"))
336 menu.Append(self.idexport, _('Export...'))
337 menu.Append(self.idexporttropes, _('Export for Tropes'))
338 menu.Append(self.idexportowledge, _('Exporter for Owledge'))
339 #menu.Append(self.popupID2, u"Concordancier")
340 #menu.Append(self.popupID3, "recharger")
343 elif 'tableau' in dir(self.Source):
344 if not hasattr(self, "pop1"):
345 self.pop1 = wx.NewId()
346 self.pop2 = wx.NewId()
347 self.pop3 = wx.NewId()
348 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
349 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
350 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
352 menu.Append(self.pop2, _("Chi2 by cluster"))
353 menu.Append(self.pop3, _("Chi2 modalities of variable"))
354 menu.AppendSeparator()
355 menu.Append(self.pop1, _("Graph of cluster"))
359 def oncloud(self, evt):
360 if 'corpus' in dir(self.Source):
361 corpus = self.Source.corpus
362 prof = [[self.la[i], self.lchi[i], self.lfreq[i]] for i, val in enumerate(self.la)]
363 parametres = copy(self.Source.parametres)
364 parametres['clusterprof'] = prof
365 parametres['type'] = 'clustercloud'
366 parametres['prof'] = self.Source.pathout['actprof_classe_%i.csv' % self.cl]
367 del parametres['uuid']
368 self.parent.OnClusterCloud(self.Source.corpus, parametres = parametres)
370 def onexport(self, evt) :
371 if 'corpus' in dir(self.Source):
372 corpus = self.Source.corpus
373 if self.Source.parametres['classif_mode'] != 2 :
377 corpus.export_classe(self.Source.pathout['classe_%i_export.txt' % self.cl], self.cl, uci = uci)
378 dial = wx.MessageDialog(self, self.Source.pathout['classe_%i_export.txt' % self.cl], "Export", wx.OK|wx.ICON_INFORMATION)
382 def onexporttropes(self, evt) :
383 if 'corpus' in dir(self.Source):
384 corpus = self.Source.corpus
385 if self.Source.parametres['classif_mode'] != 2 :
389 fileout = self.Source.pathout['export_tropes_classe_%i.txt' % self.cl]
390 corpus.export_tropes(fileout, self.cl, uci = uci)
392 def onexportowledge(self, evt):
393 if 'corpus' in dir(self.Source):
394 corpus = self.Source.corpus
395 if self.Source.parametres['classif_mode'] != 2 :
399 repout = self.Source.pathout['export_owledge_classe_%i' % self.cl]
400 if not os.path.exists(repout) :
402 corpus.export_owledge(repout, self.cl, uci = uci)
404 def getselectedwords(self) :
405 words = [self.getColumnText(self.GetFirstSelected(), 6)]
406 last = self.GetFirstSelected()
407 while self.GetNextSelected(last) != -1:
408 last = self.GetNextSelected(last)
409 words.append(self.getColumnText(last, 6))
412 def quest_var_mod(self, evt) :
413 word = self.getselectedwords()[0]
414 if len(word.split('_')) <= 1 :
415 dial = wx.MessageDialog(self, _("This is not a variable_modality form"), _("Problem"), wx.OK | wx.ICON_WARNING)
416 dial.CenterOnParent()
420 if 'corpus' in dir(self.Source):
421 corpus = self.Source.corpus
422 if word.startswith('-*') :
423 if self.them_mod == {} :
424 self.them_mod = self.Source.corpus.make_theme_dict()
425 var_mod = self.them_mod
427 if self.var_mod == {} :
428 self.var_mod = self.Source.corpus.make_etoiles_dict()
429 var_mod = self.var_mod
431 corpus = self.Source.tableau
432 if self.var_mod == {} :
433 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
434 var_mod = self.var_mod
435 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
436 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
440 vchistable = [line[1:] for line in chistable]
441 fchistable = [line[0] for line in chistable]
442 var = word.split('_')
443 #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
445 words = [word for word in var_mod[var[0]]]
447 dial = wx.MessageDialog(self, _("This is not a meta-data"), _("Problem"), wx.OK | wx.ICON_WARNING)
448 dial.CenterOnParent()
456 if word in fchistable :
457 tableout.append(vchistable[fchistable.index(word)])
459 BarFrame(self.Source.parent, tableout, title, kwords)
461 def OnChronoChi2(self, evt) :
462 word = self.getselectedwords()[0]
463 if len(word.split('_')) <= 1 :
464 dial = wx.MessageDialog(self, _("This is not a variable_modality form"), _("Problem"), wx.OK | wx.ICON_WARNING)
465 dial.CenterOnParent()
469 if 'corpus' in dir(self.Source):
470 corpus = self.Source.corpus
471 if word.startswith('-*') :
472 if self.them_mod == {} :
473 self.them_mod = self.Source.corpus.make_theme_dict()
474 var_mod = self.them_mod
476 if self.var_mod == {} :
477 self.var_mod = self.Source.corpus.make_etoiles_dict()
478 var_mod = self.var_mod
480 corpus = self.Source.tableau
481 if self.var_mod == {} :
482 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
483 var_mod = self.var_mod
484 var = word.split('_')
485 #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
487 words = [word for word in var_mod[var[0]]]
489 dial = wx.MessageDialog(self, _("This is not a meta-data"), _("Problem"), wx.OK | wx.ICON_WARNING)
490 dial.CenterOnParent()
495 vartoplot = var[0] + '_'
496 parametres = {'var' : vartoplot}
497 ChronoFrame(self.Source.parent, parametres, self.Source.pathout, which = 'chi2')
499 def OnChronoProp(self, evt) :
500 word = self.getselectedwords()[0]
501 if len(word.split('_')) <= 1 :
502 dial = wx.MessageDialog(self, _("This is not a variable_modality form"), _("Problem"), wx.OK | wx.ICON_WARNING)
503 dial.CenterOnParent()
507 if 'corpus' in dir(self.Source):
508 corpus = self.Source.corpus
509 if word.startswith('-*') :
510 if self.them_mod == {} :
511 self.them_mod = self.Source.corpus.make_theme_dict()
512 var_mod = self.them_mod
514 if self.var_mod == {} :
515 self.var_mod = self.Source.corpus.make_etoiles_dict()
516 var_mod = self.var_mod
518 corpus = self.Source.tableau
519 if self.var_mod == {} :
520 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
521 var_mod = self.var_mod
522 var = word.split('_')
523 #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
525 words = [word for word in var_mod[var[0]]]
527 dial = wx.MessageDialog(self, _("This is not a meta-data"), _("Problem"), wx.OK | wx.ICON_WARNING)
528 dial.CenterOnParent()
533 vartoplot = var[0] + '_'
534 parametres = {'var' : vartoplot}
535 ChronoFrame(self.Source.parent, parametres, self.Source.pathout, which = 'prop')
537 def quest_simi(self, evt) :
538 tableau = self.Source.tableau
539 tab = tableau.make_table_from_classe(self.cl, self.la)
540 pathout = ConstructPathOut(self.Source.pathout.dirout, 'simi_classe_%i' %self.cl)
541 if self.tmpchi is None :
542 self.tmpchi = os.path.join(pathout,'chi.csv')
543 with open(self.tmpchi, 'w') as f:
544 f.write('\n'.join([str(val) for val in self.lchi]))
545 self.filename = os.path.join(pathout,'mat01.csv')
546 tableau.printtable(self.filename, tab)
548 paramsimi = {'coeff' : 0,
571 'cola' : (200,200,200),
581 'tmpchi': self.tmpchi,
586 tableau = copymatrix(tableau)
588 tableau.lchi = self.lchi
589 #tableau.parametres['fromprof'] = True
590 for i, val in enumerate(self.la) :
591 act[val] = [self.lfreq[i]]
592 tableau.chi[val] = [self.lchi[i]]
593 paramsimi['listactives'] = copy(self.la)
594 paramsimi['actives'] = copy(act)
595 paramsimi['pathout'] = pathout
596 self.parent.SimiCluster(parametres = paramsimi, fromprof = ffr(self.filename), tableau = tableau)
598 def onwordgraph(self, evt):
599 word = self.getColumnText(self.GetFirstSelected(), 6)
600 if self.tmpchi is None :
601 self.tmpchi = os.path.join(self.Source.parametres['pathout'],'chi_%i.csv' % self.cl)
602 with open(self.tmpchi, 'w') as f:
603 f.write('\n'.join([str(val) for val in self.lchi]))
604 index = self.la.index(word)
605 parametres = {'type' : 'clustersimitxt',
606 'pathout' : self.Source.parametres['pathout'],
608 'lem' : self.Source.parametres['lem'],
609 'tmpchi' : self.tmpchi}
611 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.lfreq, self.lchi, self.cl - 1, parametres = parametres, dlg = progressbar(self.ira, 4))
615 def on_graph(self, evt):
616 if self.tmpchi is None :
617 self.tmpchi = os.path.join(self.Source.parametres['pathout'],'chi_%i.csv' % self.cl)
618 with open(self.tmpchi, 'w') as f:
619 f.write('\n'.join([str(val) for val in self.lchi]))
620 parametres = {'type' : 'clustersimitxt',
621 'pathout' : self.Source.parametres['pathout'],
622 'lem' : self.Source.parametres['lem'],
623 'tmpchi' : self.tmpchi}
624 self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.lfreq, self.lchi, self.cl - 1, parametres = parametres, dlg = progressbar(self.ira, 4))
626 def on_segments(self,evt) :
627 dlg = progressbar(self, 2)
628 corpus = self.Source.corpus
629 uces = corpus.lc[self.cl-1]
630 if self.Source.parametres['classif_mode'] != 2 :
635 dlg.Update(1, 'Segments...')
636 for i in range(2,10) :
637 li = corpus.find_segments_in_classe(uces, i, 1000, uci = uci)
642 l.sort(reverse = True)
644 dlg.Update(2, 'Tri...')
645 for i, line in enumerate(l) :
646 d[i] = [line[1],line[0], line[2]]
648 para={'dico': d,'fline':first}
650 win = wliste(self, -1, ' - '.join([_("Repeated segments"), "Classe %i" % self.cl]), d, first, size=(600, 500))
653 def on_uce_carac(self,evt) :
654 dial = PrefUCECarac(self, self.parent)
655 dial.CenterOnParent()
656 if dial.ShowModal() == wx.ID_OK :
657 limite = dial.spin_eff.GetValue()
658 atype = dial.radio_type.GetSelection()
659 dlg = progressbar(self.ira,maxi = 4)
660 corpus = self.Source.corpus
661 uces = corpus.lc[self.cl-1]
662 if self.Source.parametres['classif_mode'] != 2 :
666 tab = corpus.make_table_with_classe(uces, self.la, uci = uci)
668 dlg.Update(2, 'score...')
670 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
672 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]
673 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
675 ntab2.sort(reverse = True)
676 ntab2 = ntab2[:limite]
677 nuces = [val[1] for val in ntab2]
678 dlg.Update(3, 'concordancier...')
679 ucis_txt, ucestxt = doconcorde(corpus, nuces, self.la, uci = uci, fontsize = self.ira.fontsize)
680 items = dict([[i, '<br>'.join([ucis_txt[i], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table><br>' % ntab2[i][0], ucestxt[i]])] for i, uce in enumerate(nuces)])
682 win = message(self, items, ' - '.join([_("Typical text segments"), "Classe %i" % self.cl]), (750, 600), uceids = nuces)
683 #win.SetWindowStyle(wx.STAY_ON_TOP)
684 #win.html = '<html>\n' + '<br>'.join(['<br>'.join([ucis_txt[i], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table>' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
685 #win.HtmlPage.SetPage(win.html)
688 def on_tablex(self, evt):
689 if 'corpus' in dir(self.Source):
690 corpus = self.Source.corpus
692 corpus = self.Source.tableau
693 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
694 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
698 vchistable = [line[1:] for line in chistable]
699 fchistable = [line[0] for line in chistable]
700 words = self.getselectedwords()
701 tableout = [vchistable[fchistable.index(self.getword(word))] for word in words]
702 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
705 BarFrame(self.Source.parent, tableout, title, words)
707 def onlexdendro(self, evt):
708 if 'corpus' in dir(self.Source):
709 corpus = self.Source.corpus
711 corpus = self.Source.tableau
712 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
713 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
717 vchistable = [line[1:] for line in chistable]
718 fchistable = [line[0] for line in chistable]
719 words = self.getselectedwords()
720 tableout = [vchistable[fchistable.index(self.getword(word))] for word in words]
721 BarFrame(self.Source.parent, tableout, title, words, tree = self.Source.pathout['Rdendro'])
723 def getword(self, word) :
724 if self.translation :
725 return self.lems[word]
729 def make_concord(self, uces, title, color = 'red') :
730 corpus = self.Source.corpus
731 ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
732 last = self.GetFirstSelected()
733 while self.GetNextSelected(last) != -1:
734 last = self.GetNextSelected(last)
735 ListWord.append(self.getColumnText(last, 6))
737 ListWord = [self.getword(word) for word in ListWord]
738 if self.Source.parametres['classif_mode'] != 2 :
739 for word in ListWord :
741 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
743 for word in ListWord :
744 ucef += list(set(corpus.getlemucis(word)).intersection(uces))
746 ucis_txt, ucestxt = doconcorde(corpus, ucef, ListWord, uci = uci)
747 items = dict([[i, '<br><br>'.join([ucis_txt[i], ucestxt[i]])] for i in range(0,len(ucestxt))])
748 win = message(self, items, title, (800, 500), uceids = ucef)
751 def OnPopupTwo(self, event):
752 if 'corpus' in dir(self.Source) :
753 corpus = self.Source.corpus
754 uces = corpus.lc[self.cl-1]
755 win = self.make_concord(uces, ' - '.join([_("Concordance"), "Classe %i" % self.cl]))
758 def OnPopupThree(self, event):
759 corpus = self.Source.corpus
760 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
761 win = self.make_concord(uces, ' - '.join([_("Concordance"), _("Segments of this clustering")]))
764 def OnPopupFour(self, event):
765 corpus = self.Source.corpus
766 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
767 win = self.make_concord(uces, ' - '.join([_("Concordance"), _("All segments")]))
770 def OnPopupFive(self, event):
771 word = self.getColumnText(self.GetFirstSelected(), 6)
772 lk = "http://www.cnrtl.fr/definition/" + word
775 def OnPopupSix(self, event):
776 word = self.getColumnText(self.GetFirstSelected(), 6)
777 lk = "http://www.cnrtl.fr/etymologie/" + word
780 def OnPopupSeven(self, event):
781 word = self.getColumnText(self.GetFirstSelected(), 6)
782 lk = "http://www.cnrtl.fr/synonymie/" + word
785 def OnPopupHeight(self, event):
786 word = self.getColumnText(self.GetFirstSelected(), 6)
787 lk = "http://www.cnrtl.fr/antonymie/" + word
790 def OnPopupNine(self, event):
791 word = self.getColumnText(self.GetFirstSelected(), 6)
792 lk = "http://www.cnrtl.fr/morphologie/" + word
795 def onproxe(self, evt) :
796 word = self.getColumnText(self.GetFirstSelected(), 6)
797 lk = "http://www.cnrtl.fr/proxemie/" + word
800 def OnPopupOne(self, event):
801 corpus = self.Source.corpus
802 #print 'ATTENTION PRINT ET TABLE'
803 #corpus.make_et_table()
804 word = self.getColumnText(self.GetFirstSelected(), 6)
805 word = self.getword(word)
806 lems = corpus.getlems()
807 uces = corpus.lc[self.cl-1]
809 #FIXME : donner aussi eff reel a la place de nb uce
810 for forme in lems[word].formes :
811 if self.Source.parametres['classif_mode'] != 2 :
812 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
814 ucef = list(set(corpus.getworducis(forme)).intersection(uces))
815 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
818 rep.append([corpus.getforme(forme).forme, nb])
819 rep.sort(key = itemgetter(1), reverse = True)
820 #win = message(self, u"Formes associées", wx.Size(300, 200))
821 items = dict([[i, '\t:\t'.join([str(val) for val in forme])] for i, forme in enumerate(rep)])
822 win = message(self, items, _("Associated forms"), (300, 200))
823 #win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
824 #win.HtmlPage.SetPage(win.html)
827 def OnMakeTgen(self, evt):
828 self.parent.tree.OnTgenEditor(self.getselectedwords())
831 class wliste(wx.Frame):
833 def __init__(self, parent, id, title, d, fline, size=(600, 500)):
834 wx.Frame.__init__(self, parent, id)
835 self.liste = ListForSpec(self, parent, d, fline[1:], menu = False)
836 self.button_1 = wx.Button(self, -1, _("Close"))
837 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
838 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
841 def __do_layout(self):
842 sizer_1 = wx.BoxSizer(wx.VERTICAL)
843 sizer_2 = wx.BoxSizer(wx.VERTICAL)
844 sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
845 sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
846 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
847 self.SetAutoLayout(True)
848 self.SetSizer(sizer_1)
851 def OnCloseMe(self, event):
854 def OnCloseWindow(self, event):