1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
14 #------------------------------------
15 # import des modules wx
16 #------------------------------------
19 #------------------------------------
20 # import des fichiers du projet
21 #------------------------------------
22 from analysetxt import AnalyseText
23 from guifunct import getPage, getCorpus, SelectColumn
24 from functions import sortedby, progressbar
25 from dialog import StatDialog, PrefWordCloud
26 from PrintRScript import WordCloudRScript
29 logger = logging.getLogger('iramuteq.textwordcloud')
32 class WordCloud(AnalyseText):
35 self.parametres['type'] = 'wordcloud'
41 res = self.make_option()
43 if self.parametres['mode'] == 2 :
44 self.actives = self.corpus.make_actives_limit(limit, 1)
45 self.actives += self.corpus.make_actives_limit(limit, 2)
46 elif self.parametres['mode'] == 0 :
47 self.actives = self.corpus.make_actives_limit(limit, 1)
48 elif self.parametres['mode'] == 1 :
49 self.actives = self.corpus.make_actives_limit(limit, 2)
50 dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
51 selectcol = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
53 self.dlg = progressbar(self.ira, 2)
55 script = WordCloudRScript(self)
57 self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
64 def make_option(self, fromcluster = False) :
65 dial = PrefWordCloud(self.ira, fromcluster)
67 res = dial.ShowModal()
69 if dial.format.GetSelection() == 0 :
73 self.parametres['width'] = dial.spin_L.GetValue()
74 self.parametres['height'] = dial.spin_H.GetValue()
75 self.parametres['maxword'] = dial.spin_maxword.GetValue()
76 self.parametres['mincex'] = float(dial.spin_mincex.GetValue())/float(10)
77 self.parametres['maxcex'] = float(dial.spin_maxcex.GetValue())/float(10)
78 self.parametres['col_text'] = dial.color_text.GetColour()
79 self.parametres['col_bg'] = dial.color_bg.GetColour()
80 self.parametres['mode'] = dial.typeformeschoice.GetSelection()
81 self.parametres['svg'] = svg
83 self.parametres['indice'] = dial.indice.GetSelection()
84 outgraph = os.path.join(os.path.dirname(self.pathout['zipf.png']), 'nuage_')
90 while os.path.exists(outgraph + str(nb) + end) :
92 self.parametres['graphout'] = outgraph + str(nb) + end
96 def make_wordcloud(self) :
97 act = ['\t'.join([act, repr(self.corpus.getlemeff(act))]) for act in self.actives]
98 with open(self.pathout['actives_eff.csv'], 'w', encoding='utf8') as f :
99 f.write('\n'.join(act))
102 class ClusterCloud(WordCloud):
105 print('ClusterCloud')
106 self.parametres['type'] = 'clustercloud'
109 res = self.make_option(True) #dialogue d'options de WordCloud.make_option
111 prof = self.parametres['clusterprof']
112 del self.parametres['clusterprof']
113 if self.parametres['indice'] == 0:
117 prof = [[val[0], int(round(val[tokeep]))] for val in prof]
118 with open(self.pathout['actives_eff.csv'], 'w', encoding='utf8') as f :
119 f.write('\n'.join(['\t'.join([val[0], repr(val[1])]) for val in prof]))
120 dictcol = dict([[i, val] for i, val in enumerate(prof)])
121 self.actives = [val[0] for val in prof]
122 SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
123 script = WordCloudRScript(self)
126 dialProgression = progressbar(self.ira, self.dlg)
127 self.doR(script.scriptout, dlg = dialProgression, message = 'R...')
128 dialProgression.Destroy()