From cde1ca4b584c2fc29c45cf2e03856edff12a57d8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 2 Feb 2013 19:50:36 +0100 Subject: [PATCH] export dictionary --- corpus.py | 16 ++++++++++++++++ layout.py | 13 +++++++------ textwordcloud.py | 1 + tree.py | 27 +++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/corpus.py b/corpus.py index 3864812..51061fb 100644 --- a/corpus.py +++ b/corpus.py @@ -786,6 +786,22 @@ class Corpus : with open('/tmp/testhapxuce.html','w') as f : f.write(txt) + def export_dictionary(self, fileout, syscoding) : + listformes = [[self.formes[forme].freq, forme, self.formes[forme].lem, self.formes[forme].gram] for forme in self.formes] + listformes.sort(reverse = True) + listformes = [forme[1:] + [`forme[0]`] for forme in listformes] + with open(fileout, 'w') as f : + f.write('\n'.join(['\t'.join(forme) for forme in listformes]).encode(syscoding)) + + def export_lems(self, fileout, syscoding) : + self.make_idformes() + listlem = [[lem, '\t'.join(['\t'.join([self.idformes[forme].forme, `self.lems[lem].formes[forme]`]) for forme in self.lems[lem].formes])] for lem in self.lems] + listlem.sort() + with open(fileout, 'w') as f : + f.write('\n'.join(['\t'.join(lem) for lem in listlem]).encode(syscoding)) + + + class MakeUciStat : def __init__(self, corpus) : diff --git a/layout.py b/layout.py index 3b74fdf..550e73e 100644 --- a/layout.py +++ b/layout.py @@ -45,7 +45,7 @@ class GraphPanelAfc(wx.Panel): self.coding = coding self.itempath = itempath self.parent = self.GetParent()#parent - self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier")) + self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial")) self.labels = [] self.listimg = [] self.buts = [] @@ -251,7 +251,7 @@ class GraphPanel(wx.ScrolledWindow): self.Dict = dico self.txt = txt self.parent = parent - self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD, 0, "courier")) + self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial")) self.labels = [] self.listimg = [] self.dirout = os.path.dirname(self.Dict['ira']) @@ -655,20 +655,21 @@ class StatLayout: self.read_result() self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition) self.TabStat.parametres = parametres + self.TabStat.corpus = corpus + self.TabStat.pathout = self.pathout # CHD = GraphPanel(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext) # panel.TabChdSim.AddPage(CHD,'CHD') #self.TabStatTot = wx.TextCtrl(self.TabStat, -1, style=wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2) list_graph = [['zipf.png', 'zipf']] self.TabStatTot = GraphPanel(ira.nb, self.pathout, list_graph, self.result['glob']) - #self.TabStatTot.write(self.result['glob']) self.TabStat.AddPage(self.TabStatTot, 'global') for item in self.result: if item != 'glob': datam = [['forme', 'nb']] self.ListPan = ListPanel(ira, self, self.result[item]) - self.TabStat.AddPage(self.ListPan, item) - ira.nb.AddPage(self.TabStat, 'Stat') + self.TabStat.AddPage(self.ListPan, ' '.join(item.split('_'))) + ira.nb.AddPage(self.TabStat, '%s' % parametres['name']) ira.nb.SetSelection(ira.nb.GetPageCount() - 1) ira.ShowAPane("Tab_content") @@ -908,7 +909,7 @@ class WordCloudLayout(DefaultTextLayout): self.Tab.AddPage(self.TabStatTot, 'Nuage') self.Tab.corpus = self.corpus self.Tab.parametres = self.parametres - self.ira.nb.AddPage(self.Tab, 'WordCloud %s' % self.parametres.get('corpus_name','corpus_name')) + self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name']) self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1) self.ira.ShowAPane("Tab_content") diff --git a/textwordcloud.py b/textwordcloud.py index 8022af6..4fffba0 100644 --- a/textwordcloud.py +++ b/textwordcloud.py @@ -58,6 +58,7 @@ class WordCloud(AnalyseText): while os.path.exists(outgraph + str(nb) + '.png') : nb += 1 self.parametres['graphout'] = outgraph + str(nb) + '.png' + dial.Destroy() def make_wordcloud(self) : diff --git a/tree.py b/tree.py index 07576de..061c74c 100644 --- a/tree.py +++ b/tree.py @@ -364,9 +364,7 @@ class LeftTree(CT.CustomTreeCtrl): navig = menu.Append(wx.ID_ANY, u"Outil de navigation") statclasse = menu.Append(wx.ID_ANY, u"Statistiques par classe") rapport = menu.Append(wx.ID_ANY, u"Rapport") - menu.AppendSeparator() - self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro) self.Bind(wx.EVT_MENU, self.OnProfSR, profsr) self.Bind(wx.EVT_MENU, self.OnProfGram, profgram) @@ -375,7 +373,12 @@ class LeftTree(CT.CustomTreeCtrl): self.Bind(wx.EVT_MENU, self.OnNavig, navig) self.Bind(wx.EVT_MENU, self.StatClasse, statclasse) self.Bind(wx.EVT_MENU, self.OnRapport, rapport) - + elif pydata.get('type', False) == 'stat' and pydata['uuid'] in self.parent.history.opened : + export_dictionary = menu.Append(wx.ID_ANY, u"Exporter le dictionnaire") + export_lems = menu.Append(wx.ID_ANY, u"Exporter le dictionnaire des lems") + self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary) + self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems) + menu.AppendSeparator() itemdelete = menu.Append(wx.ID_ANY, "Supprimer de l'historique") if item == self.GetRootItem(): @@ -522,6 +525,22 @@ class LeftTree(CT.CustomTreeCtrl): else : dial.Destroy() + def OnExportDictionary(self, evt) : + corpus = self.page.corpus + corpus.export_dictionary(self.page.pathout['dictionary.csv'], self.parent.syscoding) + log.info('export dictionary %s' % self.page.pathout['dictionary.csv']) + dial = wx.MessageDialog(self.parent, self.page.pathout['dictionary.csv'], 'Export', wx.OK) + dial.ShowModal() + dial.Destroy() + + def OnExportLems(self, evt) : + corpus = self.page.corpus + corpus.export_lems(self.page.pathout['lemmes.csv'], self.parent.syscoding) + log.info('export lemmes %s' % self.page.pathout['lemmes.csv']) + dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK) + dial.ShowModal() + dial.Destroy() + def OnItemBackground(self, event): colourdata = wx.ColourData() @@ -644,7 +663,7 @@ class LeftTree(CT.CustomTreeCtrl): def OnItemDelete(self, event): strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?" - dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_QUESTION) + dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.YES | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_QUESTION) if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]: dlg.Destroy() -- 2.7.4