2678a3a62358cb8431bdd349c0f192210d9c8067
[iramuteq] / openanalyse.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2012, Pierre Ratinaud
5 #Lisense: GNU/GPL
6
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
12 import os
13 import shelve
14 from ConfigParser import *
15 from tabsimi import DoSimi
16 from functions import BugReport, DoConf
17 import logging
18
19 log = logging.getLogger('iramuteq.openanalyse')
20
21 class OpenAnalyse():
22     def __init__(self, parent, parametres, Alceste=True, simifromprof = False):
23         #self.conf = RawConfigParser()
24         #self.conf.read(filename)
25         log.info('OpenAnalyse')
26         self.parent = parent
27         if isinstance(parametres, dict) :
28             self.conf = DoConf(parametres['ira']).getoptions()
29         else :
30             self.conf = DoConf(parametres).getoptions()
31         
32         if self.conf.get('corpus', '!!') in self.parent.history.history :
33             if self.conf.get('corpus', '!!') in self.parent.history.openedcorpus :
34                 log.info('corpus is already opened')
35                 corpus = copycorpus(self.parent.history.openedcorpus[self.conf['corpus']]) 
36             else :
37                 if os.path.exists(self.parent.history.history[self.conf['corpus']]['ira']) :
38                     corpus = Corpus(self, parametres = DoConf(self.parent.history.history[self.conf['corpus']]['ira']).getoptions('corpus'), read = self.parent.history.history[self.conf['corpus']]['ira'])
39                 self.parent.history.openedcorpus[self.conf['corpus']] = corpus
40             if self.conf.get('lem',1) :
41                corpus.make_lems(True)
42             else :
43                corpus.make_lems(False)
44         else :
45             corpus = None
46         self.doopen(corpus)
47         self.parent.history.addtab(self.conf)
48         
49     def doopen(self, corpus) :
50         print self.conf
51         if self.conf['type'] == 'corpus' :
52             self.parent.ShowMenu(_("Text analysis"))
53             OpenCorpus(self.parent, self.conf) 
54         elif self.conf['type'] == 'stat' :
55             self.parent.ShowMenu(_("Text analysis"))
56             StatLayout(self.parent, corpus, self.conf)
57         elif self.conf['type'] == 'spec' :
58             self.parent.ShowMenu(_("Text analysis"))
59             dolexlayout(self.parent, corpus, self.conf)
60         elif self.conf['type'] == 'alceste' :
61             self.parent.ShowMenu(_("Text analysis"))
62             OpenCHDS(self.parent,  corpus, self.conf, Alceste = True)
63         elif self.conf['type'] == 'simitxt' :
64             self.parent.ShowMenu(_("Text analysis"))
65             SimiLayout(self.parent, corpus, self.conf)
66         elif self.conf['type'] == 'wordcloud' :
67             self.parent.ShowMenu(_("Text analysis"))
68             WordCloudLayout(self.parent, corpus, self.conf)
69             #self.tableau = Tableau(self.parent, self.conf['ira'])
70             #self.DictPathOut=construct_simipath(self.conf['pathout'])
71             #self.tableau.dictpathout = self.DictPathOut
72             #self.tableau.read_tableau(self.tableau.dictpathout['db'])
73             #if self.tableau.parametre.get('corpus', False) :
74             #    self.corpus=corpus
75                 #self.corpus.read_corpus_from_shelves(self.DictPathOut['corpus'])
76             #    self.corpus.parametres['openpath'] = self.conf['pathout']
77             #DoSimi(self.parent, self.conf, isopen = True, filename = self.conf['ira'], gparent = self, openfromprof=False) 
78             
79 #        try :
80 #            #if self.conf['type'] in ['analyse','lexico','stat','wordcloud'] :
81 #            #    self.corpus = Corpus(parent)
82 #            if 'analyse' in self.conf.sections() :
83 #                DictPathOut=ChdTxtPathOut(os.path.dirname(filename))
84 #                self.pathout = os.path.dirname(filename)
85 #                self.DictPathOut=DictPathOut
86 #                #self.corpus = Corpus(parent)
87 #                self.corpus.dictpathout = self.DictPathOut
88 #                self.corpus.read_corpus_from_shelves(self.DictPathOut['db'])
89 #                self.corpus.parametre['analyse'] = 'alceste'
90 #                self.corpus.make_lem_type_list()
91 #    #            print 'EXTRACT NR'
92 #    #            self.corpus.extractnr()
93 #                Alceste=True
94 #                #self.corpus.save_corpus(self.corpus.dictpathout['db'])
95 #                #self.corpus.make_uci_stat()
96 #                #self.corpus.make_et_table()
97 #                #self.corpus.prof_type()
98 #                #self.corpus.make_type_tot()
99 #                #self.corpus.make_size_uci()
100 #                #self.corpus.get_stat_by_cluster()
101 #                OpenCHDS(parent, self, filename, Alceste)
102 #                self.parent.ShowMenu(_("Text analysis"))
103 #                self.parent._mgr.Update()
104 #            elif 'questionnaire' in self.conf.sections() :
105 #                self.DictPathOut=ChdTxtPathOut(os.path.dirname(filename))
106 #                self.pathout = os.path.dirname(filename)
107 #                self.tableau = Tableau(parent, filename)
108 #                self.tableau.dictpathout = self.DictPathOut
109 #                self.tableau.read_tableau(self.tableau.dictpathout['db'])
110 #                OpenCHDS(parent, self, filename, False)
111 #            elif 'simi' in self.conf.sections():
112 #                self.tableau = Tableau(parent, filename)
113 #                self.DictPathOut=construct_simipath(os.path.abspath(os.path.dirname(filename)))
114 #                self.tableau.dictpathout = self.DictPathOut
115 #                self.tableau.read_tableau(self.tableau.dictpathout['db'])
116 #                if self.tableau.parametre.get('fromtxt', False) :
117 #                    self.corpus=Corpus(parent)
118 #                    self.corpus.read_corpus_from_shelves(self.DictPathOut['corpus'])
119 #                    self.corpus.parametre['openpath'] = os.path.dirname(filename)
120 #                    self.parent.ShowMenu(_("Text analysis"))
121 #                DoSimi(parent, self.conf, isopen = True, filename = filename, gparent = self, openfromprof=simifromprof) 
122 #            elif 'lexico' in self.conf.sections():
123 #                print 'lexico'
124 #                #self.corpus = Corpus(parent)
125 #                self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
126 #                self.parent.ShowMenu(_("Text analysis"))
127 #                dolexlayout(parent, self, filename)
128 #            elif 'stat' in self.conf.sections():
129 #                print 'stat'
130 #                #self.corpus = Corpus(parent)
131 #                self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
132 #                self.parent.ShowMenu(_("Text analysis"))
133 #                StatLayout(parent, self, filename)
134 #            elif 'chd_dist_quest' in self.conf.sections():
135 #                self.DictPathOut = ChdTxtPathOut(os.path.dirname(filename))
136 #                self.pathout = os.path.dirname(filename)
137 #                self.tableau = Tableau(parent, filename)
138 #                self.tableau.dictpathout = self.DictPathOut
139 #                self.tableau.read_tableau(self.tableau.dictpathout['db'])
140 #                OpenCHDS(parent, self, filename, False)
141 #            elif 'wordcloud' in self.conf.sections() :
142 #                self.corpus.dictpathout = StatTxtPathOut(os.path.dirname(filename))
143 #                self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
144 #                self.parent.ShowMenu(_("Text analysis"))
145 #                WordCloudLayout(parent, self, filename)
146 #            if self.conf.sections()[0] in ['analyse','lexico','stat','wordcloud'] :
147 #                self.corpus.parametre['openpath'] = os.path.dirname(filename)
148 #        except :
149 #            BugReport(self.parent)
150
151