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, CreateIraFile, exec_rcode, check_Rresult, MessageImage
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'
28 res = self.make_option()
30 if self.parametres['mode'] == 2 :
31 self.actives = self.corpus.make_actives_limit(limit, 1)
32 self.actives += self.corpus.make_actives_limit(limit, 2)
33 elif self.parametres['mode'] == 0 :
34 self.actives = self.corpus.make_actives_limit(limit, 1)
35 elif self.parametres['mode'] == 1 :
36 self.actives = self.corpus.make_actives_limit(limit, 2)
37 dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
38 SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
40 script = WordCloudRScript(self)
42 self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
46 def make_option(self, fromcluster = False) :
47 dial = PrefWordCloud(self.ira, fromcluster)
49 res = dial.ShowModal()
51 if dial.format.GetSelection() == 0 :
55 self.parametres['width'] = dial.spin_L.GetValue()
56 self.parametres['height'] = dial.spin_H.GetValue()
57 self.parametres['maxword'] = dial.spin_maxword.GetValue()
58 self.parametres['mincex'] = float(dial.spin_mincex.GetValue())/float(10)
59 self.parametres['maxcex'] = float(dial.spin_maxcex.GetValue())/float(10)
60 self.parametres['col_text'] = dial.color_text.GetColour()
61 self.parametres['col_bg'] = dial.color_bg.GetColour()
62 self.parametres['mode'] = dial.typeformeschoice.GetSelection()
63 self.parametres['svg'] = svg
65 self.parametres['indice'] = dial.indice.GetSelection()
66 outgraph = os.path.join(os.path.dirname(self.pathout['zipf.png']), 'nuage_')
72 while os.path.exists(outgraph + str(nb) + end) :
74 self.parametres['graphout'] = outgraph + str(nb) + end
78 def make_wordcloud(self) :
79 act = ['\t'.join([act, `self.corpus.getlemeff(act)`]) for act in self.actives]
80 with open(self.pathout['actives_eff.csv'], 'w') as f :
81 f.write('\n'.join(act).encode(self.ira.syscoding))
84 class ClusterCloud(WordCloud) :
86 self.parametres['type'] = 'clustercloud'
89 res = self.make_option(True)
91 prof = self.parametres['clusterprof']
92 del self.parametres['clusterprof']
93 if self.parametres['indice'] == 0 :
97 prof = [[val[0], int(round(val[tokeep]))] for val in prof]
98 with open(self.pathout['actives_eff.csv'], 'w') as f :
99 f.write('\n'.join(['\t'.join([val[0], `val[1]`]) for val in prof]).encode(self.ira.syscoding))
100 dictcol = dict([[i, val] for i, val in enumerate(prof)])
101 self.actives = [val[0] for val in prof]
102 SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
103 script = WordCloudRScript(self)
105 self.doR(script.scriptout, dlg = self.dlg, message = 'R...')