From ae0a736d9598a3483ccf2b35e3b61d365cf77db4 Mon Sep 17 00:00:00 2001 From: Pierre Ratinaud Date: Thu, 20 Nov 2014 00:17:20 +0100 Subject: [PATCH] multiple frequencies on matrix --- functions.py | 1 + iramuteq.py | 8 +++++++- openanalyse.py | 2 +- tabfrequence.py | 43 ++++++++++++++++++++++++++++++++++++++++++- tree.py | 1 + 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/functions.py b/functions.py index 862ea5f..f2579f1 100644 --- a/functions.py +++ b/functions.py @@ -493,6 +493,7 @@ exceptions = {'paragrapheOT' : u"Un problème de formatage (présence d'un marqu 'EmptyText' : u"Texte vide (probablement un problème de formatage du corpus). Le problème est apparu à la ligne ", 'CorpusEncoding' : u"Problème d'encodage.", 'TextBeforeTextMark' : u"Problème de formatage : du texte avant le premier marqueur de texte (****). Le problème est survenu à la ligne ", + 'MissingAnalyse' : u'Aucun fichier à cet emplacement :\n', } def BugReport(parent, error = None): diff --git a/iramuteq.py b/iramuteq.py index 1ce343d..e3ded49 100644 --- a/iramuteq.py +++ b/iramuteq.py @@ -38,7 +38,7 @@ from checkversion import NewVersion from guifunct import * from tableau import Tableau from dialog import PrefDialog, CorpusPref -from tabfrequence import Frequences +from tabfrequence import Frequences, FreqMultiple from tabchi2 import ChiSquare #from tabstudent import MakeStudent from tabchddist import ChdCluster @@ -95,6 +95,7 @@ ID_HTMLcontent = wx.NewId() ID_SimiTxt = wx.NewId() ID_proto = wx.NewId() ID_ImportTXM = wx.NewId() +ID_FreqMulti = wx.NewId() ########################################################## #elements de configuration ########################################################## @@ -261,6 +262,7 @@ class IraFrame(wx.Frame): #view_menu.AppendSeparator() matrix_menu = wx.Menu() matrix_menu.Append(ID_Freq, _(u"Frequencies").decode('utf8')) + matrix_menu.Append(ID_FreqMulti, _(u'Multiple frequencies').decode('utf8')) matrix_menu.Append(ID_Chi2, _(u"Chi2").decode('utf8')) #matrix_menu.Append(ID_Student, u"t de Student") menu_classif = wx.Menu() @@ -398,6 +400,7 @@ class IraFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.ExtractTools, extractmod) self.Bind(wx.EVT_MENU, self.ExtractTools, extractthem) self.Bind(wx.EVT_MENU, self.OnFreq, id=ID_Freq) + self.Bind(wx.EVT_MENU, self.OnFreqMulti, id=ID_FreqMulti) self.Bind(wx.EVT_MENU, self.OnChi2, id=ID_Chi2) self.Bind(wx.EVT_MENU, self.OnStudent, id=ID_Student) self.Bind(wx.EVT_MENU, self.OnCHDSIM, id=ID_CHDSIM) @@ -789,6 +792,9 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis.""" def OnFreq(self, event, matrix = None): self.analyse_matrix(Frequences, analyse_type = 'freq', matrix = matrix, dlgnb = 3) + + def OnFreqMulti(self, event, matrix = None): + self.analyse_matrix(FreqMultiple, analyse_type = 'freqmulti', matrix = matrix, dlgnb = 3) def OnChi2(self, event, matrix = None): self.analyse_matrix(ChiSquare, matrix = matrix, analyse_type = 'chi2', dlgnb = 3) diff --git a/openanalyse.py b/openanalyse.py index 41a5978..899a0bb 100644 --- a/openanalyse.py +++ b/openanalyse.py @@ -168,7 +168,7 @@ class OpenAnalyse(): ProtoLayout(self.parent, corpus, self.conf) elif self.conf['type'] == 'matrix' : MatLayout(self.parent, corpus) - elif self.conf['type'] == 'freq' : + elif self.conf['type'] == 'freq' or self.conf['type'] == 'freqmulti': FreqLayout(self.parent, corpus, self.conf) elif self.conf['type'] == 'chi2' : Chi2Layout(self.parent, corpus, self.conf) diff --git a/tabfrequence.py b/tabfrequence.py index 328e610..376c8bf 100644 --- a/tabfrequence.py +++ b/tabfrequence.py @@ -13,7 +13,8 @@ from time import sleep from analysematrix import AnalyseMatrix from functions import exec_rcode, check_Rresult from dialog import FreqDialog -from PrintRScript import PrintRScript +from PrintRScript import PrintRScript, FreqMultiScript +from operator import itemgetter class Frequences(AnalyseMatrix) : def doparametres(self, dlg=None) : @@ -159,4 +160,44 @@ class Frequences(AnalyseMatrix) : with open(fileout, 'w') as f : f.write(pretexte + texte) #return fileout + +class FreqMultiple(Frequences): + def doanalyse(self): + select = self.parametres['colsel'] + freq = self.tableau.countmultiple(select) + tot = sum([freq[forme][0] for forme in freq]) + freq = [[forme, freq[forme][0], `round((float(freq[forme][0])/tot)*100, 2)`,`len(list(set(freq[forme][1])))`, `round((float(len(list(set(freq[forme][1]))))/self.tableau.rownb)*100,2)`] for forme in freq] + freq = sorted(freq, key=itemgetter(1), reverse=True) + freq = [[line[0], `line[1]`, line[2], line[3], line[4]] for line in freq] + freq.insert(0, [u'mod', 'freq', 'percent of total', 'row number', 'percent of rows']) + self.freq = freq + with open(self.pathout['frequences.csv'], 'w') as f : + f.write('\n'.join(['\t'.join(line) for line in freq])) + self.rscript = FreqMultiScript(self) + self.rscript.make_script() + self.doR(self.rscript.scriptout) + self.dolayout() + + def dolayout(self): + pretexte = u''' + + \n

Fréquences

+
+ ''' % self.parent.SysEncoding + txt = """ + \n' + txt += '
\n +
+ """ + txt += '
'.join([''.join(line) for line in self.freq]) + '
graphgraph
' % (os.path.basename(self.pathout['barplotfreq.png']), os.path.basename(self.pathout['barplotrow.png'])) + txt += "\n" + with open(self.pathout['resultats.html'], 'w') as f : + f.write(pretexte + txt) + + + + + + + \ No newline at end of file diff --git a/tree.py b/tree.py index 5dd8365..532457f 100644 --- a/tree.py +++ b/tree.py @@ -123,6 +123,7 @@ class LeftTree(CT.CustomTreeCtrl): imgmatroot = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matroot.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['matrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['freq'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'frequences.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) + self.ild['freqmulti'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'frequences.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['chi2'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'chi2.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['reinertmatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'reinertmatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['simimatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) -- 2.7.4