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 log.info('OpenAnalyse')
25 if isinstance(parametres, dict) :
26 self.conf = DoConf(parametres['ira']).getoptions()
27 self.path = parametres['ira']
29 self.conf = DoConf(parametres).getoptions()
30 self.path = parametres
31 self.conf = self.redopath(self.conf, parametres)
33 if self.conf['type'] == 'corpus' :
34 corpus = self.opencorpus()
35 elif self.conf['corpus'] in self.parent.history.corpus :
36 if self.conf['uuid'] in self.parent.history.analyses :
40 corpus = self.openanalyse()
41 if self.conf.get('lem',1) :
42 corpus.make_lems(True)
44 corpus.make_lems(False)
46 self.parent.tree.AddAnalyse(self.conf, bold = True)
48 self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
52 self.parent.history.addtab(self.conf)
54 def redopath(self, conf, path) :
55 conf['ira'] = os.path.realpath(path)
56 conf['pathout'] = os.path.dirname(os.path.realpath(path))
57 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
60 def opencorpus(self) :
61 log.info('open corpus')
62 if self.conf['uuid'] not in self.parent.history.corpus :
63 self.parent.history.add(self.conf)
64 log.info('add to history')
65 self.parent.tree.OnItemAppend(self.conf)
66 if self.conf['uuid'] in self.parent.history.openedcorpus :
67 log.info('corpus is already opened')
68 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
70 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
71 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
72 self.opencorpus_analyses()
75 def opencorpus_analyses(self) :
76 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 self.parent.history.add(analyse_conf)
84 self.parent.tree.AddAnalyse(analyse_conf, bold = False)
86 def openanalyse(self) :
87 if self.conf['corpus'] in self.parent.history.openedcorpus :
88 log.info('corpus is already opened')
89 corpus = self.parent.history.openedcorpus[self.conf['corpus']]
91 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
92 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'])
93 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
94 self.parent.history.add(self.conf)
97 def doopen(self, corpus) :
98 if self.conf['type'] == 'corpus' :
99 self.parent.ShowMenu(_("Text analysis"))
100 OpenCorpus(self.parent, self.conf)
101 elif self.conf['type'] == 'stat' :
102 self.parent.ShowMenu(_("Text analysis"))
103 StatLayout(self.parent, corpus, self.conf)
104 elif self.conf['type'] == 'spec' :
105 self.parent.ShowMenu(_("Text analysis"))
106 dolexlayout(self.parent, corpus, self.conf)
107 elif self.conf['type'] == 'alceste' :
108 self.parent.ShowMenu(_("Text analysis"))
109 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
110 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
111 self.parent.ShowMenu(_("Text analysis"))
112 SimiLayout(self.parent, corpus, self.conf)
113 elif self.conf['type'] == 'wordcloud' :
114 self.parent.ShowMenu(_("Text analysis"))
115 WordCloudLayout(self.parent, corpus, self.conf)