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