2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2012, Pierre Ratinaud
7 from chemins import ChdTxtPathOut, StatTxtPathOut, PathOut
8 from layout import OpenCHDS, dolexlayout, StatLayout, WordCloudLayout, OpenCorpus, SimiLayout, SimiMatLayout, ProtoLayout, MatLayout, FreqLayout, Chi2Layout
9 from corpus import Corpus, copycorpus
10 from tableau import Tableau
13 #from tabsimi import DoSimi
14 from functions import DoConf, ReadDicoAsDico
15 from tableau import Tableau
18 log = logging.getLogger('iramuteq.openanalyse')
21 def __init__(self, parent, parametres, Alceste=True, simifromprof = False):
22 log.info('OpenAnalyse')
24 if isinstance(parametres, dict) :
25 self.conf = DoConf(parametres['ira']).getoptions()
26 self.path = parametres['ira']
28 self.conf = DoConf(parametres).getoptions()
29 self.path = parametres
30 self.conf = self.redopath(self.conf, parametres)
32 if self.conf['type'] == 'corpus' :
33 corpus = self.opencorpus()
34 elif self.conf['type'] == 'matrix' :
35 matrix = self.openmatrix()
36 elif self.conf.get('corpus', False) in self.parent.history.corpus :
37 if self.conf['uuid'] in self.parent.history.analyses :
41 corpus = self.openanalyse()
43 if self.conf.get('lem',1) :
47 if self.conf.get('dictionary', False) :
48 dico = ReadDicoAsDico(self.conf['dictionary'])
49 corpus.make_lems_from_dict(dico, dolem = dolem)
51 corpus.make_lems(lem = dolem)
53 self.parent.tree.AddAnalyse(self.conf, bold = True)
55 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
57 elif self.conf.get('matrix', False) in self.parent.history.ordermatrix :
59 matrix = Tableau(self.parent, parametres = self.parent.history.matrix[self.parent.history.ordermatrix[self.conf['matrix']]])
61 #if isinstance(parametres, dict) :
62 # tableau = Tableau(parent, parametres['ira'])
64 # tableau = Tableau(parent, parametres)
65 #tableau.parametres = self.conf
66 #tableau.dictpathout = PathOut(filename = tableau.parametres['filename'], dirout = self.conf['pathout'], analyse_type = self.conf['type'])
67 #tableau.dictpathout.basefiles(ChdTxtPathOut)
68 #tableau.read_tableau(tableau.dictpathout['db'])
69 #if self.parent.tree.IsInTree(uuid = self.conf['uuid']) :
70 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
73 self.parent.tree.AddAnalyse(self.conf, bold = True)
74 self.parent.history.addtab(self.conf)
76 def redopath(self, conf, path) :
77 conf['ira'] = os.path.realpath(path)
78 conf['pathout'] = os.path.dirname(os.path.realpath(path))
79 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
82 def opencorpus(self) :
83 log.info('open corpus')
84 if self.conf['uuid'] not in self.parent.history.corpus :
85 self.parent.history.add(self.conf)
86 log.info('add corpus to history')
87 self.parent.tree.OnItemAppend(self.conf)
88 if self.conf['uuid'] in self.parent.history.openedcorpus :
89 log.info('corpus is already opened')
90 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
92 #dial = progressbar(2)
93 #dial.Update(1, 'Ouverture du corpus')
94 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
95 #dial.Update(2, 'Fini')
97 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
98 self.opencorpus_analyses()
101 def openmatrix(self):
102 log.info('open matrix')
103 if self.conf['uuid'] not in self.parent.history.ordermatrix :
104 self.parent.history.addMatrix(self.conf)
105 log.info('add matrix to history')
106 self.parent.tree.OnItemAppend(self.conf)
107 if self.conf['uuid'] in self.parent.history.openedmatrix :
108 log.info('matrix is already opened')
109 self.doopen(self.parent.history.openedmatrix[self.conf['uuid']])
111 #dial = progressbar(2)
112 #dial.Update(1, 'Ouverture du corpus')
113 matrix = Tableau(self, parametres = self.conf)
115 self.parent.history.openedmatrix[self.conf['uuid']] = matrix
116 self.openmatrix_analyses()
118 self.parent.history.addtab(self.conf)
120 def opencorpus_analyses(self) :
121 log.info('open analysis')
122 basepath = self.conf['pathout']
124 for root, subfolders, files in os.walk(basepath) :
125 for folder in subfolders :
126 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
127 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
128 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
129 if analyse_conf['corpus'] == self.conf['uuid'] :
130 analyses.append(analyse_conf)
132 self.parent.history.addmultiple(analyses)
133 for analyse in analyses :
134 self.parent.tree.AddAnalyse(analyse, bold = False)
136 def openmatrix_analyses(self):
139 def openanalyse(self) :
140 if self.conf['corpus'] in self.parent.history.openedcorpus :
141 log.info('corpus is already opened')
142 corpus = copycorpus(self.parent.history.openedcorpus[self.conf['corpus']])
144 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
145 corpus = Corpus(self, parametres = DoConf(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']).getoptions('corpus'), read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira'])
146 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
147 self.parent.history.add(self.conf)
150 def doopen(self, corpus) :
151 if self.conf['type'] == 'corpus' :
152 #self.parent.ShowMenu(_("Text analysis"))
153 OpenCorpus(self.parent, self.conf)
154 elif self.conf['type'] == 'stat' :
155 #self.parent.ShowMenu(_("Text analysis"))
156 StatLayout(self.parent, corpus, self.conf)
157 elif self.conf['type'] == 'spec' :
158 #self.parent.ShowMenu(_("Text analysis"))
159 dolexlayout(self.parent, corpus, self.conf)
160 elif self.conf['type'] == 'alceste' :
161 #self.parent.ShowMenu(_("Text analysis"))
162 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
163 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
164 #self.parent.ShowMenu(_("Text analysis"))
165 SimiLayout(self.parent, corpus, self.conf)
166 elif self.conf['type'] == 'wordcloud' or self.conf['type'] == 'clustercloud':
167 #self.parent.ShowMenu(_("Text analysis"))
168 WordCloudLayout(self.parent, corpus, self.conf)
169 elif self.conf['type'] == 'reinertmatrix' :
170 #self.parent.ShowMenu(_("Spreadsheet analysis"))
171 OpenCHDS(self.parent, corpus, self.conf, Alceste = False)
172 elif self.conf['type'] == 'simimatrix' :
173 #self.parent.ShowMenu(_("Spreadsheet analysis"))
174 SimiMatLayout(self.parent, corpus, self.conf)
175 elif self.conf['type'] == 'proto' :
176 ProtoLayout(self.parent, corpus, self.conf)
177 elif self.conf['type'] == 'matrix' :
178 MatLayout(self.parent, corpus)
179 elif self.conf['type'] == 'freq' :
180 FreqLayout(self.parent, corpus, self.conf)
181 elif self.conf['type'] == 'chi2' :
182 Chi2Layout(self.parent, corpus, self.conf)