From: pierre Date: Tue, 25 Nov 2014 22:55:26 +0000 (+0100) Subject: ... X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=commitdiff_plain;h=54bbc5135afebc8bcc00973fd25fae383f27bdf4;hp=c440e446cdf3ff08f6bcd37c5061da3c5f29dc37 ... Merge branch 'master' of http://www.iramuteq.org/git/iramuteq --- diff --git a/PrintRScript.py b/PrintRScript.py index 606056d..deaddf5 100644 --- a/PrintRScript.py +++ b/PrintRScript.py @@ -319,7 +319,7 @@ def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10): fileout.write(txt) fileout.close() -def AlcesteTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar): +def ReinertTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar): txt = "clnb<-%i\n" % clnb txt += """ source("%s") @@ -704,7 +704,7 @@ class PrintSimiScript(PrintRScript) : self.packages(['igraph', 'proxy', 'Matrix']) self.sources([self.analyse.parent.RscriptsPath['simi'], self.analyse.parent.RscriptsPath['Rgraph']]) txt = '' - if not self.parametres['keep_coord'] and not self.parametres['type'] == 'simimatrix': + if not self.parametres['keep_coord'] and not (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix') : txt += """ dm.path <- "%s" cn.path <- "%s" @@ -740,7 +740,7 @@ class PrintSimiScript(PrintRScript) : index <- which(colnames(dm) == forme) } """ - elif not self.parametres['keep_coord'] and self.parametres['type'] == 'simimatrix' : + elif not self.parametres['keep_coord'] and (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix'): txt += """ dm.path <- "%s" selected.col <- "%s" @@ -909,7 +909,16 @@ class PrintSimiScript(PrintRScript) : if self.parametres['seuil_ok'] : seuil = str(self.parametres['seuil']) else : seuil = 'NULL' - + + if not self.parametres.get('edgecurved', False) : + ec = 'FALSE' + else : + ec = 'TRUE' + + txt += """ + edge.curved <- %s + """ % ec + cols = str(self.parametres['cols']).replace(')',', max=255)') cola = str(self.parametres['cola']).replace(')',',max=255)') @@ -1072,7 +1081,7 @@ class PrintSimiScript(PrintRScript) : """ else : #print self.parametres - if (self.parametres['type'] == 'clustersimitxt' and self.parametres.get('tmpchi', False)) or (self.parametres['type'] == 'simimatrix' and 'tmpchi' in self.parametres): + if (self.parametres['type'] == 'clustersimitxt' and self.parametres.get('tmpchi', False)) or (self.parametres['type'] in ['simimatrix','simiclustermatrix'] and 'tmpchi' in self.parametres): txt += """ lchi <- read.table("%s") lchi <- lchi[,1] @@ -1080,7 +1089,7 @@ class PrintSimiScript(PrintRScript) : txt += """ lchi <- lchi[sel.col] """ - if self.parametres['type'] == 'clustersimitxt' and self.parametres.get('cexfromchi', False) : + if self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix'] and self.parametres.get('cexfromchi', False) : txt += """ label.cex <- norm.vec(lchi, vcexminmax[1], vcexminmax[2]) """ @@ -1092,7 +1101,7 @@ class PrintSimiScript(PrintRScript) : label.cex <- graph.simi$label.cex } """ - if (self.parametres['type'] == 'clustersimitxt' or self.parametres['type'] == 'simimatrix') and self.parametres.get('sfromchi', False): + if (self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix']) and self.parametres.get('sfromchi', False): txt += """ vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2]) if (!length(vertex.size)) vertex.size <- 0 @@ -1123,7 +1132,7 @@ class PrintSimiScript(PrintRScript) : vertex.label.color <- colm[membership(com)] } } - coords <- plot.simi(graph.simi, p.type='%s',filename="%s", vertex.label = label.v, edge.label = label.e, vertex.col = vertex.col, vertex.label.color = vertex.label.color, vertex.label.cex=label.cex, vertex.size = vertex.size, edge.col = cola, leg=leg, width = width, height = height, alpha = alpha, movie = film, svg = svg) + coords <- plot.simi(graph.simi, p.type='%s',filename="%s", vertex.label = label.v, edge.label = label.e, vertex.col = vertex.col, vertex.label.color = vertex.label.color, vertex.label.cex=label.cex, vertex.size = vertex.size, edge.col = cola, leg=leg, width = width, height = height, alpha = alpha, movie = film, edge.curved = edge.curved, svg = svg) save.image(file="%s") """ % (type, self.filename, ffr(self.pathout['RData'])) @@ -1213,6 +1222,19 @@ class TgenSpecScript(PrintRScript): """ % ffr(self.pathout['tgenspec.csv']) self.add(txt) +class TgenProfScript(PrintRScript): + def make_script(self): + self.sources([self.analyse.ira.RscriptsPath['chdfunct']]) + txt = """ + tgen <- read.csv2("%s", row.names = 1, sep = '\\t') + """ % ffr(self.parametres['tgeneff']) + txt += """ + res <- build.prof.tgen(tgen) + write.table(res$chi2, file = "%s", sep='\\t', col.names = NA) + write.table(res$pchi2, file = "%s", sep='\\t', col.names = NA) + """ % (ffr(self.pathout['tgenchi2.csv']), ffr(self.pathout['tgenpchi2.csv'])) + self.add(txt) + class FreqMultiScript(PrintRScript): def make_script(self): self.sources([self.analyse.parent.RscriptsPath['Rgraph']]) diff --git a/ProfList.py b/ProfList.py index 7b593c6..b8d368c 100644 --- a/ProfList.py +++ b/ProfList.py @@ -21,7 +21,7 @@ import wx.lib.mixins.listctrl as listmix from listlex import ListForSpec from chemins import ConstructPathOut, ffr from dialog import PrefExport, PrefUCECarac, SearchDial, message, MessageImage, BarFrame -from tableau import Tableau +from tableau import Tableau, copymatrix from search_tools import SearchFrame import webbrowser #import cStringIO @@ -32,6 +32,7 @@ from PrintRScript import barplot from textclassechd import ClasseCHD from shutil import copyfile from operator import itemgetter +from copy import copy #--------------------------------------------------------------------------- class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): @@ -43,6 +44,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col self.Source = gparent self.cl = cl self.var_mod = {} + self.them_mod = {} line1 = profclasse.pop(0) classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****'] @@ -276,6 +278,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col self.idexport = wx.NewId() self.idexporttropes = wx.NewId() self.idexportowledge = wx.NewId() + self.onmaketgen = wx.NewId() # self.export_classes = wx.NewId() self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1) @@ -300,6 +303,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport) self.Bind(wx.EVT_MENU, self.onexporttropes, id = self.idexporttropes) self.Bind(wx.EVT_MENU, self.onexportowledge, id = self.idexportowledge) + self.Bind(wx.EVT_MENU, self.OnMakeTgen, id=self.onmaketgen) # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes) # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) @@ -318,7 +322,8 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col menu_conc.Append(self.popupID2, u"dans les segments de texte de la classe") menu_conc.Append(self.popupID3, u"dans les segments de texte classés") menu_conc.Append(self.popupID4, u"dans tous les segments de texte") - menu.AppendMenu(-1, u"Concordancier", menu_conc) + menu.AppendMenu(-1, u"Concordancier", menu_conc) + menu.Append(self.onmaketgen, _(u"Make Tgen").decode('utf8')) menu_cnrtl = wx.Menu() menu_cnrtl.Append(self.popupID5, u"Définition") menu_cnrtl.Append(self.popupID6, u"Etymologie") @@ -353,7 +358,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col menu.Append(self.pop2, u"Chi2 par classe") menu.Append(self.pop3, u"Chi2 modalités de la variable") menu.AppendSeparator() - menu.Append(self.pop1, u"Graph de la classe") + menu.Append(self.pop1, u"Graphe de la classe") self.PopupMenu(menu) menu.Destroy() @@ -361,7 +366,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col if 'corpus' in dir(self.Source): corpus = self.Source.corpus prof = [[self.la[i], self.lchi[i], self.lfreq[i]] for i, val in enumerate(self.la)] - parametres = self.Source.parametres + parametres = copy(self.Source.parametres) parametres['clusterprof'] = prof parametres['type'] = 'clustercloud' parametres['prof'] = self.Source.pathout['actprof_classe_%i.csv' % self.cl] @@ -416,15 +421,30 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col words.append(self.getColumnText(last, 6)) return words - def quest_var_mod(self, evt) : + def quest_var_mod(self, evt) : + word = self.getselectedwords()[0] + if len(word.split('_')) <= 1 : + dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING) + dial.CenterOnParent() + dial.ShowModal() + dial.Destroy() + return + if 'corpus' in dir(self.Source): corpus = self.Source.corpus - if self.var_mod == {} : - self.var_mod = self.Source.corpus.make_etoiles_dict() + if word.startswith(u'-*') : + if self.them_mod == {} : + self.them_mod = self.Source.corpus.make_theme_dict() + var_mod = self.them_mod + else : + if self.var_mod == {} : + self.var_mod = self.Source.corpus.make_etoiles_dict() + var_mod = self.var_mod else : corpus = self.Source.tableau if self.var_mod == {} : self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups]) + var_mod = self.var_mod with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f : chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f] title = chistable[0] @@ -432,36 +452,25 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col chistable.pop(0) vchistable = [line[1:] for line in chistable] fchistable = [line[0] for line in chistable] - word = self.getselectedwords()[0] - if len(word.split('_')) > 1 : - var = word.split('_') - #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]] - words = [word for word in self.var_mod[var[0]]] - words.sort() - tableout = [] - kwords = [] - for word in words : - if word in fchistable : - tableout.append(vchistable[fchistable.index(word)]) - kwords.append(word) - BarFrame(self.Source.parent, tableout, title, kwords) -# tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR) -# txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph) -# tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR) -# file = open(tmpscript,'w') -# file.write(txt) -# file.close() -# exec_rcode(self.Source.parent.RPath, tmpscript, wait = True) -# win = MessageImage(self,u"Graphique", size=(700, 500)) -# win.addsaveimage(tmpgraph) -# txt = "" % tmpgraph -# win.HtmlPage.SetPage(txt) -# win.Show(True) - else : - dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING) + + var = word.split('_') + #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]] + try : + words = [word for word in var_mod[var[0]]] + except KeyError: + dial = wx.MessageDialog(self, _(u"This is not a meta-data"), u"Problème", wx.OK | wx.ICON_WARNING) dial.CenterOnParent() dial.ShowModal() dial.Destroy() + return + words.sort() + tableout = [] + kwords = [] + for word in words : + if word in fchistable : + tableout.append(vchistable[fchistable.index(word)]) + kwords.append(word) + BarFrame(self.Source.parent, tableout, title, kwords) def quest_simi(self, evt) : tableau = self.Source.tableau @@ -507,16 +516,22 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col 'com' : 0, 'communities' : 0, 'halo' : 0, - 'tmpchi': self.tmpchi + 'tmpchi': self.tmpchi, + 'fromprof' : True, + 'edgecurved' : True, } act = {} + tableau = copymatrix(tableau) tableau.chi = {} tableau.lchi = self.lchi - tableau.parametres['fromprof'] = True + #tableau.parametres['fromprof'] = True for i, val in enumerate(self.la) : act[val] = [self.lfreq[i]] tableau.chi[val] = [self.lchi[i]] - self.parent.SimiCluster(parametres = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act, tableau = tableau) + paramsimi['listactives'] = copy(self.la) + paramsimi['actives'] = copy(act) + paramsimi['pathout'] = pathout + self.parent.SimiCluster(parametres = paramsimi, fromprof = ffr(self.filename), tableau = tableau) def onwordgraph(self, evt): word = self.getColumnText(self.GetFirstSelected(), 6) @@ -603,7 +618,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col ucis_txt, ucestxt = doconcorde(corpus, nuces, self.la, uci = uci) items = dict([[i, '
'.join([ucis_txt[i], '
score : %.2f

' % ntab2[i][0], ucestxt[i]])] for i, uce in enumerate(nuces)]) dlg.Update(4, u'texte...') - win = message(self, items, u"Segments de texte caractéristiques - Classe %i" % self.cl, (750, 600)) + win = message(self, items, u"Segments de texte caractéristiques - Classe %i" % self.cl, (750, 600), uceids = nuces) #win.html = '\n' + '
'.join(['
'.join([ucis_txt[i], '
score : %.2f
' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n' #win.HtmlPage.SetPage(win.html) dlg.Destroy() @@ -627,28 +642,6 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col nbcl = len(title) nbwords = len(words) BarFrame(self.Source.parent, tableout, title, words) -# txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph) -# #print 'ATTENTION TEST R' -# #txt = """ -# #sink('/Users/pierre/Desktop/qdfqsdfqsdfqsdf.txt') -# #Sys.getlocale() -# #sink() -# #""" -# tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR) -# file = open(tmpscript,'w') -# file.write(txt) -# file.close() -# exec_rcode(self.Source.parent.RPath, tmpscript, wait = True) -# w = 100 + (20 * nbwords) + (100 * nbcl) -# h = 100 + (nbwords * 15) -# if w > 1100 : w = 1100 -# if h > 800 : h = 800 -# if h < 450 : h = 450 -# win = MessageImage(self, u"Graphique", size=(w, h)) -# win.addsaveimage(tmpgraph) -# txt = "" % tmpgraph -# win.HtmlPage.SetPage(txt) -# win.Show(True) def onlexdendro(self, evt): if 'corpus' in dir(self.Source): @@ -684,10 +677,7 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col uci = True ucis_txt, ucestxt = doconcorde(corpus, ucef, ListWord, uci = uci) items = dict([[i, '

'.join([ucis_txt[i], ucestxt[i]])] for i in range(0,len(ucestxt))]) - win = message(self, items, title, (800, 500)) - #win = message(self, title, size=(750, 600)) - #win.html = ('\n

%s

' % ' '.join(ListWord)) + '
'.join(['
'.join([ucis_txt[i], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n' - #win.HtmlPage.SetPage(win.html) + win = message(self, items, title, (800, 500), uceids = ucef) return win def OnPopupTwo(self, event): @@ -700,13 +690,13 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col def OnPopupThree(self, event): corpus = self.Source.corpus uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] - win = self.make_concord(uces, "Concordancier - UCE classées") + win = self.make_concord(uces, "Concordancier - Segments de texte classés") win.Show(True) def OnPopupFour(self, event): corpus = self.Source.corpus uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0 - win = self.make_concord(uces, "Concordancier - Toutes les UCE") + win = self.make_concord(uces, "Concordancier - Tous les segments de texte") win.Show(True) def OnPopupFive(self, event): @@ -764,6 +754,9 @@ class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.Col #win.html = '\n' + '
'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n' #win.HtmlPage.SetPage(win.html) win.Show(True) + + def OnMakeTgen(self, evt): + self.parent.tree.OnTgenEditor(self.getselectedwords()) class wliste(wx.Frame): diff --git a/Rscripts/Rgraph.R b/Rscripts/Rgraph.R index 14ce864..a00a186 100644 --- a/Rscripts/Rgraph.R +++ b/Rscripts/Rgraph.R @@ -628,7 +628,10 @@ plot.dendro.prof <- function(tree, classes, chisqtable, nbbycl = 60, type.dendro names(ntoplot) <- rownames(toplot) ntoplot <- ntoplot[order(ntoplot, decreasing = TRUE)] ntoplot <- round(ntoplot, 0) - ntoplot <- ntoplot[1:nbbycl] + if (length(toplot) > nbbycl) { + ntoplot <- ntoplot[1:nbbycl] + } + ntoplot <- ntoplot[which(ntoplot > 0)] #ntoplot <- ntoplot[order(ntoplot)] #ntoplot <- ifelse(length(ntoplot) > nbbycl, ntoplot[1:nbbycl], ntoplot) lclasses[[classe]] <- ntoplot @@ -660,12 +663,15 @@ plot.dendro.prof <- function(tree, classes, chisqtable, nbbycl = 60, type.dendro #wordcloud(names(lclasses[[i]]), lclasses[[i]], scale = c(1.5, 0.2), random.order=FALSE, colors = colcloud[i]) yval <- 1.1 plot(0,0,pch='', axes = FALSE) - vcex <- norm.vec(lclasses[[i]], 1.5, 1.5) + vcex <- norm.vec(lclasses[[i]], 1, 2) for (j in 1:length(lclasses[[i]])) { yval <- yval-(strheight( names(lclasses[[i]])[j],cex=vcex[j])+0.02) text(-0.9, yval, names(lclasses[[i]])[j], cex = vcex[j], col = colcloud[i], adj=0) } } + if (!from.cmd) { + dev.off() + } } @@ -686,10 +692,14 @@ plot.dendro.cloud <- function(tree, classes, chisqtable, nbbycl = 60, type.dendr lclasses <- list() for (classe in 1:length(sum.cl)) { ntoplot <- toplot[,classe] + names(ntoplot) <- rownames(toplot) ntoplot <- ntoplot[order(ntoplot, decreasing = TRUE)] ntoplot <- round(ntoplot, 0) - ntoplot <- ntoplot[1:nbbycl] + if (length(toplot) > nbbycl) { + ntoplot <- ntoplot[1:nbbycl] + } ntoplot <- ntoplot[order(ntoplot)] + ntoplot <- ntoplot[which(ntoplot > 0)] #ntoplot <- ifelse(length(ntoplot) > nbbycl, ntoplot[1:nbbycl], ntoplot) lclasses[[classe]] <- ntoplot } @@ -714,7 +724,7 @@ plot.dendro.cloud <- function(tree, classes, chisqtable, nbbycl = 60, type.dendr plot.phylo(tree,label.offset=0.1,tip.col=col, type=type.dendro) for (i in rev(tree.order)) { par(mar=c(0,0,1,0),cex=0.9) - wordcloud(names(lclasses[[i]]), lclasses[[i]], scale = c(4, 0.8), random.order=FALSE, colors = colcloud[i]) + wordcloud(names(lclasses[[i]]), lclasses[[i]], scale = c(2.5, 0.5), random.order=FALSE, colors = colcloud[i]) } } diff --git a/Rscripts/chdfunct.R b/Rscripts/chdfunct.R index 5e31442..914278c 100644 --- a/Rscripts/chdfunct.R +++ b/Rscripts/chdfunct.R @@ -321,6 +321,32 @@ BuildProf01<-function(x,classes) { mat } +build.prof.tgen <- function(x) { + nbst <- sum(x[nrow(x),]) + totcl <- x[nrow(x),] + tottgen <- rowSums(x) + nbtgen <- nrow(x) - 1 + chi2 <- x[1:(nrow(x)-1),] + pchi2 <- chi2 + for (classe in 1:ncol(x)) { + for (tg in 1:nbtgen) { + cont <- c(x[tg, classe], tottgen[tg] - x[tg, classe], totcl[classe] - x[tg, classe], (nbst - totcl[classe]) - (tottgen[tg] - x[tg, classe])) + cont <- matrix(unlist(cont), nrow=2) + chiresult<-chisq.test(cont,correct=FALSE) + if (is.na(chiresult$p.value)) { + chiresult$p.value<-1 + chiresult$statistic<-0 + } + if (chiresult$expected[1,1] > cont[1,1]) { + chiresult$statistic <- chiresult$statistic * -1 + } + chi2[tg,classe] <- chiresult$statistic + pchi2[tg,classe] <- chiresult$p.value + } + } + res <- list(chi2 = chi2, pchi2 = pchi2) +} + BuildProf<- function(x,dataclasse,clusternb,lim=2) { #### #r.names<-rownames(x) diff --git a/Rscripts/simi.R b/Rscripts/simi.R index 8c5da10..bd772c2 100644 --- a/Rscripts/simi.R +++ b/Rscripts/simi.R @@ -222,7 +222,7 @@ do.simi <- function(x, method = 'cooc',seuil = NULL, p.type = 'tkplot',layout.ty out <- list(graph = g.toplot, mat.eff = mat.eff, eff = eff, mat = mat.simi, v.label = v.label, we.width = we.width, we.label=we.label, label.cex = label.cex, layout = lo, communities = com, halo = halo, elim=vec) } -plot.simi <- function(graph.simi, p.type = 'tkplot',filename=NULL, communities = NULL, vertex.col = 'red', edge.col = 'black', edge.label = TRUE, vertex.label=TRUE, vertex.label.color = 'black', vertex.label.cex= NULL, vertex.size=NULL, leg=NULL, width = 800, height = 800, alpha = 0.1, cexalpha = FALSE, movie = NULL, svg = FALSE) { +plot.simi <- function(graph.simi, p.type = 'tkplot',filename=NULL, communities = NULL, vertex.col = 'red', edge.col = 'black', edge.label = TRUE, vertex.label=TRUE, vertex.label.color = 'black', vertex.label.cex= NULL, vertex.size=NULL, leg=NULL, width = 800, height = 800, alpha = 0.1, cexalpha = FALSE, movie = NULL, edge.curved = TRUE, svg = FALSE) { mat.simi <- graph.simi$mat g.toplot <- graph.simi$graph if (is.null(vertex.size)) { @@ -272,14 +272,14 @@ plot.simi <- function(graph.simi, p.type = 'tkplot',filename=NULL, communities = } par(pch=' ') if (is.null(graph.simi$com)) { - plot(g.toplot,vertex.label='', edge.width=we.width, vertex.size=vertex.size, vertex.color=vertex.col, vertex.label.color='white', edge.label=we.label, edge.label.cex=cex, edge.color=edge.col, vertex.label.cex = 0, layout=lo, edge.curved=FALSE)#, rescale = FALSE) + plot(g.toplot,vertex.label='', edge.width=we.width, vertex.size=vertex.size, vertex.color=vertex.col, vertex.label.color='white', edge.label=we.label, edge.label.cex=cex, edge.color=edge.col, vertex.label.cex = 0, layout=lo, edge.curved=edge.curved)#, rescale = FALSE) } else { if (graph.simi$halo) { mark.groups <- communities(graph.simi$com) } else { mark.groups <- NULL } - plot(com, g.toplot,vertex.label='', edge.width=we.width, vertex.size=vertex.size, vertex.color=vertex.col, vertex.label.color='white', edge.label=we.label, edge.label.cex=cex, edge.color=edge.col, vertex.label.cex = 0, layout=lo, mark.groups = mark.groups, edge.curved=FALSE) + plot(com, g.toplot,vertex.label='', edge.width=we.width, vertex.size=vertex.size, vertex.color=vertex.col, vertex.label.color='white', edge.label=we.label, edge.label.cex=cex, edge.color=edge.col, vertex.label.cex = 0, layout=lo, mark.groups = mark.groups, edge.curved=edge.curved) } #txt.layout <- lo txt.layout <- layout.norm(lo, -1, 1, -1, 1, -1, 1) diff --git a/analysematrix.py b/analysematrix.py index a89b10e..7e3c93f 100644 --- a/analysematrix.py +++ b/analysematrix.py @@ -25,12 +25,9 @@ class AnalyseMatrix : self.dlg = dlg self.parametres = parametres self.val = False - print self.parametres if not 'pathout' in self.parametres : self.parametres['pathout'] = PathOut(tableau.parametres['originalpath'], analyse_type = self.parametres['type'], dirout = tableau.parametres['pathout']).mkdirout() - print self.parametres self.pathout = PathOut(analyse_type = self.parametres['type'], dirout = self.parametres['pathout']) - print self.pathout.dirout else : self.pathout = PathOut(filename = tableau.parametres['originalpath'], dirout = self.parametres['pathout'], analyse_type = self.parametres['type']) diff --git a/analysetxt.py b/analysetxt.py index 33f7d12..cc99482 100644 --- a/analysetxt.py +++ b/analysetxt.py @@ -78,7 +78,10 @@ class AnalyseText : else : self.val = False if dlg : - self.dlg.Destroy() + try : + self.dlg.Destroy() + except : + pass else : #if isinstance(dlg, wx.ProgressDialog) : # self.dlg.Destroy() diff --git a/configuration/global.cfg b/configuration/global.cfg index e4d877b..fa99eef 100644 --- a/configuration/global.cfg +++ b/configuration/global.cfg @@ -6,6 +6,6 @@ copyright = (c) 2008-2014 Pierre Ratinaud author = Pierre Ratinaud gpl-fr = gpl-2.0-fr.txt dev = Pierre Ratinaud (Université de Toulouse - Laboratoire LERASS - ratinaud@univ-tlse2.fr);Sébastien Déjean (Université de Toulouse);David Skalinder (Mash Strategy - davids@mash.uk.com); -version = 0.6 alpha 10 +version = 0.6 alpha 11 licence = GNU GPL (v2) -version_nb = 0.6.a10 \ No newline at end of file +version_nb = 0.6.a11 \ No newline at end of file diff --git a/configuration/iramuteq.cfg b/configuration/iramuteq.cfg index 58fd685..eb15ab1 100644 --- a/configuration/iramuteq.cfg +++ b/configuration/iramuteq.cfg @@ -5,8 +5,8 @@ language=french guilanguage=french R_mem = false R_max_mem = 1535 -version_nb = 0.6.a10 +version_nb = 0.6.a11 rlibs = false libsvdc = false libsvdc_path = /usr/bin/svd -rmirror = http://cran.rstudio.com/ +rmirror = http://cran.rstudio.com/ \ No newline at end of file diff --git a/configuration/simitxt.cfg b/configuration/simitxt.cfg index 6b6c6fc..c034e47 100644 --- a/configuration/simitxt.cfg +++ b/configuration/simitxt.cfg @@ -37,3 +37,4 @@ coeff_temax = 10 type_graph = 1 coeff_tv = True first = False +edgecurved = True diff --git a/corpus.py b/corpus.py index 3e4ae30..011206f 100644 --- a/corpus.py +++ b/corpus.py @@ -172,6 +172,16 @@ class Corpus : res = self.cformes.execute(query) return list(set(list(itertools.chain(*[[int(val) for val in row[0].split()] if not isinstance(row[0], int) else [row[0]] for row in res])))) + def gettgenst(self, tgen): + formesid = ', '.join([`val` for lem in tgen for val in self.lems[lem].formes if lem in self.lems]) + query = 'SELECT uces FROM uces where id IN (%s) ORDER BY id' % formesid + res = self.cformes.execute(query) + return list(set(list(itertools.chain(*[[int(val) for val in row[0].split()] if not isinstance(row[0], int) else [row[0]] for row in res])))) + + def gettgentxt(self, tgen): + sts = self.gettgenst(tgen) + return list(set([self.getucefromid(val).uci for val in sts])) + def getlemucis(self, lem) : uces = self.getlemuces(lem) return list(set([self.getucefromid(val).uci for val in uces])) @@ -391,6 +401,26 @@ class Corpus : tgenoccurrences[t][etoiles[i]] += sum([lemuceeff[uce] for uce in concern]) return tgenoccurrences, totoccurrences + def make_tgen_profile(self, tgen, ucecl, uci = False) : + log.info('tgen/classes') + if uci : + tab = [[lem] + [len(set(self.gettgentxt(tgen[lem])).intersection(classe)) for classe in ucecl] for lem in tgen] + else : + tab = [[lem] + [len(set(self.gettgenst(tgen[lem])).intersection(classe)) for classe in ucecl] for lem in tgen] + tab = [[line[0]] + [val for val in line[1:]] for line in tab if sum(line[1:]) >= 3] + return tab + #i = 0 + #nam = 'total' + #while nam + `i` in tgen : + # i += 1 + #nam = nam + `i` + #last = [nam] + [`len(classe)` for classe in ucecl] + #tab += [last] + #line0 = ['tgen'] + ['_'.join(['cluster', `i+1`]) for i in range(len(ucecl))] + #tab = [line0] + tab + #with open(fileout, 'w') as f : + # f.write('\n'.join(['\t'.join(line) for line in tab]).encode(self.parametres['syscoding'])) + def make_efftype_from_etoiles(self, etoiles) : dtype = {} etuces = [[] for et in etoiles] @@ -756,6 +786,28 @@ class Corpus : except IndexError : det[et[0]] = 1 return det + + def make_theme_dict(self): + themes = [val for uci in self.ucis for val in uci.paras] + det = {} + for theme in themes : + th = theme.split('_') + if th[0] in det : + try : + endth = '_'.join(th[1:]) + if theme in det[th[0]] : + det[th[0]][theme] += 1 + else : + det[th[0]][theme] = 1 + except IndexError : + det[th[0]] += 1 + else : + try : + endth = '_'.join(th[1:]) + det[th[0]] = {theme:1} + except IndexError : + det[th[0]] = 1 + return det def make_etline(self, listet) : etuces = [[] for et in listet] diff --git a/dialog.py b/dialog.py index 7fd2f4a..14b8a24 100755 --- a/dialog.py +++ b/dialog.py @@ -1564,7 +1564,7 @@ class FindInCluster(wx.Frame): class SearchDial ( wx.Frame ): def __init__( self, parent, listctrl, col, shown): - wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE ) + wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP ) self.parent = parent self.listctrl = listctrl self.col = col diff --git a/dictionnaires/lexique_en.txt b/dictionnaires/lexique_en.txt index 02d5cc0..d10dced 100644 --- a/dictionnaires/lexique_en.txt +++ b/dictionnaires/lexique_en.txt @@ -96476,7 +96476,7 @@ willowwares willowware nom willowy willowy adj willpower willpower nom willpowers willpower nom -wills will nom +wills wills nom wilt wilt nom wilted wilt ver wilting wilt ver @@ -97652,7 +97652,7 @@ your your sw yours yours sw yourself yourself sw yourselves yourselves sw -yous you nom +yous yous nom youth youth nom youthfulness youthfulness nom youthfulnesses youthfulness nom diff --git a/functions.py b/functions.py index f2579f1..6ad088d 100644 --- a/functions.py +++ b/functions.py @@ -35,7 +35,7 @@ def normpath_win32(path) : return path while '\\\\' in path : path = path.replace('\\\\', '\\') - if sys.platform == 'win32' and path.startswith('\\') and not path.startswith('\\\\') : + if path.startswith('\\') and not path.startswith('\\\\') : path = '\\' + path return path @@ -48,7 +48,9 @@ class TGen : def __getitem__(self, key): return self.tgen[key] - def read(self, path): + def read(self, path = None): + if path is None : + path = self.path with codecs.open(path, 'r', self.encoding) as f : tgen = f.read() tgen = [line.split('\t') for line in tgen.splitlines()] @@ -376,15 +378,8 @@ def treat_line_alceste(i, line) : return [i, int(line[0]), int(line[1]), float(line[2]), float(line[3]), line[6], line[4], line[5]] def ReadProfileAsDico(File, Alceste=False, encoding = sys.getdefaultencoding()): - #print 'lecture des profils : ReadProfileAsDico' - #if Alceste : - # print 'lecture du dictionnaire de type' - # dictlem = {} - # for line in parent.corpus.lem_type_list : - # dictlem[line[0]] = line[1] dictlem = {} print 'lecture des profiles' - #encoding = sys.getdefaultencoding() FileReader = codecs.open(File, 'r', encoding) Filecontent = FileReader.readlines() FileReader.close() @@ -418,17 +413,17 @@ def GetTxtProfile(dictprofile, cluster_size) : return '\n\n'.join(proflist) def formatExceptionInfo(maxTBlevel=5): - cla, exc, trbk = sys.exc_info() - try : - excName = cla.__name__ - except : - excName = 'None' - try: - excArgs = exc.args[0] - except : - excArgs = "" - excTb = traceback.format_tb(trbk, maxTBlevel) - return (excName, excArgs, excTb) + cla, exc, trbk = sys.exc_info() + try : + excName = cla.__name__ + except : + excName = 'None' + try: + excArgs = exc.args[0] + except : + excArgs = "" + excTb = traceback.format_tb(trbk, maxTBlevel) + return (excName, excArgs, excTb) #fonction des etudiants de l'iut @@ -692,7 +687,6 @@ def progressbar(self, maxi) : else : parent = self try : - print '###horrible hack progressbar' maxi = int(maxi) except : maxi = 1 diff --git a/guifunct.py b/guifunct.py index 1641795..6280e94 100644 --- a/guifunct.py +++ b/guifunct.py @@ -58,6 +58,7 @@ def get_table_param(self, filename) : if self.tableau.parametres['colsep'] == 'tabulation' : self.tableau.parametres['colsep'] = '\t' self.tableau.parametres['filetype'] = 'csv' + self.tableau.parametres['encodage'] = dlg.le[dlg.list_encodages.GetSelection()] elif getfileextension(filename) == '.xls' : dlg = dialog.FileOptionDialog(self, -1, _(u"File format").decode('utf8'), sep=False, sheet = True, size=(350, 200), style=wx.DEFAULT_DIALOG_STYLE) @@ -322,6 +323,19 @@ class PrefSimi ( wx.Dialog ): self.check_elab = wx.CheckBox( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) fgSizer3.Add( self.check_elab, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + self.m_staticline39 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer3.Add( self.m_staticline39, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_staticline40 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + fgSizer3.Add( self.m_staticline40, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_staticText321 = wx.StaticText( self.m_panel2, wx.ID_ANY, _(u"Edge curved"), wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText321.Wrap( -1 ) + fgSizer3.Add( self.m_staticText321, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + + self.check_curved = wx.CheckBox( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) + fgSizer3.Add( self.check_curved, 0, wx.ALL, 5 ) + self.m_staticline2914 = wx.StaticLine( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) fgSizer3.Add( self.m_staticline2914, 0, wx.EXPAND, 5 ) @@ -786,6 +800,7 @@ class PrefSimi ( wx.Dialog ): self.comcheck.SetValue(self.paramsimi['com']) self.choix_com.SetSelection(self.paramsimi['communities']) self.halo.SetValue(self.paramsimi['halo']) + self.check_curved.SetValue(self.paramsimi.get('edgecurved', True)) def ChangeCount(self, evt) : self.textcount.SetValue('%i' % self.listcol.GetSelectedItemCount()) @@ -962,12 +977,12 @@ class PrepSimi : 'com' :self.dial.comcheck.GetValue(), 'communities' : self.dial.choix_com.GetSelection(), 'halo' : self.dial.halo.GetValue(), + 'edgecurved' : self.dial.check_curved.GetValue(), } if 'cexfromchi' in self.parametres : param['cexfromchi'] = self.dial.checkit.GetValue() if 'sfromchi' in self.parametres : param['sfromchi'] = self.dial.checki.GetValue() - print param if 'vlabcolor' in self.parametres : param['vlabcolor'] = self.parametres['vlabcolor'] if 'check_bystar' in dir(self.dial) : diff --git a/images/but_dendro_cloud.png b/images/but_dendro_cloud.png new file mode 100644 index 0000000..5678282 Binary files /dev/null and b/images/but_dendro_cloud.png differ diff --git a/images/but_dendro_liste.png b/images/but_dendro_liste.png new file mode 100644 index 0000000..310dbe8 Binary files /dev/null and b/images/but_dendro_liste.png differ diff --git a/iramuteq.py b/iramuteq.py index e3ded49..8a0e628 100644 --- a/iramuteq.py +++ b/iramuteq.py @@ -5,39 +5,36 @@ #License: GNU GPL from optparse import OptionParser +from wx import BusyCursor parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="open FILE", metavar="FILE", default=False) (options, args) = parser.parse_args() -#print args -#print options import sys reload(sys) import locale import tempfile import codecs import os -import shutil from random import randint -from ConfigParser import * +from ConfigParser import ConfigParser, RawConfigParser import webbrowser import gettext import logging #------------------------------------ import wx -#import wx.aui import wx.lib.agw.aui as aui import wx.html import wx.grid import wx.lib.hyperlink as hl #------------------------------------ -from functions import BugReport, PlaySound, ReadLexique, History, DoConf, ReadDicoAsDico, progressbar +from functions import BugReport, PlaySound, History from checkversion import NewVersion from guifunct import * from tableau import Tableau -from dialog import PrefDialog, CorpusPref +from dialog import PrefDialog from tabfrequence import Frequences, FreqMultiple from tabchi2 import ChiSquare #from tabstudent import MakeStudent @@ -48,18 +45,15 @@ from tabsimi import DoSimi from tabrsimple import InputText from tabverges import Prototypical from tabsplitvar import SplitMatrixFromVar -#from textafcuci import AfcUci -from textdist import AnalysePam +#from textdist import AnalysePam from textstat import Stat from textaslexico import Lexico from textsimi import SimiTxt, SimiFromCluster from textwordcloud import WordCloud, ClusterCloud from textreinert import Reinert -#from profile_segment import ProfileSegment #from textcheckcorpus import checkcorpus from openanalyse import OpenAnalyse from corpus import Builder, SubBuilder -#from sheet import MySheet from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled from chemins import RscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut from parse_factiva_xml import ImportFactiva @@ -152,17 +146,18 @@ sys.stdout = printer() ConfigPath = ConstructConfigPath(UserConfigPath) langues = {'french' : wx.LANGUAGE_FRENCH, - 'english' : wx.LANGUAGE_ENGLISH, - 'portuguese' : wx.LANGUAGE_PORTUGUESE, - 'italian' : wx.LANGUAGE_ITALIAN, - 'spanish' : wx.LANGUAGE_SPANISH} + 'english' : wx.LANGUAGE_ENGLISH, + 'portuguese' : wx.LANGUAGE_PORTUGUESE, + 'italian' : wx.LANGUAGE_ITALIAN, + 'spanish' : wx.LANGUAGE_SPANISH + } code_langues = {'french' : 'fr_FR', - 'english' : 'en', - 'portuguese' : 'pt_PT', - 'italian' : 'it_IT', - 'spanish' : 'es_ES' - } + 'english' : 'en', + 'portuguese' : 'pt_PT', + 'italian' : 'it_IT', + 'spanish' : 'es_ES' + } ##################################################################### class IraFrame(wx.Frame): @@ -310,8 +305,8 @@ class IraFrame(wx.Frame): #-------------------------------------------------------------------- self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP) self.statusbar.SetStatusWidths([-2, -3]) - self.statusbar.SetStatusText(u"Prêt", 0) - self.statusbar.SetStatusText(u"Bienvenue", 1) + self.statusbar.SetStatusText(_(u"Ready"), 0) + self.statusbar.SetStatusText(_(u"Welcome"), 1) # min size for the frame itself isn't completely done. # see the end up FrameManager::Update() for the test @@ -345,7 +340,7 @@ class IraFrame(wx.Frame): # f.write('') self.history = History(os.path.join(UserConfigPath, 'history.db')) self.tree = LeftTree(self) - self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption(_(u"Navigator").decode('utf8')). + self._mgr.AddPane(self.tree, aui.AuiPaneInfo().Name("lefttree").Caption(_(u"Historic").decode('utf8')). Left().MinSize(wx.Size(200,500)).Layer(1).Position(1).CloseButton(False).MaximizeButton(True). MinimizeButton(True)) @@ -583,9 +578,16 @@ vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" self.tableau = Tableau(self,os.path.abspath(self.input_path[0])) val = get_table_param(self, self.input_path[0]) if val == wx.ID_OK : - self.tableau.make_content() - OpenAnalyse(self, self.tableau.parametres) - self.tree.OnItemAppend(self.tableau.parametres) + busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self) + wx.SafeYield() + try : + self.tableau.make_content() + OpenAnalyse(self, self.tableau.parametres) + self.tree.OnItemAppend(self.tableau.parametres) + del busy + except : + del busy + BugReport(self) #self.tableau.show_tab() def OnOpenAnalyse(self, event): @@ -965,8 +967,8 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis.""" except: BugReport(self) - def SimiCluster(self, parametres = {}, fromprof = False, pathout = '', listactives = [], actives = [], tableau = None) : - DoSimi(self, param = parametres, fromprof = fromprof, listactives = listactives, actives = actives, tableau = tableau) + def SimiCluster(self, parametres = {}, fromprof = False, tableau = None) : + self.analyse_matrix(DoSimi, parametres = parametres, analyse_type = 'simiclustermatrix', matrix = tableau, dlgnb = 5) # def OnSimi(self,evt): # try : diff --git a/layout.py b/layout.py index b362300..6050d2e 100644 --- a/layout.py +++ b/layout.py @@ -12,7 +12,7 @@ import wx.lib.agw.labelbook as LB from wx.lib.agw.fmresources import * from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath from ConfigParser import ConfigParser -from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar, normpath_win32 +from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar, normpath_win32, TGen from ProfList import ProfListctrlPanel from guiparam3d import param3d, simi3d from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript @@ -519,6 +519,10 @@ class OpenCHDS(): panel.TabChdSim.AddPage(self.prof_seg_nb, _(u"Repeated segments profiles").decode('utf8')) # panel.Bind(wx.EVT_BUTTON, self.ongetrapport, id = self.ID_rapport) + if os.path.exists(os.path.join(self.parametres['pathout'], 'tgenchi2.csv')) : + self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenchi2.csv') + TgenLayout(panel) + panel.TabChdSim.SetSelection(0) self.parent.nb.AddPage(panel, _(u"Clustering").decode('utf8') + ' - %s' % corpname) self.parent.ShowTab(True) self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1) @@ -659,9 +663,14 @@ class TgenLayout : self.page = page parametres = self.page.parametres ira = wx.GetApp().GetTopWindow() + tgenpath = os.path.join(parametres['pathout'], 'tgen.csv') self.page.tgens, etoiles = ReadList(parametres['tgenspec'], ira.syscoding, sep="\t") + tgen = TGen(path = tgenpath, encoding = parametres['encoding']) + tgen.read() tgentab = False gparent = None + if 'TabChdSim' in dir(page) : + page = page.TabChdSim for i in range(page.GetPageCount()) : tab = page.GetPage(i) if 'gparent' in dir(tab) : @@ -671,14 +680,17 @@ class TgenLayout : if tab.tgen : tgentab = tab break + if tgentab : self.page.tgentab.RefreshData(self.page.tgens) - self.page.SetSelection(i) + self.page.tgentab.tgens = tgen.tgen + page.SetSelection(i) else : self.page.tgentab = ListForSpec(ira, gparent, self.page.tgens, etoiles[1:]) self.page.tgentab.tgen = True - self.page.AddPage(self.page.tgentab, u'Tgens Specificities') - self.page.SetSelection(self.page.GetPageCount() - 1) + self.page.tgentab.tgens = tgen.tgen + page.AddPage(self.page.tgentab, u'Tgens Specificities') + page.SetSelection(page.GetPageCount() - 1) class dolexlayout : def __init__(self, ira, corpus, parametres): @@ -706,7 +718,7 @@ class dolexlayout : self.TabStat.parametres = parametres self.ListPan = ListForSpec(ira, self, self.DictSpec, self.etoiles) if os.path.exists(self.pathout['banalites.csv']) : - self.listban = ListForSpec(ira, self, self.dictban, ['eff'] + self.etoiles) + self.listban = ListForSpec(ira, self, self.dictban, ['eff'] + self.etoiles, usefirst = True) #self.ListPan2 = ListForSpec(sash.rightwin1, self, self.DictSpec, first) self.ListPant = ListForSpec(ira, self, self.DictType, self.etoiles) self.ListPanEff = ListForSpec(ira, self, self.DictEff, self.etoiles) @@ -732,10 +744,6 @@ class dolexlayout : self.TabAFC.AddPage(self.tabAFCTGraph, 'AFC type') self.TabStat.AddPage(self.TabAFC, 'AFC') - - - - ira.nb.AddPage(self.TabStat, u'Spécificités') self.ira = ira @@ -801,9 +809,11 @@ class GraphPanelDendro(wx.Panel): self.panel_1.SetBackgroundColour('white') self.deb = wx.StaticText(self.panel_1, -1, txt) dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap() + dendro_liste_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro_liste.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap() + dendro_cloud_img= wx.Image(os.path.join(self.ira.images_path,'but_dendro_cloud.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.butdendro = wx.BitmapButton(self, -1, dendro_img) - self.butdendrotexte = wx.BitmapButton(self, -1, dendro_img) - self.butdendrocloud = wx.BitmapButton(self, -1, dendro_img) + self.butdendrotexte = wx.BitmapButton(self, -1, dendro_liste_img) + self.butdendrocloud = wx.BitmapButton(self, -1, dendro_cloud_img) for i in range(0,len(list_graph)): if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) : @@ -906,6 +916,9 @@ class GraphPanelDendro(wx.Panel): txt += """ load("%s") source("%s") + if (is.null(debsup)) { + debsup <- debet + } chistable <- chistabletot[1:(debsup-1),] open_file_graph("%s", width=%i, height=%i, svg = %s) plot.dendro.prof(tree.cut1$tree.cl, classes, chistable, nbbycl = 60, type.dendro="%s", bw=%s, lab=NULL) @@ -914,6 +927,9 @@ class GraphPanelDendro(wx.Panel): txt += """ load("%s") source("%s") + if (is.null(debsup)) { + debsup <- debet + } chistable <- chistabletot[1:(debsup-1),] open_file_graph("%s", width=%i, height=%i, svg=%s) plot.dendro.cloud(tree.cut1$tree.cl, classes, chistable, nbbycl = 300, type.dendro="%s", bw=%s, lab=NULL) @@ -923,7 +939,10 @@ class GraphPanelDendro(wx.Panel): tmpfile = tempfile.mktemp() with open(tmpfile, 'w') as f : f.write(txt) + busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self.parent) + wx.SafeYield() error = exec_rcode(self.ira.RPath, tmpfile, wait=True) + del busy check_Rresult(self.ira, error) self.list_graph.append([fileout, 'Dendrogramme CHD1 - %s' % type_dendro]) print_liste(self.dictpathout['liste_graph_chd'], self.list_graph) @@ -1378,6 +1397,7 @@ class SimiMatLayout(DefaultMatLayout) : 'halo' : self.dial.halo.GetValue(), 'com' : self.dial.comcheck.GetValue(), 'communities' : self.dial.choix_com.GetSelection(), + 'edgecurved' : self.dial.check_curved.GetValue(), } if 'cexfromchi' in self.parametres : paramsimi['cexfromchi'] = self.dial.checkit.GetValue() diff --git a/listlex.py b/listlex.py index f1f4f65..10729e8 100644 --- a/listlex.py +++ b/listlex.py @@ -25,7 +25,7 @@ from operator import itemgetter #--------------------------------------------------------------------------- class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin): - def __init__(self, parent,gparent, dlist = {}, first = [], menu = True): + def __init__(self, parent,gparent, dlist = {}, first = [], usefirst = False, menu = True): #def __init__(self, parent) : wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES) self.parent=parent @@ -33,7 +33,7 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor self.dlist=dlist self.first = first self.tgen = False - if 'etoiles' in dir(self.gparent) : + if 'etoiles' in dir(self.gparent) and not usefirst : self.etoiles = self.gparent.etoiles else : self.etoiles = [] @@ -199,15 +199,14 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor menu.Append(self.popupID3, u"Graphique") menu_stcaract = wx.Menu() self.menuid = {} - for i, et in enumerate(self.etoiles) : - nid = wx.NewId() - self.menuid[nid] = i - menu_stcaract.Append(nid, et) - self.Bind(wx.EVT_MENU, self.onstcaract, id = nid) - menu.AppendMenu(-1, u"Segments de texte caractéristiques", menu_stcaract) - #menu.Append(self.popup_Tgen_glob, "Tgen global") if not self.tgen : - menu.Append(self.onmaketgen, "Make Tgen") + for i, et in enumerate(self.etoiles) : + nid = wx.NewId() + self.menuid[nid] = i + menu_stcaract.Append(nid, et) + self.Bind(wx.EVT_MENU, self.onstcaract, id = nid) + menu.AppendMenu(-1, u"Segments de texte caractéristiques", menu_stcaract) + menu.Append(self.onmaketgen, _(u"Make Tgen").decode('utf8')) self.PopupMenu(menu) menu.Destroy() @@ -247,15 +246,10 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor parametres = page.parametres paneff = self.gparent.ListPanEff panchi = self.gparent.ListPan - #etoiles = self.gparent.etoiles et = self.etoiles[ind] - - #if et.startswith(u'X.') : - # et = et.replace(u'X.', u'*') uces = corpus.getucesfrometoile(et) self.la = [panchi.dlist[i][0] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ] self.lchi = [panchi.dlist[i][ind+1] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ] - #lfreq = [paneff.dlist[i][ind+1] for i in range(0, len(panchi.dlist)) if panchi.dlist[i][ind+1] >= minind ] if max(self.lchi) == float('inf') : nchi = [] for val in self.lchi : @@ -277,8 +271,6 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor ucis_txt, ucestxt = doconcorde(corpus, nuces, self.la) items = dict([[i, '
'.join([ucis_txt[i], '
score : %.2f

' % ntab2[i][0], ucestxt[i]])] for i in range(0,len(ucestxt))]) win = message(self, items, u"Segments de texte caractéristiques - %s" % self.first[ind], (900, 600)) - #win.html = '\n' + '
'.join(['
'.join([ucis_txt[i], '
score : %.2f
' % ntab2[i][0], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n' - #win.HtmlPage.SetPage(win.html) win.Show(True) def OnPopupTwo(self, event): @@ -288,15 +280,17 @@ class ListForSpec(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSor corpus = page.corpus else : corpus = self.parent.parent.parent.corpus - item=self.getColumnText(self.GetFirstSelected(), 0) - uce_ok = corpus.getlemuces(item) ira = wx.GetApp().GetTopWindow() - ucis_txt, ucestxt = doconcorde(corpus, uce_ok, [item]) + item=self.getColumnText(self.GetFirstSelected(), 0) + if not self.tgen : + uce_ok = corpus.getlemuces(item) + wordlist = [item] + else : + uce_ok = corpus.gettgenst(self.tgens[item]) + wordlist = [val for val in self.tgens[item] if val in corpus.lems] + ucis_txt, ucestxt = doconcorde(corpus, uce_ok, wordlist) items = dict([[i, '

'.join([ucis_txt[i], ucestxt[i]])] for i in range(0,len(ucestxt))]) - win = message(ira, items, u"Concordancier - %s" % item, (800, 500)) - #win = message(ira, u"Concordancier", (800, 500)) - #win.html = ('\n

%s

' % item) + '
'.join(['
'.join([ucis_txt[i], ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n' - #win.HtmlPage.SetPage(win.html) + win = message(ira, items, u"Concordancier - %s" % item, (800, 500), uceids = uce_ok) win.Show(True) def getinf(self, txt) : diff --git a/openanalyse.py b/openanalyse.py index 899a0bb..c8089d2 100644 --- a/openanalyse.py +++ b/openanalyse.py @@ -162,7 +162,7 @@ class OpenAnalyse(): WordCloudLayout(self.parent, corpus, self.conf) elif self.conf['type'] == 'reinertmatrix' : OpenCHDS(self.parent, corpus, self.conf, Alceste = False) - elif self.conf['type'] == 'simimatrix' : + elif self.conf['type'] == 'simimatrix' or self.conf['type'] == 'simiclustermatrix': SimiMatLayout(self.parent, corpus, self.conf) elif self.conf['type'] == 'proto' : ProtoLayout(self.parent, corpus, self.conf) diff --git a/tabsimi.py b/tabsimi.py index 9de8067..db34395 100644 --- a/tabsimi.py +++ b/tabsimi.py @@ -30,7 +30,7 @@ class DoSimi(AnalyseMatrix): self.cmd = self.parametres.get('cmd', False) self.dirout = self.parametres.get('pathout', False) if self.fromprof: - self.paramsimi = parametres + self.paramsimi = self.parametres else : self.paramsimi = {'coeff' : 0, 'layout' : 2, @@ -109,7 +109,6 @@ class DoSimi(AnalyseMatrix): #self.parametres['type'] = 'simimatrix' if not self.pathout : self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'SimiMatrix') - print self.parametres['pathout'] else : self.parametres['pathout'] = self.dirout self.pathout.createdir(self.parametres['pathout']) diff --git a/textdist.py b/textdist.py index 8886a9e..33dd2ce 100644 --- a/textdist.py +++ b/textdist.py @@ -14,7 +14,7 @@ from ConfigParser import * import sys from functions import print_liste, exec_rcode, CreateIraFile, progressbar, check_Rresult, BugDialog from layout import PrintRapport -from PrintRScript import AlcesteTxtProf, RPamTxt +from PrintRScript import ReinertTxtProf, RPamTxt from openanalyse import OpenAnalyse from time import time, sleep diff --git a/textreinert.py b/textreinert.py index b15273f..6300ae5 100644 --- a/textreinert.py +++ b/textreinert.py @@ -7,10 +7,10 @@ import os from time import time from analysetxt import AnalyseText from OptionAlceste import OptionAlc -from PrintRScript import RchdTxt, AlcesteTxtProf +from PrintRScript import RchdTxt, ReinertTxtProf, TgenProfScript from layout import PrintRapport -from chemins import ChdTxtPathOut -from functions import DoConf, print_liste +from chemins import ChdTxtPathOut, PathOut +from functions import DoConf, print_liste, TGen class Reinert(AnalyseText) : @@ -81,7 +81,7 @@ class Reinert(AnalyseText) : return self.pathout['Rchdtxt'] def printRscript2(self) : - AlcesteTxtProf(self.pathout, self.parent.RscriptsPath, self.clnb, 0.9) + ReinertTxtProf(self.pathout, self.parent.RscriptsPath, self.clnb, 0.9) return self.pathout['RTxtProfGraph'] def print_graph_files(self) : @@ -98,4 +98,36 @@ class Reinert(AnalyseText) : chd_graph_list.append([os.path.basename(self.pathout['arbre2']), u'chd2']) print_liste(self.pathout['liste_graph_afc'], afc_graph_list) print_liste(self.pathout['liste_graph_chd'], chd_graph_list) - PrintRapport(self, self.corpus, self.parametres) \ No newline at end of file + PrintRapport(self, self.corpus, self.parametres) + +class TgenProf(AnalyseText): + def __init__(self, ira, corpus, parametres, cluster_size): + self.ira = ira + self.corpus = corpus + self.parametres = parametres + self.pathout = PathOut(dirout = self.parametres['pathout']) + self.cluster_size = [len(classe) for classe in corpus.lc] + print cluster_size + self.doanalyse() + + def doanalyse(self): + self.tgen = TGen(path = self.parametres['tgenpath'], encoding = self.ira.syscoding) + self.tgen.read(self.tgen.path) + #self.parametres['etoiles'].sort() + self.parametres['tgeneff'] = os.path.join(self.parametres['pathout'], 'tgeneff.csv') + tgenst = self.corpus.make_tgen_profile(self.tgen.tgen, self.corpus.lc) + clnames = ['cluster_%03d' % i for i in range(1, len(self.cluster_size) + 1)] + et = dict(zip(clnames, self.cluster_size)) + tgenst = dict([[line[0], dict(zip(clnames, line[1:]))] for line in tgenst]) + self.tgen.writetable(self.parametres['tgeneff'], tgenst, et) + self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenchi2.csv') + self.Rscript = TgenProfScript(self) + self.Rscript.make_script() + self.Rscript.write() + self.doR(self.Rscript.scriptout, dlg = False, message = 'R...') + + + + + + \ No newline at end of file diff --git a/tree.py b/tree.py index 532457f..3d8196c 100644 --- a/tree.py +++ b/tree.py @@ -18,6 +18,7 @@ from dialog import PrefSimpleFile, PrefExport from layout import open_antiprofil, TgenLayout from guifunct import TGenFrame from textaslexico import TgenSpec +from textreinert import TgenProf log = logging.getLogger('iramuteq.tree') @@ -127,6 +128,7 @@ class LeftTree(CT.CustomTreeCtrl): self.ild['chi2'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'chi2.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['reinertmatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'reinertmatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['simimatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) + self.ild['simiclustermatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.ild['proto'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'proto.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap()) self.SetImageList(self.il) @@ -142,7 +144,7 @@ class LeftTree(CT.CustomTreeCtrl): self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal) self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded) - self.textroot = self.AppendItem(self.root, u'Corpus texte') + self.textroot = self.AppendItem(self.root, _(u'Textual corpus')) self.SetPyData(self.textroot, {'uuid': 'textroot'}) self.SetItemImage(self.textroot, imgtextroot, CT.TreeItemIcon_Normal) self.SetItemImage(self.textroot, imgtextroot, CT.TreeItemIcon_Expanded) @@ -164,7 +166,7 @@ class LeftTree(CT.CustomTreeCtrl): self.SetItemImage(last, img, CT.TreeItemIcon_Normal) self.SetItemImage(last, img, CT.TreeItemIcon_Expanded) - self.matroot = self.AppendItem(self.root, u'Matrices') + self.matroot = self.AppendItem(self.root, _(u'Matrix')) self.SetPyData(self.matroot, {'uuid': 'matroot'}) self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Normal) self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Expanded) @@ -444,6 +446,8 @@ class LeftTree(CT.CustomTreeCtrl): profsr = menu.Append(wx.ID_ANY, _(u"Repeated segments profiles").decode('utf8')) profgram = menu.Append(wx.ID_ANY, _(u"POS profiles").decode('utf8')) + tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8')) + computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8')) export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpus").decode('utf8')) colored = menu.Append(wx.ID_ANY, _(u"Colored corpus").decode('utf8')) navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8')) @@ -455,6 +459,8 @@ class LeftTree(CT.CustomTreeCtrl): self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro) self.Bind(wx.EVT_MENU, self.OnProfSR, profsr) self.Bind(wx.EVT_MENU, self.OnProfGram, profgram) + self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen) + self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen) self.Bind(wx.EVT_MENU, self.OnExportCorpus, export_corpus) self.Bind(wx.EVT_MENU, self.OnColored, colored) self.Bind(wx.EVT_MENU, self.OnNavig, navig) @@ -717,8 +723,11 @@ class LeftTree(CT.CustomTreeCtrl): else : self.page.parametres['tgenpath'] = tgenpath tgen = TGen(path = tgenpath, encoding = self.parent.syscoding) - self.page.parametres['etoiles'] = self.page.etoiles - TgenSpec(self.parent, corpus, self.page.parametres) + if self.page.parametres['type'] == 'spec' : + self.page.parametres['etoiles'] = self.page.etoiles + TgenSpec(self.parent, corpus, self.page.parametres) + elif self.page.parametres['type'] == 'alceste' : + TgenProf(self.parent, corpus, self.page.parametres, self.page.cluster_size) TgenLayout(self.page) def OnExportClasses(self, event): @@ -970,6 +979,7 @@ class LeftTree(CT.CustomTreeCtrl): if select : self.history.addtab(item) self.SetItemBold(child, True) + self.SelectItem(child) #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')