From be2de22859c8f59abe9e1082981e4c3a62e9b7ca Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 7 Jan 2013 00:13:24 +0100 Subject: [PATCH] ... --- ProfList.py | 107 ++++++++++++++++++++++++++++---------------------------- analysetxt.py | 7 ++-- checkinstall.py | 9 ++++- chemins.py | 1 - corpusNG.py | 6 ++++ dialog.py | 2 +- functions.py | 4 +++ guifunct.py | 41 +++++++++++----------- iramuteq.py | 7 ++-- layout.py | 4 +-- openanalyse.py | 4 +-- textsimi.py | 65 ++++++++++++++++++++++++++++++---- 12 files changed, 167 insertions(+), 90 deletions(-) diff --git a/ProfList.py b/ProfList.py index 596b4e6..db822cf 100644 --- a/ProfList.py +++ b/ProfList.py @@ -504,59 +504,60 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word) def on_graph(self, evt): - dlg = progressbar(self, 2) - corpus = self.Source.corpus - uces = corpus.lc[self.cl-1] - dlg.Update(1, u'Tableau...') - #tab = corpus.make_table_with_classe(uces, self.la) - pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl) - self.filename = os.path.join(pathout,'mat01.csv') - dlg.Update(2, u'Ecriture...') - #corpus.write_tab(tab, self.filename) - #del tab - corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename) - dlg.Destroy() - paramsimi = {'coeff' : 0, - 'layout' : 2, - 'type' : 1, - 'arbremax' : 1, - 'coeff_tv' : 1, - 'coeff_tv_nb' : 0, - 'tvprop' : 0, - 'tvmin' : 5, - 'tvmax' : 30, - 'coeff_te' : 1, - 'coeff_temin' : 1, - 'coeff_temax' : 10, - 'label_v': 1, - 'label_e': 0, - 'vcex' : 0, - 'vcexmin' : 10, - 'vcexmax' : 25, - 'cex' : 10, - 'cexfromchi' : True, - 'sfromchi': False, - 'seuil_ok' : 0, - 'seuil' : 1, - 'cols' : (255,0,0), - 'cola' : (200,200,200), - 'width' : 1000, - 'height' : 1000, - 'first' : True, - 'keep_coord' : True, - 'alpha' : 20, - 'film': False, - } - self.tableau = Tableau(self.parent, '') - self.tableau.listactives = self.la - self.tableau.actives = {} - self.tableau.lchi = self.lchi - self.tableau.chi = {} - self.tableau.parametre['fromprof'] = True - for i, val in enumerate(self.la) : - self.tableau.actives[val] = [self.lfreq[i]] - self.tableau.chi[val] = [self.lchi[i]] - DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout) + self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = {'type' : 'clustersimitxt', 'pathout' : self.Source.parametres['pathout']}, dlg = progressbar(self, 4)) + #dlg = progressbar(self, 2) + #corpus = self.Source.corpus + #uces = corpus.lc[self.cl-1] + #dlg.Update(1, u'Tableau...') + ##tab = corpus.make_table_with_classe(uces, self.la) + #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl) + #self.filename = os.path.join(pathout,'mat01.csv') + #dlg.Update(2, u'Ecriture...') + ##corpus.write_tab(tab, self.filename) + ##del tab + #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename) + #dlg.Destroy() + #paramsimi = {'coeff' : 0, + # 'layout' : 2, + # 'type' : 1, + # 'arbremax' : 1, + # 'coeff_tv' : 1, + # 'coeff_tv_nb' : 0, + # 'tvprop' : 0, + # 'tvmin' : 5, + # 'tvmax' : 30, + # 'coeff_te' : 1, + # 'coeff_temin' : 1, + # 'coeff_temax' : 10, + # 'label_v': 1, + # 'label_e': 0, + # 'vcex' : 0, + # 'vcexmin' : 10, + # 'vcexmax' : 25, + # 'cex' : 10, + # 'cexfromchi' : True, + # 'sfromchi': False, + # 'seuil_ok' : 0, + # 'seuil' : 1, + # 'cols' : (255,0,0), + # 'cola' : (200,200,200), + # 'width' : 1000, + # 'height' : 1000, + # 'first' : True, + # 'keep_coord' : True, + # 'alpha' : 20, + # 'film': False, + # } + #self.tableau = Tableau(self.parent, '') + #self.tableau.listactives = self.la + #self.tableau.actives = {} + #self.tableau.lchi = self.lchi + #self.tableau.chi = {} + #self.tableau.parametre['fromprof'] = True + #for i, val in enumerate(self.la) : + # self.tableau.actives[val] = [self.lfreq[i]] + # self.tableau.chi[val] = [self.lchi[i]] + #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout) def on_segments(self,evt) : dlg = progressbar(self, 2) diff --git a/analysetxt.py b/analysetxt.py index 54f0c5c..d3f8591 100644 --- a/analysetxt.py +++ b/analysetxt.py @@ -10,7 +10,7 @@ import os #ALCESTE from PrintRScript import RchdTxt, AlcesteTxtProf from OptionAlceste import OptionAlc -from layout import PrintRapport +#from layout import PrintRapport from openanalyse import OpenAnalyse from time import time ###################################### @@ -53,7 +53,10 @@ class AnalyseText : self.dialok = True self.parametres = parametres self.val = False - self.pathout = PathOut(corpus.parametres['originalpath'], analyse_type = parametres['type'], dirout = corpus.parametres['pathout']) + if not 'pathout' in self.parametres : + self.pathout = PathOut(corpus.parametres['originalpath'], analyse_type = parametres['type'], dirout = corpus.parametres['pathout']) + else : + self.pathout = PathOut(filename = corpus.parametres['originalpath'], dirout = self.parametres['pathout'], analyse_type = self.parametres['name']) self.parametres = self.make_config(parametres) log.info(self.pathout.dirout) if self.parametres is not None : diff --git a/checkinstall.py b/checkinstall.py index 38640ed..742c15a 100644 --- a/checkinstall.py +++ b/checkinstall.py @@ -7,7 +7,7 @@ import os import sys import shutil -from chemins import ConstructConfigPath +from chemins import ConstructConfigPath, ConstructDicoPath from functions import exec_rcode, exec_RCMD import wx import tempfile @@ -54,6 +54,8 @@ def UpgradeConf(self) : def CreateIraDirectory(UserConfigPath,AppliPath): if not os.path.exists(UserConfigPath): os.mkdir(UserConfigPath) + if not os.path.exists(os.path.join(UserConfigPath, 'dictionnaires')) : + os.mkdir(os.path.join(UserConfigPath, 'dictionnaires')) def CopyConf(self) : DictUser = self.ConfigPath @@ -67,6 +69,11 @@ def CopyConf(self) : if item == u'preferences' : if not os.path.exists(filein) : shutil.copyfile(DictAppli[item],filein) + dicoUser = self.DictPath + dicoAppli = ConstructDicoPath(self.AppliPath) + for fi in dicoUser : + if not os.path.exists(dicoUser[fi]) : + shutil.copyfile(dicoAppli[fi], dicoUser[fi]) def CheckRPath(PathPath): if not os.path.exists(PathPath.get('PATHS','rpath')): diff --git a/chemins.py b/chemins.py index 18ce8e8..3b3ee17 100644 --- a/chemins.py +++ b/chemins.py @@ -117,7 +117,6 @@ def ConstructConfigPath(AppliPath, user=True): 'path': os.path.join(ConfigPath, 'path.cfg'), 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'), 'pam' : os.path.join(ConfigPath, 'pam.cfg'), - 'history' : os.path.join(ConfigPath, 'history.db'), 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'), 'stat' : os.path.join(ConfigPath, 'stat.cfg'), 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'), diff --git a/corpusNG.py b/corpusNG.py index cbaefa3..f6468b3 100644 --- a/corpusNG.py +++ b/corpusNG.py @@ -163,6 +163,9 @@ class Corpus : lemuceeff[uce] = lemuceeff.get(uce, 0) + eff[i] return lemuceeff + def getlemclustereff(self, lem, cluster) : + return len(list(set(self.lc[cluster]).intersection(self.getlemuces(lem)))) + def getlemeff(self, lem) : return self.lems[lem].freq @@ -1220,6 +1223,9 @@ class Builder : ReadLexique(self.parent, lang = parametres['lang']) self.parent.expressions = ReadDicoAsDico(self.parent.DictPath.get(parametres['lang']+'_exp', 'french_exp')) self.parametres = parametres + else : + if self.dlg is not None : + self.dlg.Destroy() dial.Destroy() def doanalyse(self) : diff --git a/dialog.py b/dialog.py index da4eed7..2e19745 100755 --- a/dialog.py +++ b/dialog.py @@ -2329,7 +2329,7 @@ class CorpusPref ( wx.Dialog ): fgSizer4.Add( self.check_charact, 0, wx.ALL, 5 ) self.txt_charact = wx.TextCtrl( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) - self.txt_charact.SetMinSize( wx.Size( 200,-1 ) ) + self.txt_charact.SetMinSize( wx.Size( 400,-1 ) ) fgSizer4.Add( self.txt_charact, 0, wx.ALL|wx.EXPAND, 5 ) diff --git a/functions.py b/functions.py index 8abda95..54ead63 100644 --- a/functions.py +++ b/functions.py @@ -520,6 +520,8 @@ def check_Rresult(parent, pid) : return False #except : # BugReport(parent) + else : + return None else : if pid != 0 : #try : @@ -527,6 +529,8 @@ def check_Rresult(parent, pid) : return False #except : # BugReport(parent) + else : + return None def print_liste(filename,liste): with open(filename,'w') as f : diff --git a/guifunct.py b/guifunct.py index 1302fbc..ca8f66c 100644 --- a/guifunct.py +++ b/guifunct.py @@ -1324,26 +1324,27 @@ class PrepSimi : self.dial.CenterOnParent() self.val = self.dial.ShowModal() if self.val == wx.ID_OK : - if self.dial.check_bystar.GetValue() : - variables = treat_var_mod(self.parametres['stars']) - vardial = dialog.OptLexi(parent) - vardial.listet = self.parametres['stars'] - vardial.variables = [v for v in variables] - for et in vardial.variables : - vardial.list_box_1.Append(et) - nval = vardial.ShowModal() - if nval == wx.ID_OK : - if vardial.choice.GetSelection() == 1 : - listet = [vardial.listet[i] for i in vardial.list_box_1.GetSelections()] - else : - listet = variables[vardial.variables[vardial.list_box_1.GetSelections()[0]]] - self.dial.Destroy() - vardial.Destroy() - self.etline = source.corpus.make_etline(listet) - self.parametres['selectedstars'] = listet - self.parametres['listet'] = self.etline - else: - vardial.Destroy() + if 'bystar' in self.parametres : + if self.dial.check_bystar.GetValue() : + variables = treat_var_mod(self.parametres['stars']) + vardial = dialog.OptLexi(parent) + vardial.listet = self.parametres['stars'] + vardial.variables = [v for v in variables] + for et in vardial.variables : + vardial.list_box_1.Append(et) + nval = vardial.ShowModal() + if nval == wx.ID_OK : + if vardial.choice.GetSelection() == 1 : + listet = [vardial.listet[i] for i in vardial.list_box_1.GetSelections()] + else : + listet = variables[vardial.variables[vardial.list_box_1.GetSelections()[0]]] + self.dial.Destroy() + vardial.Destroy() + self.etline = source.corpus.make_etline(listet) + self.parametres['selectedstars'] = listet + self.parametres['listet'] = self.etline + else: + vardial.Destroy() last = self.dial.listcol.GetFirstSelected() lastl = [self.dial.listcol.GetFirstSelected()] indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)] diff --git a/iramuteq.py b/iramuteq.py index a5d5d9a..17d348f 100644 --- a/iramuteq.py +++ b/iramuteq.py @@ -54,7 +54,7 @@ from analysetxt import Alceste from textdist import PamTxt from textstat import Stat from textaslexico import Lexico -from textsimi import SimiTxt +from textsimi import SimiTxt, SimiFromCluster from textwordcloud import WordCloud from profile_segment import ProfileSegment from textcheckcorpus import checkcorpus @@ -149,10 +149,13 @@ class IraFrame(wx.Frame): self.images_path = os.path.join(AppliPath,'images') self.UserConfigPath = UserConfigPath self.RscriptsPath = ConstructRscriptsPath(AppliPath) - self.DictPath = ConstructDicoPath(AppliPath) + #self.DictPath = ConstructDicoPath(AppliPath) + self.DictPath = ConstructDicoPath(UserConfigPath) self.ConfigGlob = ConfigGlob self.ConfigPath = ConstructConfigPath(UserConfigPath) self.pref = RawConfigParser() + #workaround for import problem + self.SimiFromCluster = SimiFromCluster #langues mylocale = wx.Locale(wx.LANGUAGE_FRENCH) mylocale.AddCatalogLookupPathPrefix(os.path.join(AppliPath,'locale')) diff --git a/layout.py b/layout.py index df30cfd..9611dbb 100644 --- a/layout.py +++ b/layout.py @@ -10,8 +10,8 @@ import wx import agw.aui as aui from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath from ConfigParser import ConfigParser -from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult -from ProfList import * +from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar +from ProfList import ProfListctrlPanel from guiparam3d import param3d, simi3d from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript from profile_segment import ProfileSegment diff --git a/openanalyse.py b/openanalyse.py index c55fef3..0c0fff7 100644 --- a/openanalyse.py +++ b/openanalyse.py @@ -12,7 +12,7 @@ from tableau import Tableau import os import shelve #from ConfigParser import * -from tabsimi import DoSimi +#from tabsimi import DoSimi from functions import BugReport, DoConf import logging @@ -98,7 +98,7 @@ class OpenAnalyse(): elif self.conf['type'] == 'alceste' : self.parent.ShowMenu(_("Text analysis")) OpenCHDS(self.parent, corpus, self.conf, Alceste = True) - elif self.conf['type'] == 'simitxt' : + elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' : self.parent.ShowMenu(_("Text analysis")) SimiLayout(self.parent, corpus, self.conf) elif self.conf['type'] == 'wordcloud' : diff --git a/textsimi.py b/textsimi.py index a5b8c7b..dc75f6e 100644 --- a/textsimi.py +++ b/textsimi.py @@ -1,19 +1,19 @@ # -*- coding: utf-8 -*- #Author: Pierre Ratinaud -#Copyright (c) 2008-2011 Pierre Ratinaud +#Copyright (c) 2008-2013 Pierre Ratinaud #Lisense: GNU/GPL from chemins import ffr, simipath #from corpus import Corpus import os from analysetxt import AnalyseText -from ConfigParser import RawConfigParser -from guifunct import getPage, getCorpus +#from ConfigParser import RawConfigParser +#from guifunct import getPage, getCorpus from dialog import StatDialog from guifunct import SelectColumn, PrepSimi from functions import indices_simi, progressbar, treat_var_mod, read_list_file, print_liste -from tableau import Tableau -from tabsimi import DoSimi +#from tableau import Tableau +#from tabsimi import DoSimi from PrintRScript import PrintSimiScript import wx from copy import copy @@ -115,14 +115,67 @@ class SimiTxt(AnalyseText): #self.actives, lim = self.corpus.make_actives_nb(self.parametres.get('max_actives',1500), 1) self.parametres['eff_min_forme'] = lim self.parametres['nbactives'] = len(self.actives) - self.parametres['fromprof'] = True + self.parametres['fromprof'] = False self.corpus.make_and_write_sparse_matrix_from_uces(self.actives, self.pathout['mat01.csv'], self.pathout['listeuce1.csv']) with open(self.pathout['actives.csv'], 'w') as f : f.write('\n'.join(self.actives).encode(self.ira.syscoding)) +class SimiFromCluster(SimiTxt) : + def __init__(self, ira, corpus, actives, numcluster, parametres = None, dlg = False) : + self.actives = actives + self.numcluster = numcluster + parametres['name'] = 'simi_classe_%i' % (numcluster + 1) + SimiTxt.__init__(self, ira, corpus, parametres, dlg) + + def preferences(self) : + return self.parametres + + def doanalyse(self) : + self.parametres['type'] = 'clustersimitxt' + self.pathout.basefiles(simipath) + self.indices = indices_simi + self.makesimiparam() + if 'bystar' in self.parametres : + del self.parametres['bystar'] + dictcol = dict([[i, [act, self.corpus.getlemclustereff(act, self.numcluster)]] for i, act in enumerate(self.actives)]) + continu = True + if self.dlg : + #self.listet = self.corpus.make_etoiles() + #self.listet.sort() + self.stars = []#copy(self.listet) + self.parametres['stars'] = False#copy(self.listet) + self.parametres['sfromchi'] = True + prep = PrepSimi(self.ira, self, self.parametres, self.pathout['selected.csv'], self.actives, indices_simi, wordlist=dictcol) + if prep.val == wx.ID_OK : + continu = True + self.parametres = prep.parametres + else : + continu = False + if continu : + self.makefiles() + script = PrintSimiScript(self) + script.make_script() + if self.doR(script.scriptout) : + return False + if self.parametres['type_graph'] == 1: + if os.path.exists(self.pathout['liste_graph']): + graph_simi = read_list_file(self.pathout['liste_graph']) + graph_simi.append([os.path.basename(script.filename), script.txtgraph]) + else : + graph_simi = [[os.path.basename(script.filename), script.txtgraph]] + print_liste(self.pathout['liste_graph'], graph_simi) + else : + return False + def makefiles(self) : + self.parametres['eff_min_forme'] = 3 + self.parametres['nbactives'] = len(self.actives) + self.parametres['fromprof'] = True + self.corpus.make_and_write_sparse_matrix_from_classe(self.actives, self.corpus.lc[self.numcluster], self.pathout['mat01.csv']) + with open(self.pathout['actives.csv'], 'w') as f : + f.write('\n'.join(self.actives).encode(self.ira.syscoding)) # self.tableau = Tableau(self.parent, '') # self.tableau.listactives = self.actives -- 2.7.4