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 print 'corpus in history.corpus'
37 if self.conf['uuid'] in self.parent.history.analyses :
41 corpus = self.openanalyse()
42 if self.conf.get('lem',1) :
43 corpus.make_lems(True)
45 corpus.make_lems(False)
48 self.parent.tree.AddAnalyse(self.conf)
51 print self.parent.tree.GiveFocus(uuid = self.conf['uuid'], bold = True)
54 self.parent.history.addtab(self.conf)
56 def redopath(self, conf, path) :
57 conf['ira'] = os.path.realpath(path)
58 conf['pathout'] = os.path.dirname(os.path.realpath(path))
59 DoConf(conf['ira']).makeoptions([conf['type']], [conf])
62 def opencorpus(self) :
63 log.info('open corpus')
64 if self.conf['uuid'] not in self.parent.history.corpus :
65 self.parent.history.add(self.conf)
66 log.info('add to history')
67 self.parent.tree.OnItemAppend(self.conf)
68 if self.conf['uuid'] in self.parent.history.openedcorpus :
69 log.info('corpus is already opened')
70 self.doopen(self.parent.history.openedcorpus[self.conf['uuid']])
72 corpus = Corpus(self, parametres = self.conf, read = self.parent.history.history[self.parent.history.ordercorpus[self.conf['uuid']]]['ira'])
73 self.parent.history.openedcorpus[self.conf['uuid']] = corpus
74 self.opencorpus_analyses()
77 def opencorpus_analyses(self) :
78 basepath = self.conf['pathout']
79 for root, subfolders, files in os.walk(basepath) :
80 for folder in subfolders :
81 if os.path.exists(os.path.join(folder, 'Analyse.ira')) :
82 analyse_conf = DoConf(os.path.join(folder, 'Analyse.ira')).getoptions()
83 analyse_conf = self.redopath(analyse_conf, os.path.join(folder, 'Analyse.ira'))
84 if analyse_conf['corpus'] == self.conf['uuid'] :
85 self.parent.history.add(analyse_conf)
86 self.parent.tree.AddAnalyse(analyse_conf, bold = False)
88 def openanalyse(self) :
89 if self.conf['corpus'] in self.parent.history.openedcorpus :
90 log.info('corpus is already opened')
91 corpus = self.parent.history.openedcorpus[self.conf['corpus']]
93 if os.path.exists(self.parent.history.history[self.parent.history.ordercorpus[self.conf['corpus']]]['ira']) :
94 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'])
95 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
96 self.parent.history.add(self.conf)
99 def doopen(self, corpus) :
100 if self.conf['type'] == 'corpus' :
101 self.parent.ShowMenu(_("Text analysis"))
102 OpenCorpus(self.parent, self.conf)
103 elif self.conf['type'] == 'stat' :
104 self.parent.ShowMenu(_("Text analysis"))
105 StatLayout(self.parent, corpus, self.conf)
106 elif self.conf['type'] == 'spec' :
107 self.parent.ShowMenu(_("Text analysis"))
108 dolexlayout(self.parent, corpus, self.conf)
109 elif self.conf['type'] == 'alceste' :
110 self.parent.ShowMenu(_("Text analysis"))
111 OpenCHDS(self.parent, corpus, self.conf, Alceste = True)
112 elif self.conf['type'] == 'simitxt' or self.conf['type'] == 'clustersimitxt' :
113 self.parent.ShowMenu(_("Text analysis"))
114 SimiLayout(self.parent, corpus, self.conf)
115 elif self.conf['type'] == 'wordcloud' :
116 self.parent.ShowMenu(_("Text analysis"))
117 WordCloudLayout(self.parent, corpus, self.conf)