lot of things :)
[iramuteq] / textwordcloud.py
index c7ca3f1..bc875bc 100644 (file)
@@ -43,11 +43,15 @@ class WordCloud(AnalyseText):
         else :
             return 'NOK'
     
-    def make_option(self) :
-        dial = PrefWordCloud(self.ira)
+    def make_option(self, fromcluster = False) :
+        dial = PrefWordCloud(self.ira, fromcluster)
         dial.CenterOnParent()
         res = dial.ShowModal()
         if res == wx.ID_OK :
+            if dial.format.GetSelection() == 0 :
+                svg = 0
+            else :
+                svg = 1
             self.parametres['width'] = dial.spin_L.GetValue()
             self.parametres['height'] = dial.spin_H.GetValue()
             self.parametres['maxword'] = dial.spin_maxword.GetValue()
@@ -56,16 +60,48 @@ class WordCloud(AnalyseText):
             self.parametres['col_text'] = dial.color_text.GetColour()
             self.parametres['col_bg'] = dial.color_bg.GetColour()
             self.parametres['mode'] = dial.typeformeschoice.GetSelection()
+            self.parametres['svg'] = svg
+            if fromcluster :
+                self.parametres['indice'] = dial.indice.GetSelection()
             outgraph = os.path.join(os.path.dirname(self.pathout['zipf.png']), 'nuage_')
             nb = 1
-            while os.path.exists(outgraph + str(nb) + '.png') :
+            if svg :
+                end = '.svg'
+            else :
+                end = '.png'
+            while os.path.exists(outgraph + str(nb) + end) :
                 nb += 1
-            self.parametres['graphout'] = outgraph + str(nb) + '.png'
+            self.parametres['graphout'] = outgraph + str(nb) + end
         dial.Destroy()
         return res
 
-
     def make_wordcloud(self) :
         act = ['\t'.join([act, `self.corpus.getlemeff(act)`]) for act in self.actives]
         with open(self.pathout['actives_eff.csv'], 'w') as f :
             f.write('\n'.join(act).encode(self.ira.syscoding))
+
+
+class ClusterCloud(WordCloud) :
+    def doanalyse(self) :
+        self.parametres['type'] = 'clustercloud'
+        #FIXME
+        limit = 2
+        res = self.make_option(True)
+        if res == wx.ID_OK :
+            prof = self.parametres['clusterprof']
+            del self.parametres['clusterprof']
+            if self.parametres['indice'] == 0 :
+                tokeep = 1
+            else : 
+                tokeep = 2
+            prof = [[val[0], int(round(val[tokeep]))] for val in prof]
+            with open(self.pathout['actives_eff.csv'], 'w') as f :
+                f.write('\n'.join(['\t'.join([val[0], `val[1]`]) for val in prof]).encode(self.ira.syscoding))
+            dictcol = dict([[i, val] for i, val in enumerate(prof)])
+            self.actives = [val[0] for val in prof]
+            SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], dlg = True)
+            script = WordCloudRScript(self)
+            script.make_script()
+            self.doR(script.scriptout, dlg = self.dlg, message = 'R...')
+        else :
+            return 'NOK'