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, LabbeLayout
9 from corpus import Corpus, copycorpus
10 from tableau import Tableau
12 from functions import DoConf, ReadDicoAsDico
13 from tableau import Tableau
16 log = logging.getLogger('iramuteq.openanalyse')
19 def __init__(self, parent, parametres, Alceste=True, simifromprof = False):
20 log.info('OpenAnalyse')
22 if isinstance(parametres, dict) :
23 self.conf = DoConf(parametres['ira']).getoptions()
24 self.path = parametres['ira']
26 self.conf = DoConf(parametres).getoptions()
27 self.path = parametres
28 self.conf = self.redopath(self.conf, parametres)
30 if self.conf['type'] == 'corpus' :
31 corpus = self.opencorpus()
32 elif self.conf['type'] == 'matrix' :
33 matrix = self.openmatrix()
34 elif self.conf.get('corpus', False) in self.parent.history.corpus :
35 if self.conf['uuid'] in self.parent.history.analyses :
39 corpus = self.openanalyse()
41 if self.conf.get('lem',1) :
45 if self.conf.get('dictionary', False) :
46 dico = ReadDicoAsDico(self.conf['dictionary'])
47 corpus.make_lems_from_dict(dico, dolem = dolem)
49 corpus.make_lems(lem = dolem)
51 self.parent.tree.AddAnalyse(self.conf, bold = True)
53 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
55 elif self.conf.get('matrix', False) in self.parent.history.ordermatrix :
57 matrix = Tableau(self.parent, parametres = self.parent.history.matrix[self.parent.history.ordermatrix[self.conf['matrix']]])
59 #if isinstance(parametres, dict) :
60 # tableau = Tableau(parent, parametres['ira'])
62 # tableau = Tableau(parent, parametres)
63 #tableau.parametres = self.conf
64 #tableau.dictpathout = PathOut(filename = tableau.parametres['filename'], dirout = self.conf['pathout'], analyse_type = self.conf['type'])
65 #tableau.dictpathout.basefiles(ChdTxtPathOut)
66 #tableau.read_tableau(tableau.dictpathout['db'])
67 #if self.parent.tree.IsInTree(uuid = self.conf['uuid']) :
68 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
71 self.parent.tree.AddAnalyse(self.conf, bold = True)
72 self.parent.history.addtab(self.conf)
74 def redopath(self, conf, path) :
75 conf['ira'] = os.path.realpath(path)
76 conf['pathout'] = os.path.dirname(os.path.realpath(path))
77 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
80 def opencorpus(self) :
81 log.info('open corpus')
82 if self.conf['uuid'] not in self.parent.history.corpus :
83 self.parent.history.add(self.conf)
84 log.info('add corpus to history')
85 self.parent.tree.OnItemAppend(self.conf)
86 if self.conf['uuid'] in self.parent.history.openedcorpus :
87 log.info('corpus is already opened')
88 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
90 #dial = progressbar(2)
91 #dial.Update(1, 'Ouverture du corpus')
92 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
93 #dial.Update(2, 'Fini')
95 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
96 self.opencorpus_analyses()
100 log.info('open matrix')
101 if self.conf['uuid'] not in self.parent.history.ordermatrix :
102 self.parent.history.addMatrix(self.conf)
103 log.info('add matrix to history')
104 self.parent.tree.OnItemAppend(self.conf)
105 if self.conf['uuid'] in self.parent.history.openedmatrix :
106 log.info('matrix is already opened')
107 self.doopen(self.parent.history.openedmatrix[self.conf['uuid']])
109 #dial = progressbar(2)
110 #dial.Update(1, 'Ouverture du corpus')
111 matrix = Tableau(self, parametres = self.conf)
113 self.parent.history.openedmatrix[self.conf['uuid']] = matrix
114 self.openmatrix_analyses()
116 self.parent.history.addtab(self.conf)
118 def opencorpus_analyses(self) :
119 log.info('open analysis')
120 basepath = self.conf['pathout']
122 for root, subfolders, files in os.walk(basepath) :
123 for folder in subfolders :
124 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
125 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
126 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
127 if analyse_conf['corpus'] == self.conf['uuid'] :
128 analyses.append(analyse_conf)
130 self.parent.history.addmultiple(analyses)
131 for analyse in analyses :
132 self.parent.tree.AddAnalyse(analyse, bold = False)
134 def openmatrix_analyses(self):
137 def openanalyse(self) :
138 if self.conf['corpus'] in self.parent.history.openedcorpus :
139 log.info('corpus is already opened')
140 corpus = copycorpus(self.parent.history.openedcorpus[self.conf['corpus']])
142 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
143 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'])
144 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
145 self.parent.history.add(self.conf)
148 def doopen(self, corpus) :
149 if self.conf['type'] == 'corpus' :
150 OpenCorpus(self.parent, self.conf)
151 elif self.conf['type'] == 'stat' :
152 StatLayout(self.parent, corpus, self.conf)
153 elif self.conf['type'] == 'spec' :
154 dolexlayout(self.parent, corpus, self.conf)
155 elif self.conf['type'] == 'labbe' :
156 LabbeLayout(self.parent, corpus, self.conf)
157 elif self.conf['type'] == 'alceste' :
158 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
159 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
160 SimiLayout(self.parent, corpus, self.conf)
161 elif self.conf['type'] == 'wordcloud' or self.conf['type'] == 'clustercloud':
162 WordCloudLayout(self.parent, corpus, self.conf)
163 elif self.conf['type'] == 'reinertmatrix' :
164 OpenCHDS(self.parent, corpus, self.conf, Alceste = False)
165 elif self.conf['type'] == 'simimatrix' or self.conf['type'] == 'simiclustermatrix':
166 SimiMatLayout(self.parent, corpus, self.conf)
167 elif self.conf['type'] == 'proto' :
168 ProtoLayout(self.parent, corpus, self.conf)
169 elif self.conf['type'] == 'matrix' :
170 MatLayout(self.parent, corpus)
171 elif self.conf['type'] == 'freq' or self.conf['type'] == 'freqmulti':
172 FreqLayout(self.parent, corpus, self.conf)
173 elif self.conf['type'] == 'chi2' or self.conf['type'] == 'chi2mcnemar':
174 Chi2Layout(self.parent, corpus, self.conf)