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']
35 # def __init__(self, parent, cmd = False):
36 # self.parent = parent
38 # self.ConfigPath = parent.ConfigPath
39 # self.DictPath = parent.DictPath
40 # self.KeyConf = RawConfigParser()
41 # self.KeyConf.read(self.ConfigPath['key'])
43 # page = getPage(self.parent)
44 # if page is not None :
45 # self.corpus = getCorpus(page)
46 # if self.corpus is not None :
47 # pathout = ConstructPathOut(self.corpus.parametre['openpath'], 'lexico')
48 # self.dictpathout = StatTxtPathOut(pathout)
50 # #print self.corpus.lems
54 # self.corpus = Corpus(parent)
55 # self.corpus.content = self.parent.content
56 # self.corpus.parametre['encodage'] = parent.corpus_encodage
57 # self.corpus.parametre['lang'] = parent.corpus_lang
58 # self.corpus.parametre['filename'] = parent.filename
59 # dial = StatDialog(self, self.parent)
60 # dial.check_uce.SetValue(True)
61 # dial.check_uce.Enable(False)
62 # dial.OnCheckUce(wx.EVT_MENU)
63 # self.val = dial.ShowModal()
64 ## dial = LexDialog(self.parent)
65 ## dial.CenterOnParent()
66 ## res = dial.ShowModal()
67 # if self.val == wx.ID_OK :
68 # #if dial.m_radioBox2.GetSelection() == 0 : self.corpus.parametre['lem'] = True
69 # if dial.radio_lem.GetSelection() == 0 : self.corpus.parametre['lem'] = True
70 # else : self.corpus.parametre['lem'] = False
71 # #if dial.m_radioBox21.GetSelection() == 0 : self.corpus.parametre['expressions'] = True
72 # if dial.exp.GetSelection() == 0 : self.corpus.parametre['expressions'] = True
73 # else : self.corpus.parametre['expressions'] = False
74 # self.make_uce = dial.check_uce.GetValue()
75 # self.corpus.parametre['nbforme_uce'] = dial.spin_ctrl_4.GetValue()
76 # self.corpus.parametre['max_actives'] = dial.spin_max_actives.GetValue()
77 # self.corpus.parametre['eff_min_uce'] = self.corpus.parametre['nbforme_uce']
79 # pathout = ConstructPathOut(self.corpus.parametre['filename'], 'lexico')
80 # self.dictpathout = StatTxtPathOut(pathout)
82 # #print self.corpus.ucis
85 # def make_corpus(self) :
88 # dlg = progressbar(self, maxi = 6)
89 # self.corpus.supplementaires = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "2"]
90 # self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]
91 # ucis_txt, ucis_paras_txt = self.corpus.start_analyse(self.parent, dlg = dlg, cmd = self.cmd)
95 # dlg.Update(5, '%i ucis - Construction des uces' % len(ucis_paras_txt))
96 # self.corpus.make_ucis_paras_uces(ucis_paras_txt, make_uce = self.make_uce)
99 # if self.corpus.para_coords != [[] for val in self.corpus.para_coords] :
100 # self.corpus.parametre['para'] = True
102 # self.corpus.parametre['para'] = False
103 # self.corpus.make_etoiles(self.corpus.para_coords)
105 # print 'len(ucis_paras_uces)', len(self.corpus.ucis_paras_uces)
108 # dlg.Update(6, u'Dictionnaires')
109 # uces, orderuces = self.corpus.make_forms_and_uces()
110 # self.corpus.make_lems(self.parent.lexique)
111 ## if not self.corpus.parametre['lem'] :
112 ## formes = self.corpus.formes
114 ## formes = self.corpus.make_lem_eff()
124 """ % (self.parent.RscriptsPath['chdfunct'], self.parent.RscriptsPath['Rgraph'])
126 dmf<-read.csv2("%s",row.names=1)
127 """ % self.dictpathout['tableafcm']
129 dmt<-read.csv2("%s",row.names=1)
130 """ % self.dictpathout['tabletypem']
131 if self.parametres['indice'] == 'hypergeo' :
133 outf <- make.spec.hypergeo(dmf)
134 outt <- make.spec.hypergeo(dmt)
136 elif self.parametres['indice'] == 'chi2' :
145 write.csv2(specf,file="%s")
146 """ % self.dictpathout['tablespecf']
148 write.csv2(spect,file="%s")
149 """ % self.dictpathout['tablespect']
151 write.csv2(outf[[3]],file="%s")
152 """ % self.dictpathout['eff_relatif_forme']
154 write.csv2(outt[[3]],file="%s")
155 """ % self.dictpathout['eff_relatif_type']
156 if self.parametres['clnb'] > 2 :
159 nd <- ncol(specf) - 1
163 dmfp<-dmf[-which(slf==0),]
164 specfp <- specf[-which(slf==0),]
169 afcf <- ca(dmfp, nd = nd)
172 dmtp<-dmt[-which(slt==0),]
173 spectp <- spect[-which(slt==0),]
178 afct <- ca(dmtp, nd = nd)
179 open_file_graph("%s", widt = 1000, height=1000)
180 plot(afcf, what=c('all','none'), labels=c(1,1))
181 open_file_graph("%s", widt = 1000, height=1000)
182 plot(afcf, what=c('none','all'), labels=c(1,1))
183 open_file_graph("%s", widt = 1000, height=1000)
184 plot(afct, what=c('all','none'), labels=c(1,1))
185 open_file_graph("%s", widt = 1000, height=1000)
186 plot(afct, what=c('none','all'), labels=c(1,1))
187 afcf <- AddCorrelationOk(afcf)
188 afct <- AddCorrelationOk(afct)
189 afcf <- summary.ca.dm(afcf)
190 afct <- summary.ca.dm(afct)
191 afcf_table <- create_afc_table(afcf)
192 afct_table <- create_afc_table(afct)
193 write.csv2(afcf_table$facteur, file = "%s")
194 write.csv2(afcf_table$colonne, file = "%s")
195 write.csv2(afcf_table$ligne, file = "%s")
196 write.csv2(afct_table$facteur, file = "%s")
197 write.csv2(afct_table$colonne, file = "%s")
198 write.csv2(afct_table$ligne, file = "%s")
202 """ % (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'])
206 """ % self.dictpathout['RData']
207 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
208 tmpscript = open(tmpfile, 'w')
211 self.doR(tmpfile, dlg = self.dlg, message = 'R...')
212 #pid = exec_rcode(self.parent.RPath, tmpfile, wait = False)
213 #while pid.poll() == None :
215 #check_Rresult(self.parent, pid)
217 def preferences(self) :
218 listet = self.corpus.make_etoiles()
220 variables = treat_var_mod(listet)
221 var = [v for v in variables]
222 dial = OptLexi(self.parent)
226 dial.list_box_1.Append(et)
227 dial.CenterOnParent()
228 self.dialok = dial.ShowModal()
229 if self.dialok == wx.ID_OK :
230 if dial.choice.GetSelection() == 1 :
231 ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
233 ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
235 self.parametres['mineff'] = dial.spin.GetValue()
236 if dial.choice_indice.GetSelection() == 0 :
237 self.parametres['indice'] = 'hypergeo'
239 self.parametres['indice'] = 'chi2'
240 self.parametres['clnb'] = len(ListEt)
241 #if dial.checklem.GetValue() :
242 # self.parametres['lem'] = 1
244 # self.parametres['lem'] = 0
246 return self.parametres
251 def make_lexico(self) :
252 # listet = self.corpus.make_etoiles()
254 # variables = treat_var_mod(listet)
255 # var = [v for v in variables]
257 # dial = OptLexi(self.parent)
258 # dial.listet = listet
259 # dial.variables = var
261 # dial.list_box_1.Append(et)
262 # dial.CenterOnParent()
263 # val = dial.ShowModal()
264 # if val == wx.ID_OK :
265 # if dial.choice.GetSelection() == 1 :
266 # ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
268 # ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
269 # mineff = dial.spin.GetValue()
270 # if dial.choice_indice.GetSelection() == 0 :
271 # indice = 'hypergeo'
274 # self.parametres = {'indice' : indice}
279 mineff = self.parametres['mineff']
280 #dlg = progressbar(self, maxi = 3)
281 tabout = self.corpus.make_lexitable(mineff, self.listet)
282 #log.warning('Fmax a 200')
283 #Fmax = [line for line in tabout[1:] if sum(line[1:]) > 199]
284 #formesmax = [line[0] for line in Fmax]
285 #Fmax = [line[1:] for line in Fmax]
286 #summax = [sum(col) for col in zip(*Fmax)]
287 #tabout.append(['Fmax'] + summax)
288 #tabout = [line for line in tabout if line[0] not in formesmax]
289 #log.warning('ATTENTION : hapax par etoile')
290 #tabout.append(['hapax'] + self.corpus.gethapaxbyet(self.listet))
291 write_tab(tabout, self.dictpathout['tableafcm'])
293 #log.warning('ATTENTION : gethapaxuces')
294 #self.corpus.gethapaxuces()
296 tabout = self.corpus.make_efftype_from_etoiles(self.listet)
297 write_tab(tabout, self.dictpathout['tabletypem'])
299 self.dlg.Update(2, u'R...')
302 self.dlg.Update(3, u'Chargement...')
303 afcf_graph_list = [[os.path.basename(self.dictpathout['afcf_row']), u'lignes'],\
304 [os.path.basename(self.dictpathout['afcf_col']), u'colonnes']]
305 afct_graph_list = [[os.path.basename(self.dictpathout['afct_row']), u'lignes'],\
306 [os.path.basename(self.dictpathout['afct_col']), u'colonnes']]
307 print_liste(self.dictpathout['liste_graph_afcf'],afcf_graph_list)
308 print_liste(self.dictpathout['liste_graph_afct'],afct_graph_list)
309 #CreateIraFile(self.dictpathout, 0, corpname = os.path.basename(self.corpus.parametre['filename']), section = 'lexico')
310 DoConf().makeoptions(['spec'],[self.parametres], self.dictpathout['ira'])
311 #OpenAnalyse(self.parent, self.dictpathout['ira'])