1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
6 from chemins import ConstructPathOut, StatTxtPathOut
7 #from corpus import Corpus
8 from analysetxt import AnalyseText
13 from functions import exec_rcode, progressbar, check_Rresult, CreateIraFile, print_liste, treat_var_mod, write_tab, DoConf
14 from dialog import OptLexi, StatDialog #LexDialog
15 from openanalyse import OpenAnalyse
17 from ConfigParser import RawConfigParser
18 from guifunct import getPage, getCorpus
19 from time import sleep
22 log = logging.getLogger('iramuteq.spec')
24 class Lexico(AnalyseText) :
26 pathout = self.pathout.dirout
27 self.dictpathout = StatTxtPathOut(pathout)
28 self.parametres['ira'] = self.dictpathout['ira']
42 """ % (self.parent.RscriptsPath['chdfunct'], self.parent.RscriptsPath['Rgraph'])
44 dmf<-read.csv2("%s",row.names=1)
45 """ % self.dictpathout['tableafcm']
47 dmt<-read.csv2("%s",row.names=1)
48 """ % self.dictpathout['tabletypem']
49 if self.parametres['indice'] == 'hypergeo' :
51 outf <- make.spec.hypergeo(dmf)
52 outt <- make.spec.hypergeo(dmt)
54 elif self.parametres['indice'] == 'chi2' :
63 write.csv2(specf,file="%s")
64 """ % self.dictpathout['tablespecf']
66 write.csv2(spect,file="%s")
67 """ % self.dictpathout['tablespect']
69 write.csv2(outf[[3]],file="%s")
70 """ % self.dictpathout['eff_relatif_forme']
72 write.csv2(outt[[3]],file="%s")
73 """ % self.dictpathout['eff_relatif_type']
74 if self.parametres['clnb'] > 2 :
81 dmfp<-dmf[-which(slf==0),]
82 specfp <- specf[-which(slf==0),]
87 afcf <- ca(dmfp, nd = nd)
90 dmtp<-dmt[-which(slt==0),]
91 spectp <- spect[-which(slt==0),]
96 afct <- ca(dmtp, nd = nd)
97 open_file_graph("%s", widt = 1000, height=1000)
98 plot(afcf, what=c('all','none'), labels=c(1,1))
99 open_file_graph("%s", widt = 1000, height=1000)
100 plot(afcf, what=c('none','all'), labels=c(1,1))
101 open_file_graph("%s", widt = 1000, height=1000)
102 plot(afct, what=c('all','none'), labels=c(1,1))
103 open_file_graph("%s", widt = 1000, height=1000)
104 plot(afct, what=c('none','all'), labels=c(1,1))
105 afcf <- AddCorrelationOk(afcf)
106 afct <- AddCorrelationOk(afct)
107 afcf <- summary.ca.dm(afcf)
108 afct <- summary.ca.dm(afct)
109 afcf_table <- create_afc_table(afcf)
110 afct_table <- create_afc_table(afct)
111 write.csv2(afcf_table$facteur, file = "%s")
112 write.csv2(afcf_table$colonne, file = "%s")
113 write.csv2(afcf_table$ligne, file = "%s")
114 write.csv2(afct_table$facteur, file = "%s")
115 write.csv2(afct_table$colonne, file = "%s")
116 write.csv2(afct_table$ligne, file = "%s")
120 """ % (self.dictpathout['afcf_row'], self.dictpathout['afcf_col'], self.dictpathout['afct_row'], self.dictpathout['afct_col'], self.dictpathout['afcf_facteur_csv'], self.dictpathout['afcf_col_csv'], self.dictpathout['afcf_row_csv'], self.dictpathout['afct_facteur_csv'], self.dictpathout['afct_col_csv'], self.dictpathout['afct_row_csv'])
124 """ % self.dictpathout['RData']
125 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
126 tmpscript = open(tmpfile, 'w')
129 self.doR(tmpfile, dlg = self.dlg, message = 'R...')
131 def preferences(self) :
132 listet = self.corpus.make_etoiles()
134 variables = treat_var_mod(listet)
135 var = [v for v in variables]
136 dial = OptLexi(self.parent)
140 dial.list_box_1.Append(et)
141 dial.CenterOnParent()
142 self.dialok = dial.ShowModal()
143 if self.dialok == wx.ID_OK :
144 if dial.choice.GetSelection() == 1 :
145 ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
147 ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
149 self.parametres['mineff'] = dial.spin.GetValue()
150 if dial.choice_indice.GetSelection() == 0 :
151 self.parametres['indice'] = 'hypergeo'
153 self.parametres['indice'] = 'chi2'
154 self.parametres['clnb'] = len(ListEt)
156 return self.parametres
161 def make_lexico(self) :
162 mineff = self.parametres['mineff']
163 #dlg = progressbar(self, maxi = 3)
164 tabout = self.corpus.make_lexitable(mineff, self.listet)
165 #log.warning('Fmax a 200')
166 #Fmax = [line for line in tabout[1:] if sum(line[1:]) > 199]
167 #formesmax = [line[0] for line in Fmax]
168 #Fmax = [line[1:] for line in Fmax]
169 #summax = [sum(col) for col in zip(*Fmax)]
170 #tabout.append(['Fmax'] + summax)
171 #tabout = [line for line in tabout if line[0] not in formesmax]
172 #log.warning('ATTENTION : hapax par etoile')
173 #tabout.append(['hapax'] + self.corpus.gethapaxbyet(self.listet))
174 write_tab(tabout, self.dictpathout['tableafcm'])
176 #log.warning('ATTENTION : gethapaxuces')
177 #self.corpus.gethapaxuces()
179 tabout = self.corpus.make_efftype_from_etoiles(self.listet)
180 write_tab(tabout, self.dictpathout['tabletypem'])
182 self.dlg.Update(2, u'R...')
185 self.dlg.Update(3, u'Chargement...')
186 afcf_graph_list = [[os.path.basename(self.dictpathout['afcf_row']), u'lignes'],\
187 [os.path.basename(self.dictpathout['afcf_col']), u'colonnes']]
188 afct_graph_list = [[os.path.basename(self.dictpathout['afct_row']), u'lignes'],\
189 [os.path.basename(self.dictpathout['afct_col']), u'colonnes']]
190 print_liste(self.dictpathout['liste_graph_afcf'],afcf_graph_list)
191 print_liste(self.dictpathout['liste_graph_afct'],afct_graph_list)
192 #DoConf().makeoptions(['spec'],[self.parametres], self.dictpathout['ira'])