From 432118f2ac3d2f8234c388e77d0fb9e14234750f Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 10 Feb 2013 13:55:44 +0100 Subject: [PATCH] antipro pour matrix --- ProfList.py | 12 +++++++++--- corpus.py | 42 ++++++++++++++++++++++++++++++++---------- guifunct.py | 2 +- tree.py | 8 +++++++- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/ProfList.py b/ProfList.py index 6d007a7..063a275 100644 --- a/ProfList.py +++ b/ProfList.py @@ -291,7 +291,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph) self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe) self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro) - #self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport) + self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport) # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes) # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) @@ -323,7 +323,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col menu.Append(self.popupIDgraph, u"Graphe de la classe") menu.Append(self.idseg, u"Segments répétés") menu.Append(self.iducecarac, u"UCE caractéristiques") - #menu.Append(self.idexport, 'Partitionner...') + menu.Append(self.idexport, 'Exporter...') #menu.Append(self.popupID2, u"Concordancier") # menu.Append(self.popupID3, "recharger") @@ -349,7 +349,13 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col def onexport(self, evt) : if 'corpus' in dir(self.Source): corpus = self.Source.corpus - ClasseCHD(self.parent, corpus, self.cl) + corpus.export_classe(self.Source.pathout['classe_%i_export.txt' % self.cl], self.cl) + dial = wx.MessageDialog(self, self.Source.pathout['classe_%i_export.txt' % self.cl], u"Export", wx.ID_OK|wx.ICON_INFORMATION) + dial.ShowModal() + dial.Destroy() + #if 'corpus' in dir(self.Source): + # corpus = self.Source.corpus + #ClasseCHD(self.parent, corpus, self.cl) def getselectedwords(self) : words = [self.getColumnText(self.GetFirstSelected(), 6)] diff --git a/corpus.py b/corpus.py index 51061fb..76ebb66 100644 --- a/corpus.py +++ b/corpus.py @@ -433,6 +433,18 @@ class Corpus : f.write(etline.encode(self.parametres['syscoding']) + '\n') f.write(guce.encode(self.parametres['syscoding']) + '\n\n') + def export_classe(self, outf, classe, lem = False) : + sts = self.lc[classe] + res = self.getconcorde(sts) + self.make_iduces() + with open(outf, 'w') as f : + for uce in res : + guce = uce[1] + f.write(' '.join(self.ucis[self.iduces[uce[0]].uci].etoiles).encode(self.parametres['syscoding']) + '\n') + if lem : + guce = ' '.join([self.formes[forme].lem for forme in guce.split()]) + f.write(guce.encode(self.parametres['syscoding']) + '\n\n') + def make_and_write_sparse_matrix_from_uces(self, actives, outfile, listuce = False) : log.info('make_and_write_sparse_matrix_from_uces %s' % outfile) nbl = 0 @@ -707,27 +719,37 @@ class Corpus : self.lc0 = self.lc.pop(0) #return ucecl - def get_stat_by_cluster(self, outf) : + def get_stat_by_cluster(self, outf, lclasses = None) : log.info('get_stat_by_cluster') + if lclasses is None : + lclasses = self.lc t1 = time() - occurrences = dict([[i + 1, 0] for i in range(len(self.lc))]) - formescl = dict([[i + 1, 0] for i in range(len(self.lc))]) - hapaxcl = dict([[i + 1, 0] for i in range(len(self.lc))]) - lenclasses = dict([[i+1,len(cl)] for i, cl in enumerate(self.lc)]) - sets = [set(cl) for cl in self.lc] + occurrences = dict([[i + 1, 0] for i in range(len(lclasses))]) + formescl = dict([[i + 1, 0] for i in range(len(lclasses))]) + hapaxcl = dict([[i + 1, 0] for i in range(len(lclasses))]) + lenclasses = dict([[i+1,len(cl)] for i, cl in enumerate(lclasses)]) + sets = [set(cl) for cl in lclasses] for forme in self.formes : formeuceeff = self.getformeuceseff(forme) - for i, classe in enumerate(self.lc) : + for i, classe in enumerate(lclasses) : concern = sets[i].intersection(formeuceeff.keys()) if len(concern) : occurrences[i+1] += sum([formeuceeff[uce] for uce in concern]) formescl[i+1] += 1 if self.formes[forme].freq == 1 : hapaxcl[i+1] += 1 - toprint = '\n'.join([';'.join([`i`, `occurrences[i]`, `formescl[i]`, `hapaxcl[i]`, `lenclasses[i]`, `float(hapaxcl[i])/float(formescl[i])`]) for i in occurrences]) - with open(outf, 'w') as f : - f.write(toprint) log.info('%f' % (time() - t1)) + if outf is not None : + toprint = '\n'.join([';'.join([`i`, `occurrences[i]`, `formescl[i]`, `hapaxcl[i]`, `lenclasses[i]`, `float(hapaxcl[i])/float(formescl[i])`]) for i in occurrences]) + with open(outf, 'w') as f : + f.write(toprint) + else : + return [[`occurrences[i]`, `formescl[i]`, `hapaxcl[i]`, `lenclasses[i]`, `float(hapaxcl[i])/float(formescl[i])`] for i in occurrences] + + def get_stat_by_et(self, outf, etoiles) : + lclasses = [self.getucesfrometoile(etoile) for etoile in etoiles] + stats = self.get_stat_by_cluster(None, lclasses) + stats = [[etoiles[i]] + val for i, val in enumerate(stats)] def gethapaxbyet(self, etoiles) : hapaxuces = [self.getlemuces(forme)[0] for forme in self.lems if self.lems[forme].freq == 1] diff --git a/guifunct.py b/guifunct.py index 8ee4879..b16c58c 100644 --- a/guifunct.py +++ b/guifunct.py @@ -14,7 +14,7 @@ from functions import treat_var_mod def OnOpen(self, type): if type == "Data": - wildcard = u"Fichiers supportés|*.ods;*.xls;*.csv;*.txt|Openoffice Clac|*.ods|Fichier excel|*.xls|Fichier csv|*.csv|Fichier texte|*.txt|Tous les fichiers|*" + wildcard = u"Fichiers supportés|*.ods;*.xls;*.csv;*.txt|Openoffice Calc|*.ods|Excel 97/2000/XP/2003|*.xls|Fichier csv|*.csv|Fichier texte|*.txt|Tous les fichiers|*" elif type == "Texte": wildcard = "Fichier texte|*.txt|Tous les fichiers|*" elif type == "Analyse": diff --git a/tree.py b/tree.py index c3f0ba6..6c28c09 100644 --- a/tree.py +++ b/tree.py @@ -352,7 +352,7 @@ class LeftTree(CT.CustomTreeCtrl): self.Bind(wx.EVT_MENU, self.OnSpec, spec) self.Bind(wx.EVT_MENU, self.OnSimiTxt, simi) self.Bind(wx.EVT_MENU, self.OnWordCloud, wdc) - elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened : + elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened : openmenu = wx.Menu() antipro = openmenu.Append(wx.ID_ANY, u"antiprofils") menu.AppendMenu(wx.ID_ANY, u"Ouvrir...", openmenu) @@ -379,6 +379,12 @@ class LeftTree(CT.CustomTreeCtrl): self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary) self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems) menu.AppendSeparator() + elif pydata.get('type', False) == 'gnepamatrix' and pydata['uuid'] in self.parent.history.opened : + openmenu = wx.Menu() + antipro = openmenu.Append(wx.ID_ANY, u"antiprofils") + menu.AppendMenu(wx.ID_ANY, u"Ouvrir...", openmenu) + self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro) + itemdelete = menu.Append(wx.ID_ANY, "Supprimer de l'historique") if item == self.GetRootItem(): -- 2.7.4