chrono windows
[iramuteq] / textafcuci.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2009 Pierre Ratinaud
4 #License: GNU/GPL
5
6 from chemins import ConstructPathOut, ConstructAfcUciPath
7 from layout import GraphPanel
8 #from PrintRScript import RAfcUci 
9 from corpus import Corpus
10 from listlex import *
11 from functions import ReadList, progressbar, exec_rcode, check_Rresult
12 import wx
13 import os
14 from ConfigParser import RawConfigParser
15 from time import time, sleep
16
17 class AfcUci():
18     def __init__(self, parent, cmd = False):
19 #################################################################### 
20         self.conf = None
21         self.parent = parent
22         self.type = 'afcuci'
23         self.cmd = cmd
24         self.corpus = Corpus(parent)        
25         self.corpus.parametre['encodage'] = parent.corpus_encodage
26         self.corpus.parametre['filename'] = parent.filename    
27         self.corpus.parametre['lang'] = parent.corpus_lang
28         self.corpus.content = self.parent.content
29         self.ConfigPath = parent.ConfigPath
30         self.DictPath = parent.DictPath
31         self.AlcesteConf = RawConfigParser()
32         self.AlcesteConf.read(self.ConfigPath['alceste'])
33         self.KeyConf = RawConfigParser()
34         self.KeyConf.read(self.ConfigPath['key'])
35         pathout = ConstructPathOut(self.corpus.parametre['filename'], 'afcuci')
36         self.corpus.dictpathout = ConstructAfcUciPath(pathout)        
37         self.corpus.supplementaires = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "2"]
38         self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]        
39
40         self.read_alceste_parametre()
41         ################################
42         if not self.cmd :
43             self.dlg = progressbar(self, 6)
44         else :
45             self.dlg = None
46         ucis_txt, ucis_paras_txt = self.corpus.start_analyse(self.parent, dlg = self.dlg, cmd = self.cmd)
47         self.corpus.make_ucis_paras_uces(ucis_paras_txt, make_uce = False)
48         uces, orderuces = self.corpus.make_forms_and_uces()
49         self.corpus.make_lems(self.parent.lexique)
50         self.corpus.min_eff_formes()
51         
52         self.corpus.make_var_actives() 
53         self.corpus.make_var_supp()
54         print self.corpus.supp
55
56         self.corpus.make_pondtable_with_uci(self.corpus.actives, self.corpus.dictpathout['TableCont'])
57         self.corpus.make_pondtable_with_uci(self.corpus.supp, self.corpus.dictpathout['TableSup'])
58
59
60         self.corpus.parametre['para'] = False
61         self.corpus.make_etoiles([])
62         self.corpus.make_tableet_with_uci(self.corpus.dictpathout['TableEt'])
63         RAfcUci(self.corpus.dictpathout, nd=3, RscriptsPath=self.parent.RscriptsPath, PARCEX='0.5')
64         pid = exec_rcode(self.parent.RPath,self.corpus.dictpathout['Rafcuci'], wait = False)
65         while pid.poll() == None :
66             if not self.cmd :
67                 self.dlg.Pulse(u'CHD...')
68                 sleep(0.2)
69             else :
70                 pass
71         check_Rresult(self.parent, pid)
72
73         if not self.cmd :
74             self.dlg.Update(6, 'Affichage')
75             self.DoLayout(parent, self.corpus.dictpathout)
76             self.dlg.Destroy()
77
78     def read_alceste_parametre(self) :
79         self.conf = RawConfigParser()
80         self.conf.read(self.parent.ConfigPath['alceste'])
81         for option in self.conf.options('ALCESTE') :
82             if self.conf.get('ALCESTE', option).isdigit() :
83                 self.corpus.parametre[option] = int(self.conf.get('ALCESTE', option))
84             else :
85                 self.corpus.parametre[option] = self.conf.get('ALCESTE', option)
86             
87         list_bool = ['lem', 'expressions']
88         for val in list_bool :
89             if self.corpus.parametre[val] == 'True' :
90                 self.corpus.parametre[val] = True
91             else : 
92                 self.corpus.parametre[val] = False
93
94     def DoLayout(self, parent, DictAfcUciOut):
95         self.TabAfcUci = wx.aui.AuiNotebook(parent.nb, -1, wx.DefaultPosition)
96         #self.TabAfcTot = wx.html.HtmlWindow(self.TabAfcUci, -1)
97         #txtafctot = MakeAfcUciPages(DictAfcUciOut, parent.encode)
98         list_graph = [[os.path.basename(DictAfcUciOut['AfcColAct']),''],
99                       [os.path.basename(DictAfcUciOut['AfcColSup']),''],
100                       [os.path.basename(DictAfcUciOut['AfcColEt']),''],
101                       [os.path.basename(DictAfcUciOut['AfcRow']),'']]
102         self.TabAfcTot = GraphPanel(self.TabAfcUci, DictAfcUciOut, list_graph, txt = '')
103         
104         #self.TabAfcSplit = wx.html.HtmlWindow(self.TabAfcUci, -1)
105         #txtafcsplit = MakeAfcSplitPage(1, 2, DictAfcUciOut, self.pathout, parent.encode)
106         #if "gtk2" in wx.PlatformInfo:
107         #    self.TabAfcSplit.SetStandardFonts()
108         #self.TabAfcSplit.SetPage(txtafcsplit)
109         
110         dictrow, first = ReadList(self.corpus.dictpathout['afc_row'])
111         panel_list = ListForSpec(parent, self, dictrow, first[1:])
112
113         
114         
115         self.TabAfcUci.AddPage(self.TabAfcTot, 'Graph Afc totale')
116         #self.TabAfcUci.AddPage(self.TabAfcSplit, 'Graph AFC Split')
117         self.TabAfcUci.AddPage(panel_list, 'Colonnes')
118         parent.nb.AddPage(self.TabAfcUci, 'AFC Sur UCI')
119                 
120         parent.nb.SetSelection(parent.nb.GetPageCount() - 1)
121         parent.ShowTab(True) 
122