1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
6 from chemins import ConstructPathOut, StatTxtPathOut, PathOut, ffr
7 #from corpus import Corpus
8 from analysetxt import AnalyseText
12 #from listlex import *
13 from functions import exec_rcode, progressbar, check_Rresult, CreateIraFile, print_liste, treat_var_mod, write_tab, DoConf, TGen
14 from dialog import OptLexi#, StatDialog
15 #from openanalyse import OpenAnalyse
17 #from ConfigParser import RawConfigParser
18 #from guifunct import getPage, getCorpus
19 from PrintRScript import TgenSpecScript
20 from time import sleep
23 log = logging.getLogger('iramuteq.spec')
25 class Lexico(AnalyseText) :
27 pathout = self.pathout.dirout
28 self.dictpathout = StatTxtPathOut(pathout)
29 self.parametres['ira'] = self.dictpathout['ira']
43 """ % (ffr(self.parent.RscriptsPath['chdfunct']), ffr(self.parent.RscriptsPath['Rgraph']))
45 dmf<-read.csv2("%s",row.names=1)
46 """ % ffr(self.dictpathout['tableafcm'])
48 dmt<-read.csv2("%s",row.names=1)
49 """ % ffr(self.dictpathout['tabletypem'])
52 """ % self.parametres['indice']
53 if self.parametres['indice'] == 'hypergeo' :
55 outf <- make.spec.hypergeo(dmf)
56 outt <- make.spec.hypergeo(dmt)
58 elif self.parametres['indice'] == 'chi2' :
64 if (indice == 'hypergeo') {
66 } else if (indice == 'chi2') {
69 banal <- apply(abs(outf[[1]]), 1, max)
70 banal <- which(banal < banseuil)
71 banalfreq <- rowSums(dmf[banal,])
72 banalspec <- specf<-outf[[1]][banal,]
73 banal <- cbind(banalfreq, banalspec)
74 write.csv2(banal,file="%s")
75 """ % ffr(self.pathout['banalites.csv'])
79 write.csv2(specf,file="%s")
80 """ % ffr(self.dictpathout['tablespecf'])
82 write.csv2(spect,file="%s")
83 """ % ffr(self.dictpathout['tablespect'])
85 write.csv2(outf[[3]],file="%s")
86 """ % ffr(self.dictpathout['eff_relatif_forme'])
88 write.csv2(outt[[3]],file="%s")
89 """ % ffr(self.dictpathout['eff_relatif_type'])
90 if self.parametres['clnb'] > 2 :
97 dmfp<-dmf[-which(slf==0),]
98 specfp <- specf[-which(slf==0),]
103 afcf <- ca(dmfp, nd = nd)
106 dmtp<-dmt[-which(slt==0),]
107 spectp <- spect[-which(slt==0),]
112 afct <- ca(dmtp, nd = nd)
113 open_file_graph("%s", widt = 1000, height=1000)
114 plot(afcf, what=c('all','none'), labels=c(1,1))
115 open_file_graph("%s", widt = 1000, height=1000)
116 plot(afcf, what=c('none','all'), labels=c(1,1))
117 open_file_graph("%s", widt = 1000, height=1000)
118 plot(afct, what=c('all','none'), labels=c(1,1))
119 open_file_graph("%s", widt = 1000, height=1000)
120 plot(afct, what=c('none','all'), labels=c(1,1))
121 afcf <- AddCorrelationOk(afcf)
122 afct <- AddCorrelationOk(afct)
123 afcf <- summary.ca.dm(afcf)
124 afct <- summary.ca.dm(afct)
125 afcf_table <- create_afc_table(afcf)
126 afct_table <- create_afc_table(afct)
127 write.csv2(afcf_table$facteur, file = "%s")
128 write.csv2(afcf_table$colonne, file = "%s")
129 write.csv2(afcf_table$ligne, file = "%s")
130 write.csv2(afct_table$facteur, file = "%s")
131 write.csv2(afct_table$colonne, file = "%s")
132 write.csv2(afct_table$ligne, file = "%s")
136 """ % (ffr(self.dictpathout['afcf_row']), ffr(self.dictpathout['afcf_col']), ffr(self.dictpathout['afct_row']), ffr(self.dictpathout['afct_col']), ffr(self.dictpathout['afcf_facteur_csv']), ffr(self.dictpathout['afcf_col_csv']), ffr(self.dictpathout['afcf_row_csv']), ffr(self.dictpathout['afct_facteur_csv']), ffr(self.dictpathout['afct_col_csv']), ffr(self.dictpathout['afct_row_csv']))
140 """ % ffr(self.dictpathout['RData'])
141 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
142 tmpscript = open(tmpfile, 'w')
145 self.doR(tmpfile, dlg = self.dlg, message = 'R...')
147 def preferences(self) :
148 listet = self.corpus.make_etoiles()
150 variables = treat_var_mod(listet)
151 var = [v for v in variables]
152 dial = OptLexi(self.parent)
156 dial.list_box_1.Append(et)
157 dial.CenterOnParent()
158 self.dialok = dial.ShowModal()
159 if self.dialok == wx.ID_OK :
160 if dial.choice.GetSelection() == 1 :
161 ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
163 ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
166 self.parametres['mineff'] = dial.spin.GetValue()
167 if dial.choice_indice.GetSelection() == 0 :
168 self.parametres['indice'] = 'hypergeo'
170 self.parametres['indice'] = 'chi2'
171 self.parametres['typeformes'] = dial.typeformes.GetSelection()
172 self.parametres['clnb'] = len(ListEt)
174 return self.parametres
179 def make_lexico(self) :
180 mineff = self.parametres['mineff']
181 #dlg = progressbar(self, maxi = 3)
182 tabout = self.corpus.make_lexitable(mineff, self.listet, gram = self.parametres['typeformes'])
183 #log.warning('Fmax a 200')
184 #Fmax = [line for line in tabout[1:] if sum(line[1:]) > 199]
185 #formesmax = [line[0] for line in Fmax
186 #Fmax = [line[1:] for line in Fmax]
187 #summax = [sum(col) for col in zip(*Fmax)]
188 #tabout.append(['Fmax'] + summax)
189 #tabout = [line for line in tabout if line[0] not in formesmax]
190 #log.warning('ATTENTION : hapax par etoile')
191 #tabout.append(['hapax'] + self.corpus.gethapaxbyet(self.listet))
192 write_tab(tabout, self.dictpathout['tableafcm'])
194 #log.warning('ATTENTION : gethapaxuces')
195 #self.corpus.gethapaxuces()
197 tabout = self.corpus.make_efftype_from_etoiles(self.listet)
198 write_tab(tabout, self.dictpathout['tabletypem'])
200 self.dlg.Update(2, u'R...')
203 self.dlg.Update(3, u'Chargement...')
204 afcf_graph_list = [[os.path.basename(self.dictpathout['afcf_row']), u'lignes'],\
205 [os.path.basename(self.dictpathout['afcf_col']), u'colonnes']]
206 afct_graph_list = [[os.path.basename(self.dictpathout['afct_row']), u'lignes'],\
207 [os.path.basename(self.dictpathout['afct_col']), u'colonnes']]
208 print_liste(self.dictpathout['liste_graph_afcf'],afcf_graph_list)
209 print_liste(self.dictpathout['liste_graph_afct'],afct_graph_list)
210 #DoConf().makeoptions(['spec'],[self.parametres], self.dictpathout['ira'])
212 class TgenSpec(AnalyseText):
213 def __init__(self, ira, corpus, parametres):
216 self.parametres = parametres
217 self.pathout = PathOut(dirout = self.parametres['pathout'])
221 self.tgen = TGen(path = self.parametres['tgenpath'], encoding = self.ira.syscoding)
222 self.tgen.read(self.tgen.path)
223 self.parametres['etoiles'].sort()
224 tgenocc, totocc = self.corpus.make_tgen_table(self.tgen, self.parametres['etoiles'])
225 self.parametres['tgeneff'] = os.path.join(self.parametres['pathout'], 'tgeneff.csv')
226 self.tgen.writetable(self.parametres['tgeneff'], tgenocc, totocc)
227 self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenspec.csv')
228 self.Rscript = TgenSpecScript(self)
229 self.Rscript.make_script()
231 self.doR(self.Rscript.scriptout, dlg = False, message = 'R...')