2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2009 Pierre Ratinaud
7 from analysetxt import AnalyseText
8 from guifunct import getPage, getCorpus, SelectColumn
9 #from ConfigParser import RawConfigParser
10 from functions import sortedby, progressbar
11 from dialog import StatDialog, PrefWordCloud
12 from PrintRScript import WordCloudRScript
13 #from ttparser import *
15 #from time import sleep
20 logger = logging.getLogger('iramuteq.textwordcloud')
23 class WordCloud(AnalyseText):
25 self.parametres['type'] = 'wordcloud'
29 res = self.make_option()
31 if self.parametres['mode'] == 2 :
32 self.actives = self.corpus.make_actives_limit(limit, 1)
33 self.actives += self.corpus.make_actives_limit(limit, 2)
34 elif self.parametres['mode'] == 0 :
35 self.actives = self.corpus.make_actives_limit(limit, 1)
36 elif self.parametres['mode'] == 1 :
37 self.actives = self.corpus.make_actives_limit(limit, 2)
38 dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
39 selectcol = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
41 self.dlg = progressbar(self.ira, 2)
43 script = WordCloudRScript(self)
45 self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
51 def make_option(self, fromcluster = False) :
52 dial = PrefWordCloud(self.ira, fromcluster)
54 res = dial.ShowModal()
56 if dial.format.GetSelection() == 0 :
60 self.parametres['width'] = dial.spin_L.GetValue()
61 self.parametres['height'] = dial.spin_H.GetValue()
62 self.parametres['maxword'] = dial.spin_maxword.GetValue()
63 self.parametres['mincex'] = float(dial.spin_mincex.GetValue())/float(10)
64 self.parametres['maxcex'] = float(dial.spin_maxcex.GetValue())/float(10)
65 self.parametres['col_text'] = dial.color_text.GetColour()
66 self.parametres['col_bg'] = dial.color_bg.GetColour()
67 self.parametres['mode'] = dial.typeformeschoice.GetSelection()
68 self.parametres['svg'] = svg
70 self.parametres['indice'] = dial.indice.GetSelection()
71 outgraph = os.path.join(os.path.dirname(self.pathout['zipf.png']), 'nuage_')
77 while os.path.exists(outgraph + str(nb) + end) :
79 self.parametres['graphout'] = outgraph + str(nb) + end
83 def make_wordcloud(self) :
84 act = ['\t'.join([act, `self.corpus.getlemeff(act)`]) for act in self.actives]
85 with open(self.pathout['actives_eff.csv'], 'w') as f :
86 f.write('\n'.join(act).encode(self.ira.syscoding))
89 class ClusterCloud(WordCloud) :
91 self.parametres['type'] = 'clustercloud'
94 res = self.make_option(True)
96 prof = self.parametres['clusterprof']
97 del self.parametres['clusterprof']
98 if self.parametres['indice'] == 0 :
102 prof = [[val[0], int(round(val[tokeep]))] for val in prof]
103 with open(self.pathout['actives_eff.csv'], 'w') as f :
104 f.write('\n'.join(['\t'.join([val[0], `val[1]`]) for val in prof]).encode(self.ira.syscoding))
105 dictcol = dict([[i, val] for i, val in enumerate(prof)])
106 self.actives = [val[0] for val in prof]
107 SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
108 script = WordCloudRScript(self)
110 self.doR(script.scriptout, dlg = self.dlg, message = 'R...')