X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=analysetxt.py;h=f11a5967db4e67935d921e7d6e475c58a7383ce5;hb=refs%2Fheads%2F3.0;hp=f9b39738ea0c0f36bb14dc5d054fbe87e352cdf3;hpb=00cb7159f4b39c7640aaf13f10570f31c2601ba6;p=iramuteq diff --git a/analysetxt.py b/analysetxt.py index f9b3973..7bbd053 100755 --- a/analysetxt.py +++ b/analysetxt.py @@ -1,43 +1,54 @@ # -*- coding: utf-8 -*- -# Author: Pierre Ratinaud -# lisence : GNU GPL -# copyright : 2012-2013 (c) Pierre Ratinaud +#Author: Pierre Ratinaud +#Copyright (c) 2008-2020 Pierre Ratinaud +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 +#License: GNU/GPL +#------------------------------------ +# import des modules python +#------------------------------------ import logging -from chemins import PathOut -from functions import exec_rcode, check_Rresult, DoConf, ReadDicoAsDico, progressbar from shutil import copy from time import time, sleep from uuid import uuid4 import os + +#------------------------------------ +# import des fichiers du projet +#------------------------------------ +from chemins import PathOut +from functions import exec_rcode, check_Rresult, DoConf, ReadDicoAsDico, progressbar from openanalyse import OpenAnalyse from dialog import StatDialog + + log = logging.getLogger('iramuteq.analyse') + + class AnalyseText : - def __init__(self, ira, corpus, parametres=None, dlg=False, lemdial=True) : + + def __init__(self, ira, corpus, parametres=None, dlg=False, lemdial=True): self.corpus = corpus self.ira = ira self.parent = ira self.dlg = dlg self.dialok = True self.parametres = parametres - #print(parametres) self.lemdial = lemdial self.val = False self.keys = DoConf(self.ira.ConfigPath['key']).getoptions() - if not 'pathout' in self.parametres : + if not 'pathout' in self.parametres: self.pathout = PathOut(corpus.parametres['originalpath'], analyse_type=parametres['type'], dirout=corpus.parametres['pathout']) - else : + else: self.pathout = PathOut(filename=corpus.parametres['originalpath'], dirout=self.parametres['pathout'], analyse_type=self.parametres['type']) self.parametres = self.lemparam() - if self.parametres is not None : + if self.parametres is not None: self.parametres = self.make_config(parametres) - #print 'paramtre aprs make_config', self.parametres - log.info(self.pathout.dirout) - if self.parametres is not None : + if self.parametres is not None: self.keys = DoConf(self.ira.ConfigPath['key']).getoptions() + print(self.keys) gramact = [k for k in self.keys if self.keys[k] == 1] gramsup = [k for k in self.keys if self.keys[k] == 2] self.parametres['pathout'] = self.pathout.mkdirout() @@ -47,13 +58,12 @@ class AnalyseText : self.parametres['uuid'] = str(uuid4()) self.parametres['name'] = os.path.split(self.parametres['pathout'])[1] self.parametres['type'] = parametres['type'] - self.parametres['encoding'] = self.ira.syscoding + #self.parametres['encoding'] = self.ira.syscoding self.t1 = time() - if not self.parametres.get('dictionary', False) : - print self.parametres + if not self.parametres.get('dictionary', False): self.corpus.make_lems(lem=self.parametres['lem']) - else : - print 'read new dico' + else: + print('read new dico') dico = ReadDicoAsDico(self.parametres['dictionary']) self.corpus.make_lems_from_dict(dico, dolem=self.parametres['lem']) dictname = os.path.basename(self.parametres['dictionary']) @@ -61,10 +71,10 @@ class AnalyseText : copy(self.parametres['dictionary'], dictpath) self.parametres['dictionary'] = dictpath self.corpus.parse_active(gramact, gramsup) - if dlg : - self.dlg = progressbar(self.ira, dlg) +# if dlg: +# self.dlg = progressbar(self.ira, dlg) result_analyse = self.doanalyse() - if result_analyse is None : + if result_analyse is None: self.time = time() - self.t1 minutes, seconds = divmod(self.time, 60) hours, minutes = divmod(minutes, 60) @@ -73,12 +83,13 @@ class AnalyseText : DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira']) self.ira.history.add(self.parametres) if dlg : - if not isinstance(dlg, int) : - dlg.Destroy() - self.dlg.Destroy() +# if not isinstance(dlg, int) : +# dlg.Destroy() + self.dlg = progressbar(self.ira, dlg) OpenAnalyse(self.parent, self.parametres['ira']) self.ira.tree.AddAnalyse(self.parametres) self.val = 5100 + self.dlg.Destroy() else : self.val = False if dlg : @@ -135,12 +146,19 @@ class AnalyseText : pass def doR(self, Rscript, wait=False, dlg=None, message='') : - log.info('R code...') + log.info('R code... ') + # idéalement, la fonction prendrait en charge la création/destruction de sa propre fenêtre de progression + if isinstance(dlg, int): + dialProgression = progressbar(self, dlg) + else: + dialProgression = dlg pid = exec_rcode(self.ira.RPath, Rscript, wait=wait) while pid.poll() is None : if dlg : - self.dlg.Pulse(message) + dialProgression.Pulse(message) sleep(0.2) else : sleep(0.2) + if isinstance(dlg, int): + dialProgression.Destroy() return check_Rresult(self.ira, pid)