multisplit
[iramuteq] / textlabbe.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
5 #License: GNU/GPL
6
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
10 import os
11 import tempfile
12 from time import sleep
13 import logging
14
15 #------------------------------------
16 # import des modules wx
17 #------------------------------------
18 import wx
19
20 #------------------------------------
21 # import des fichiers du projet
22 #------------------------------------
23 from chemins import ConstructPathOut, StatTxtPathOut, PathOut, ffr
24 from analysetxt import AnalyseText
25 from functions import exec_rcode, progressbar, check_Rresult, CreateIraFile, print_liste, treat_var_mod, write_tab, DoConf, TGen
26 from dialog import OptLexi
27 from PrintRScript import LabbeScript
28
29
30 log = logging.getLogger('iramuteq.labbe')
31
32
33 class DistLabbe(AnalyseText) :
34
35     def doanalyse(self) :
36         pathout = self.pathout.dirout
37         self.dictpathout = StatTxtPathOut(pathout)
38         self.parametres['ira'] = self.dictpathout['ira']
39         self.make_lexico()
40         if self.dlg :
41             try :
42                 self.dlg.Destroy()
43             except :
44                 pass
45
46     def preferences(self) :
47         listet = self.corpus.make_etoiles()
48         listet.sort()
49         variables = treat_var_mod(listet)
50         var = [v for v in variables]
51         dial = OptLexi(self.parent)
52         dial.listet = listet
53         dial.variables = var
54         for et in var :
55             dial.list_box_1.Append(et)
56         dial.CenterOnParent()
57         self.dialok = dial.ShowModal()
58         if self.dialok == wx.ID_OK :
59             if dial.choice.GetSelection() == 1 :
60                 ListEt = [listet[i] for i in dial.list_box_1.GetSelections()]
61             else :
62                 ListEt = variables[var[dial.list_box_1.GetSelections()[0]]]
63             self.listet = ListEt
64             self.listet.sort()
65             self.parametres['mineff'] = dial.spin.GetValue()
66             if dial.choice_indice.GetSelection() == 0 :
67                 self.parametres['indice'] = 'hypergeo'
68             else :
69                 self.parametres['indice'] = 'chi2'
70             self.parametres['typeformes'] = dial.typeformes.GetSelection()
71             self.parametres['clnb'] = len(ListEt)
72             dial.Destroy()
73             return self.parametres
74         else :
75             dial.Destroy()
76             return None
77
78     def make_lexico(self) :
79         mineff = self.parametres['mineff']
80         tabout = self.corpus.make_lexitable(mineff, self.listet, gram = self.parametres['typeformes'])
81         write_tab(tabout, self.dictpathout['tableafcm'])
82         #tabout = self.corpus.make_efftype_from_etoiles(self.listet)
83         #write_tab(tabout, self.dictpathout['tabletypem'])
84         self.dlg = progressbar(self, 3)
85         if self.dlg :
86             self.dlg.Update(2, 'R...')
87         script = LabbeScript(self)
88         script.make_script()
89         self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
90         if self.dlg :
91             self.dlg.Update(3, 'Chargement...')
92         afcf_graph_list = [[os.path.basename(self.dictpathout['afcf_row']), 'lignes'],\
93                             [os.path.basename(self.dictpathout['afcf_col']), 'colonnes']]
94         #afct_graph_list = [[os.path.basename(self.dictpathout['afct_row']), 'lignes'],\
95         #                    [os.path.basename(self.dictpathout['afct_col']), 'colonnes']]
96         print_liste(self.dictpathout['liste_graph_afcf'],afcf_graph_list)
97         #print_liste(self.dictpathout['liste_graph_afct'],afct_graph_list)
98         self.dlg.Destroy()