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, copycorpus
10 from tableau import Tableau
13 from tabsimi import DoSimi
14 from functions import BugReport, DoConf
17 log = logging.getLogger('iramuteq.openanalyse')
20 def __init__(self, parent, parametres, Alceste=True, simifromprof = False):
21 log.info('OpenAnalyse')
23 if isinstance(parametres, dict) :
24 self.conf = DoConf(parametres['ira']).getoptions()
25 self.path = parametres['ira']
27 self.conf = DoConf(parametres).getoptions()
28 self.path = parametres
29 self.conf = self.redopath(self.conf, parametres)
31 if self.conf['type'] == 'corpus' :
32 corpus = self.opencorpus()
33 elif self.conf['corpus'] in self.parent.history.corpus :
34 if self.conf['uuid'] in self.parent.history.analyses :
38 corpus = self.openanalyse()
39 if self.conf.get('lem',1) :
40 corpus.make_lems(True)
42 corpus.make_lems(False)
44 self.parent.tree.AddAnalyse(self.conf, bold = True)
46 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
50 self.parent.history.addtab(self.conf)
52 def redopath(self, conf, path) :
53 conf['ira'] = os.path.realpath(path)
54 conf['pathout'] = os.path.dirname(os.path.realpath(path))
55 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
58 def opencorpus(self) :
59 log.info('open corpus')
60 if self.conf['uuid'] not in self.parent.history.corpus :
61 self.parent.history.add(self.conf)
62 log.info('add to history')
63 self.parent.tree.OnItemAppend(self.conf)
64 if self.conf['uuid'] in self.parent.history.openedcorpus :
65 log.info('corpus is already opened 1')
66 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
68 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
69 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
70 self.opencorpus_analyses()
73 def opencorpus_analyses(self) :
74 log.info('open analysis')
75 basepath = self.conf['pathout']
77 for root, subfolders, files in os.walk(basepath) :
78 for folder in subfolders :
79 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
80 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
81 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
82 if analyse_conf['corpus'] == self.conf['uuid'] :
83 analyses.append(analyse_conf)
85 self.parent.history.addmultiple(analyses)
86 for analyse in analyses :
87 self.parent.tree.AddAnalyse(analyse, bold = False)
89 def openanalyse(self) :
90 if self.conf['corpus'] in self.parent.history.openedcorpus :
91 log.info('corpus is already opened 2')
92 corpus = self.parent.history.openedcorpus[self.conf['corpus']]
94 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
95 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'])
96 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
97 self.parent.history.add(self.conf)
100 def doopen(self, corpus) :
101 if self.conf['type'] == 'corpus' :
102 self.parent.ShowMenu(_("Text analysis"))
103 OpenCorpus(self.parent, self.conf)
104 elif self.conf['type'] == 'stat' :
105 self.parent.ShowMenu(_("Text analysis"))
106 StatLayout(self.parent, corpus, self.conf)
107 elif self.conf['type'] == 'spec' :
108 self.parent.ShowMenu(_("Text analysis"))
109 dolexlayout(self.parent, corpus, self.conf)
110 elif self.conf['type'] == 'alceste' :
111 self.parent.ShowMenu(_("Text analysis"))
112 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
113 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
114 self.parent.ShowMenu(_("Text analysis"))
115 SimiLayout(self.parent, corpus, self.conf)
116 elif self.conf['type'] == 'wordcloud' :
117 self.parent.ShowMenu(_("Text analysis"))
118 WordCloudLayout(self.parent, corpus, self.conf)