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
9 from corpus import Corpus, copycorpus
10 from tableau import Tableau
13 #from tabsimi import DoSimi
14 from functions import DoConf
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.get('corpus', False) in self.parent.history.corpus :
35 if self.conf['uuid'] in self.parent.history.analyses :
39 corpus = self.openanalyse()
40 if self.conf.get('lem',1) :
41 corpus.make_lems(True)
43 corpus.make_lems(False)
45 self.parent.tree.AddAnalyse(self.conf, bold = True)
47 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
51 if isinstance(parametres, dict) :
52 tableau = Tableau(parent, parametres['ira'])
54 tableau = Tableau(parent, parametres)
55 tableau.parametres = self.conf
56 tableau.dictpathout = PathOut(filename = tableau.parametres['filename'], dirout = self.conf['pathout'], analyse_type = self.conf['type'])
57 tableau.dictpathout.basefiles(ChdTxtPathOut)
58 tableau.read_tableau(tableau.dictpathout['db'])
59 if self.parent.tree.IsInTree(uuid = self.conf['uuid']) :
60 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
62 self.parent.tree.AddAnalyse(self.conf, bold = True)
64 self.parent.history.addtab(self.conf)
66 def redopath(self, conf, path) :
67 conf['ira'] = os.path.realpath(path)
68 conf['pathout'] = os.path.dirname(os.path.realpath(path))
69 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
72 def opencorpus(self) :
73 log.info('open corpus')
74 if self.conf['uuid'] not in self.parent.history.corpus :
75 self.parent.history.add(self.conf)
76 log.info('add corpus to history')
77 self.parent.tree.OnItemAppend(self.conf)
78 if self.conf['uuid'] in self.parent.history.openedcorpus :
79 log.info('corpus is already opened')
80 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
82 #dial = progressbar(2)
83 #dial.Update(1, 'Ouverture du corpus')
84 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
85 #dial.Update(2, 'Fini')
87 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
88 self.opencorpus_analyses()
91 def opencorpus_analyses(self) :
92 log.info('open analysis')
93 basepath = self.conf['pathout']
95 for root, subfolders, files in os.walk(basepath) :
96 for folder in subfolders :
97 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
98 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
99 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
100 if analyse_conf['corpus'] == self.conf['uuid'] :
101 analyses.append(analyse_conf)
103 self.parent.history.addmultiple(analyses)
104 for analyse in analyses :
105 self.parent.tree.AddAnalyse(analyse, bold = False)
107 def openanalyse(self) :
108 if self.conf['corpus'] in self.parent.history.openedcorpus :
109 log.info('corpus is already opened')
110 corpus = copycorpus(self.parent.history.openedcorpus[self.conf['corpus']])
112 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
113 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'])
114 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
115 self.parent.history.add(self.conf)
118 def doopen(self, corpus) :
119 if self.conf['type'] == 'corpus' :
120 self.parent.ShowMenu(_("Text analysis"))
121 OpenCorpus(self.parent, self.conf)
122 elif self.conf['type'] == 'stat' :
123 self.parent.ShowMenu(_("Text analysis"))
124 StatLayout(self.parent, corpus, self.conf)
125 elif self.conf['type'] == 'spec' :
126 self.parent.ShowMenu(_("Text analysis"))
127 dolexlayout(self.parent, corpus, self.conf)
128 elif self.conf['type'] == 'alceste' :
129 self.parent.ShowMenu(_("Text analysis"))
130 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
131 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
132 self.parent.ShowMenu(_("Text analysis"))
133 SimiLayout(self.parent, corpus, self.conf)
134 elif self.conf['type'] == 'wordcloud' or self.conf['type'] == 'clustercloud':
135 self.parent.ShowMenu(_("Text analysis"))
136 WordCloudLayout(self.parent, corpus, self.conf)
137 elif self.conf['type'] == 'gnepamatrix' :
138 #self.parent.ShowMenu(_("Spreadsheet analysis"))
139 OpenCHDS(self.parent, corpus, self.conf, Alceste = False)
140 elif self.conf['type'] == 'simimatrix' :
141 #self.parent.ShowMenu(_("Spreadsheet analysis"))
142 SimiMatLayout(self.parent, corpus, self.conf)
143 elif self.conf['type'] == 'proto' :
144 ProtoLayout(self.parent, corpus, self.conf)