2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2012, Pierre Ratinaud
7 from chemins import ChdTxtPathOut, StatTxtPathOut, construct_simipath
8 from layout import OpenCHDS, dolexlayout, StatLayout, WordCloudLayout, OpenCorpus, SimiLayout
9 #from corpus import Corpus
10 from corpusNG import Corpus, copycorpus
11 from tableau import Tableau
14 from ConfigParser import *
15 from tabsimi import DoSimi
16 from functions import BugReport, DoConf
19 log = logging.getLogger('iramuteq.openanalyse')
22 def __init__(self, parent, parametres, Alceste=True, simifromprof = False):
23 #self.conf = RawConfigParser()
24 #self.conf.read(filename)
25 log.info('OpenAnalyse')
27 if isinstance(parametres, dict) :
28 self.conf = DoConf(parametres['ira']).getoptions()
29 self.path = parametres['ira']
31 self.conf = DoConf(parametres).getoptions()
32 self.path = parametres
33 self.conf = self.redopath(self.conf, parametres)
35 if self.conf['type'] == 'corpus' :
36 corpus = self.opencorpus()
37 elif self.conf['corpus'] in self.parent.history.history :
38 corpus = self.openanalyse()
39 if self.conf.get('lem',1) :
40 corpus.make_lems(True)
42 corpus.make_lems(False)
46 self.parent.history.addtab(self.conf)
48 def redopath(self, conf, path) :
49 #if not os.path.exists(conf['ira']) :
50 conf['ira'] = os.path.realpath(path)
51 conf['pathout'] = os.path.dirname(os.path.realpath(path))
52 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
55 def opencorpus(self) :
56 if self.conf['uuid'] not in self.parent.history.history :
57 self.parent.history.add(self.conf)
58 log.info('add to history')
59 self.parent.tree.OnItemAppend(self.conf)
60 if self.conf['uuid'] in self.parent.history.openedcorpus :
61 log.info('corpus is already opened')
62 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
64 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.conf['uuid']]['ira'])
65 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
66 self.opencorpus_analyses()
69 def opencorpus_analyses(self) :
70 basepath = self.conf['pathout']
71 for root, subfolders, files in os.walk(basepath) :
72 for folder in subfolders :
73 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
74 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
75 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
76 if analyse_conf['corpus'] == self.conf['uuid'] :
77 self.parent.history.add(analyse_conf)
78 self.parent.tree.AddAnalyse(analyse_conf, bold = False)
80 #self.parent.tree.OnItemAppend(self.conf)
81 def openanalyse(self) :
82 if self.conf['corpus'] in self.parent.history.openedcorpus :
83 log.info('corpus is already opened')
84 corpus = self.parent.history.openedcorpus[self.conf['corpus']]
86 if os.path.exists(self.parent.history.history[self.conf['corpus']]['ira']) :
87 corpus = Corpus(self, parametres = DoConf(self.parent.history.history[self.conf['corpus']]['ira']).getoptions('corpus'), read = self.parent.history.history[self.conf['corpus']]['ira'])
88 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
91 def doopen(self, corpus) :
93 if self.conf['type'] == 'corpus' :
94 self.parent.ShowMenu(_("Text analysis"))
95 OpenCorpus(self.parent, self.conf)
96 elif self.conf['type'] == 'stat' :
97 self.parent.ShowMenu(_("Text analysis"))
98 StatLayout(self.parent, corpus, self.conf)
99 elif self.conf['type'] == 'spec' :
100 self.parent.ShowMenu(_("Text analysis"))
101 dolexlayout(self.parent, corpus, self.conf)
102 elif self.conf['type'] == 'alceste' :
103 self.parent.ShowMenu(_("Text analysis"))
104 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
105 elif self.conf['type'] == 'simitxt' :
106 self.parent.ShowMenu(_("Text analysis"))
107 SimiLayout(self.parent, corpus, self.conf)
108 elif self.conf['type'] == 'wordcloud' :
109 self.parent.ShowMenu(_("Text analysis"))
110 WordCloudLayout(self.parent, corpus, self.conf)
111 #self.tableau = Tableau(self.parent, self.conf['ira'])
112 #self.DictPathOut=construct_simipath(self.conf['pathout'])
113 #self.tableau.dictpathout = self.DictPathOut
114 #self.tableau.read_tableau(self.tableau.dictpathout['db'])
115 #if self.tableau.parametre.get('corpus', False) :
117 #self.corpus.read_corpus_from_shelves(self.DictPathOut['corpus'])
118 # self.corpus.parametres['openpath'] = self.conf['pathout']
119 #DoSimi(self.parent, self.conf, isopen = True, filename = self.conf['ira'], gparent = self, openfromprof=False)
122 # #if self.conf['type'] in ['analyse','lexico','stat','wordcloud'] :
123 # # self.corpus = Corpus(parent)
124 # if 'analyse' in self.conf.sections() :
125 # DictPathOut=ChdTxtPathOut(os.path.dirname(filename))
126 # self.pathout = os.path.dirname(filename)
127 # self.DictPathOut=DictPathOut
128 # #self.corpus = Corpus(parent)
129 # self.corpus.dictpathout = self.DictPathOut
130 # self.corpus.read_corpus_from_shelves(self.DictPathOut['db'])
131 # self.corpus.parametre['analyse'] = 'alceste'
132 # self.corpus.make_lem_type_list()
133 # # print 'EXTRACT NR'
134 # # self.corpus.extractnr()
136 # #self.corpus.save_corpus(self.corpus.dictpathout['db'])
137 # #self.corpus.make_uci_stat()
138 # #self.corpus.make_et_table()
139 # #self.corpus.prof_type()
140 # #self.corpus.make_type_tot()
141 # #self.corpus.make_size_uci()
142 # #self.corpus.get_stat_by_cluster()
143 # OpenCHDS(parent, self, filename, Alceste)
144 # self.parent.ShowMenu(_("Text analysis"))
145 # self.parent._mgr.Update()
146 # elif 'questionnaire' in self.conf.sections() :
147 # self.DictPathOut=ChdTxtPathOut(os.path.dirname(filename))
148 # self.pathout = os.path.dirname(filename)
149 # self.tableau = Tableau(parent, filename)
150 # self.tableau.dictpathout = self.DictPathOut
151 # self.tableau.read_tableau(self.tableau.dictpathout['db'])
152 # OpenCHDS(parent, self, filename, False)
153 # elif 'simi' in self.conf.sections():
154 # self.tableau = Tableau(parent, filename)
155 # self.DictPathOut=construct_simipath(os.path.abspath(os.path.dirname(filename)))
156 # self.tableau.dictpathout = self.DictPathOut
157 # self.tableau.read_tableau(self.tableau.dictpathout['db'])
158 # if self.tableau.parametre.get('fromtxt', False) :
159 # self.corpus=Corpus(parent)
160 # self.corpus.read_corpus_from_shelves(self.DictPathOut['corpus'])
161 # self.corpus.parametre['openpath'] = os.path.dirname(filename)
162 # self.parent.ShowMenu(_("Text analysis"))
163 # DoSimi(parent, self.conf, isopen = True, filename = filename, gparent = self, openfromprof=simifromprof)
164 # elif 'lexico' in self.conf.sections():
166 # #self.corpus = Corpus(parent)
167 # self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
168 # self.parent.ShowMenu(_("Text analysis"))
169 # dolexlayout(parent, self, filename)
170 # elif 'stat' in self.conf.sections():
172 # #self.corpus = Corpus(parent)
173 # self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
174 # self.parent.ShowMenu(_("Text analysis"))
175 # StatLayout(parent, self, filename)
176 # elif 'chd_dist_quest' in self.conf.sections():
177 # self.DictPathOut = ChdTxtPathOut(os.path.dirname(filename))
178 # self.pathout = os.path.dirname(filename)
179 # self.tableau = Tableau(parent, filename)
180 # self.tableau.dictpathout = self.DictPathOut
181 # self.tableau.read_tableau(self.tableau.dictpathout['db'])
182 # OpenCHDS(parent, self, filename, False)
183 # elif 'wordcloud' in self.conf.sections() :
184 # self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
185 # self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
186 # self.parent.ShowMenu(_("Text analysis"))
187 # WordCloudLayout(parent, self, filename)
188 # if self.conf.sections()[0] in ['analyse','lexico','stat','wordcloud'] :
189 # self.corpus.parametre['openpath'] = os.path.dirname(filename)
191 # BugReport(self.parent)