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
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']
51 """ % self.parametres['indice']
52 if self.parametres['indice'] == 'hypergeo' :
54 outf <- make.spec.hypergeo(dmf)
55 outt <- make.spec.hypergeo(dmt)
57 elif self.parametres['indice'] == 'chi2' :
63 if (indice == 'hypergeo') {
65 } else if (indice == 'chi2') {
68 banal <- apply(abs(outf[[1]]), 1, max)
69 banal <- which(banal < banseuil)
70 banalfreq <- rowSums(dmf[banal,])
71 banalspec <- specf<-outf[[1]][banal,]
72 banal <- cbind(banalfreq, banalspec)
73 write.csv2(banal,file="%s")
74 """ % self.pathout['banalites.csv']
78 write.csv2(specf,file="%s")
79 """ % self.dictpathout['tablespecf']
81 write.csv2(spect,file="%s")
82 """ % self.dictpathout['tablespect']
84 write.csv2(outf[[3]],file="%s")
85 """ % self.dictpathout['eff_relatif_forme']
87 write.csv2(outt[[3]],file="%s")
88 """ % self.dictpathout['eff_relatif_type']
89 if self.parametres['clnb'] > 2 :
96 dmfp<-dmf[-which(slf==0),]
97 specfp <- specf[-which(slf==0),]
102 afcf <- ca(dmfp, nd = nd)
105 dmtp<-dmt[-which(slt==0),]
106 spectp <- spect[-which(slt==0),]
111 afct <- ca(dmtp, nd = nd)
112 open_file_graph("%s", widt = 1000, height=1000)
113 plot(afcf, what=c('all','none'), labels=c(1,1))
114 open_file_graph("%s", widt = 1000, height=1000)
115 plot(afcf, what=c('none','all'), labels=c(1,1))
116 open_file_graph("%s", widt = 1000, height=1000)
117 plot(afct, what=c('all','none'), labels=c(1,1))
118 open_file_graph("%s", widt = 1000, height=1000)
119 plot(afct, what=c('none','all'), labels=c(1,1))
120 afcf <- AddCorrelationOk(afcf)
121 afct <- AddCorrelationOk(afct)
122 afcf <- summary.ca.dm(afcf)
123 afct <- summary.ca.dm(afct)
124 afcf_table <- create_afc_table(afcf)
125 afct_table <- create_afc_table(afct)
126 write.csv2(afcf_table$facteur, file = "%s")
127 write.csv2(afcf_table$colonne, file = "%s")
128 write.csv2(afcf_table$ligne, file = "%s")
129 write.csv2(afct_table$facteur, file = "%s")
130 write.csv2(afct_table$colonne, file = "%s")
131 write.csv2(afct_table$ligne, file = "%s")
135 """ % (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'])
139 """ % self.dictpathout['RData']
140 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
141 tmpscript = open(tmpfile, 'w')
144 self.doR(tmpfile, dlg = self.dlg, message = 'R...')
146 def preferences(self) :
147 listet = self.corpus.make_etoiles()
149 variables = treat_var_mod(listet)
150 var = [v for v in variables]
151 dial = OptLexi(self.parent)
155 dial.list_box_1.Append(et)
156 dial.CenterOnParent()
157 self.dialok = dial.ShowModal()
158 if self.dialok == wx.ID_OK :
159 if dial.choice.GetSelection() == 1 :
160 ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
162 ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
164 self.parametres['mineff'] = dial.spin.GetValue()
165 if dial.choice_indice.GetSelection() == 0 :
166 self.parametres['indice'] = 'hypergeo'
168 self.parametres['indice'] = 'chi2'
169 self.parametres['typeformes'] = dial.typeformes.GetSelection()
170 self.parametres['clnb'] = len(ListEt)
172 return self.parametres
177 def make_lexico(self) :
178 mineff = self.parametres['mineff']
179 #dlg = progressbar(self, maxi = 3)
180 tabout = self.corpus.make_lexitable(mineff, self.listet, gram = self.parametres['typeformes'])
181 #log.warning('Fmax a 200')
182 #Fmax = [line for line in tabout[1:] if sum(line[1:]) > 199]
183 #formesmax = [line[0] for line in Fmax
184 #Fmax = [line[1:] for line in Fmax]
185 #summax = [sum(col) for col in zip(*Fmax)]
186 #tabout.append(['Fmax'] + summax)
187 #tabout = [line for line in tabout if line[0] not in formesmax]
188 #log.warning('ATTENTION : hapax par etoile')
189 #tabout.append(['hapax'] + self.corpus.gethapaxbyet(self.listet))
190 write_tab(tabout, self.dictpathout['tableafcm'])
192 #log.warning('ATTENTION : gethapaxuces')
193 #self.corpus.gethapaxuces()
195 tabout = self.corpus.make_efftype_from_etoiles(self.listet)
196 write_tab(tabout, self.dictpathout['tabletypem'])
198 self.dlg.Update(2, u'R...')
201 self.dlg.Update(3, u'Chargement...')
202 afcf_graph_list = [[os.path.basename(self.dictpathout['afcf_row']), u'lignes'],\
203 [os.path.basename(self.dictpathout['afcf_col']), u'colonnes']]
204 afct_graph_list = [[os.path.basename(self.dictpathout['afct_row']), u'lignes'],\
205 [os.path.basename(self.dictpathout['afct_col']), u'colonnes']]
206 print_liste(self.dictpathout['liste_graph_afcf'],afcf_graph_list)
207 print_liste(self.dictpathout['liste_graph_afct'],afct_graph_list)
208 #DoConf().makeoptions(['spec'],[self.parametres], self.dictpathout['ira'])