From fc14fc86c13eb0ed0f420771b08cc42a5db90c01 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 28 Jan 2013 23:47:59 +0100 Subject: [PATCH] correction ++ --- PrintRScript.py | 41 +++++++++++++++++++++++++++++++++++++---- Rscripts/afc_graph.R | 8 +++++++- Rscripts/simi.R | 30 ++++++++++++++---------------- corpus.py | 16 ++++++++++------ functions.py | 29 +++++++++++++++++++++++++---- 5 files changed, 93 insertions(+), 31 deletions(-) diff --git a/PrintRScript.py b/PrintRScript.py index b80c899..b29f813 100644 --- a/PrintRScript.py +++ b/PrintRScript.py @@ -793,7 +793,28 @@ class PrintSimiScript(PrintRScript) : txt += """ mat <- as.matrix(stats::as.dist(mat,diag=TRUE,upper=TRUE)) mat[is.na(mat)] <- 0 - mat[is.infinite(mat)] <- 0 + if (length(which(mat == Inf))) { + infp <- which(mat == Inf) + mat[infp] <- NA + maxmat <- max(mat, na.rm = TRUE) + if (maxmat > 0) { + maxmat <- maxmat + 1 + } else { + maxmat <- 0 + } + mat[infp] <- maxmat + } + if (length(which(mat == -Inf))) { + infm <- which(mat == -Inf) + mat[infm] <- NA + minmat <- min(mat, na.rm = TRUE) + if (maxmat < 0) { + minmat <- minmat - 1 + } else { + minmat <- 0 + } + mat[infm] <- minmat + } """ if 'word' in self.parametres and not self.parametres['keep_coord'] : txt += """ @@ -1029,23 +1050,35 @@ class PrintSimiScript(PrintRScript) : if self.parametres['type'] == 'clustersimitxt' and self.parametres.get('sfromchi', False) : txt += """ vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2]) + if (!length(vertex.size)) vertex.size <- 0 """ else : txt += """ if (is.null(minmaxeff[1])) { - vertex.size <- NULL + vertex.size <- 0 } else { vertex.size <- graph.simi$eff } """ - txt += """ vertex.size <- NULL """ + #txt += """ vertex.size <- NULL """ if self.parametres['svg'] : svg = 'TRUE' else : svg = 'FALSE' txt += """ svg <- %s """ % svg txt += """ - coords <- plot.simi(graph.simi, p.type='%s',filename="%s", vertex.label = label.v, edge.label = label.e, vertex.col = cols, 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) + vertex.col <- cols + if (!is.null(graph.simi$com)) { + com <- graph.simi$com + colm <- rainbow(length(com)) + if (vertex.size != 0 || graph.simi$halo) { + vertex.label.color <- 'black' + vertex.col <- colm[membership(com)] + } else { + 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) save.image(file="%s") """ % (type, self.filename, self.pathout['RData']) diff --git a/Rscripts/afc_graph.R b/Rscripts/afc_graph.R index e0c2adf..5b12163 100644 --- a/Rscripts/afc_graph.R +++ b/Rscripts/afc_graph.R @@ -51,6 +51,7 @@ if ( qui == 3 ) { if ( what == 0 ) table.in <- afc$colcoord if ( what == 1 ) table.in <- afc$colcrl rownames(table.in) <- afc$colnames + eff <- afc$colmass if (typegraph == 0) { table.in<-table.in[,c(x,y)] } else { @@ -76,7 +77,12 @@ if ( qui == 3 ) { ry <- range(table.in[,2], na.rm = TRUE) rz <- range(table.in[,3], na.rm = TRUE) } - eff <- rowSums(afctable) + if (exists(afctable)) { + eff <- rowSums(afctable) + } else { + eff <- afctable$rowmass + } + if (!is.null(debsup)) { if ( qui == 0 ) { table.in <- table.in[1:(debsup-1),] diff --git a/Rscripts/simi.R b/Rscripts/simi.R index b8c2369..a582ec2 100644 --- a/Rscripts/simi.R +++ b/Rscripts/simi.R @@ -123,13 +123,17 @@ do.simi <- function(x, method = 'cooc',seuil = NULL, p.type = 'tkplot',layout.ty weori<-get.edge.attribute(g1,'weight') if (max.tree) { if (method == 'cooc') { - invw<-1/weori + invw <- 1 / weori } else { - + invw <- 1 - weori } E(g1)$weight<-invw g.max<-minimum.spanning.tree(g1) - E(g.max)$weight<-1/E(g.max)$weight + if (method == 'cooc') { + E(g.max)$weight<-1 / E(g.max)$weight + } else { + E(g.max)$weight<-1 - E(g.max)$weight + } g.toplot<-g.max } @@ -269,16 +273,8 @@ plot.simi <- function(graph.simi, p.type = 'tkplot',filename=NULL, communities = 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)#, rescale = FALSE) } else { - com <- graph.simi$com - colm <- rainbow(length(com)) - if (vertex.size != 0 || graph.simi$halo) { - vertex.label.color <- 'black' - vertex.col <- colm[membership(com)] - } else { - vertex.label.color <- colm[membership(com)] - } if (graph.simi$halo) { - mark.groups <- communities(com) + mark.groups <- communities(graph.simi$com) } else { mark.groups <- NULL } @@ -315,10 +311,12 @@ plot.simi <- function(graph.simi, p.type = 'tkplot',filename=NULL, communities = library('rgl') #rgl.open() #par3d(cex=0.8) - rglplot(g.toplot,vertex.label= vire.nonascii(v.label), edge.width=we.width/10, vertex.size=0.01, vertex.color=vertex.col, vertex.label.color="black", edge.color = edge.col, layout=lo) - los <- layout.norm(lo, -1, 1, -1, 1, -1, 1) - rgl.spheres(los, col = vertex.col, radius = vertex.size/100, alpha = alpha) - rgl.bg(color = c('white','black')) + lo <- layout.norm(lo, -10, 10, -10, 10, -10, 10) + rglplot(g.toplot,vertex.label='', edge.width=we.width/10, vertex.size=0.01, vertex.color=vertex.col, vertex.label.color="black", edge.color = edge.col, layout=lo, rescale = FALSE) + #los <- layout.norm(lo, -1, 1, -1, 1, -1, 1) + text3d(lo[,1], lo[,2], lo[,3], vire.nonascii(v.label), col = vertex.label.color, alpha = 1, cex = vertex.label.cex) + rgl.spheres(lo, col = vertex.col, radius = vertex.size/100, alpha = alpha) + rgl.bg(color = c('white','black')) if (!is.null(movie)) { require(tcltk) ReturnVal <- tkmessageBox(title="RGL 3 D",message="Cliquez pour commencer le film",icon="info",type="ok") diff --git a/corpus.py b/corpus.py index 44ea0ef..ec27764 100644 --- a/corpus.py +++ b/corpus.py @@ -281,8 +281,8 @@ class Corpus : for uci in self.ucis : get = list(set(uci.etoiles).intersection(etoiles)) if len(get) > 1 : - return '2 variables sur la meme ligne' - elif get != [] : + log.info('2 variables sur une ligne') + if get != [] : etuces[etoiles.index(get[0])] += [uce.ident for uce in uci.uces] etuces = [set(val) for val in etuces] tab = [] @@ -1116,7 +1116,6 @@ class BuildFromAlceste(BuildCorpus) : log.info(u'Empty text : %i' % linenb) iduci -= 1 self.corpus.ucis.pop() - #raise Exception("EmptyText %i" % linenb) self.corpus.ucis.append(Uci(iduci, line)) if self.dlg is not None : if not (iduci + 1) % 10 : @@ -1129,19 +1128,24 @@ class BuildFromAlceste(BuildCorpus) : idpara += 1 self.corpus.ucis[-1].paras.append(line.split()[0]) else : - raise Exception('paragrapheOT') + raise Exception('paragrapheOT %i' % linenb) elif line.strip() != '' and iduci != -1 : txt.append(line) if txt != [] and iduci != -1 : iduce, idpara = self.treattxt(txt, iduce, idpara, iduci) del(txt) else : - raise Exception("EmptyText") + if iduci != -1 : + iduci -= 1 + self.corpus.ucis.pop() + log.info(Exception("Empty text %i" % linenb)) + else : + raise Exception('EmptyText %i' % linenb) if iduci != -1 and iduce != -1: self.backup_uce() else : log.info(_(u"No Text in corpora. Are you sure of the formatting ?")) - raise Exception('TextBeforeTextMark') + raise Exception('TextBeforeTextMark %i' % linenb) except UnicodeDecodeError : raise Exception("CorpusEncoding") diff --git a/functions.py b/functions.py index 90b380e..28d648e 100644 --- a/functions.py +++ b/functions.py @@ -212,7 +212,9 @@ class BugDialog(wx.Dialog): kwds["style"] = wx.DEFAULT_DIALOG_STYLE kwds["size"] = wx.Size(500, 200) wx.Dialog.__init__(self, *args, **kwds) + self.SetTitle(kwds['title']) self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE) + self.text_ctrl_1.SetBackgroundColour('#DDE8EB') self.button_1 = wx.Button(self, wx.ID_OK, "") self.__set_properties() @@ -221,7 +223,6 @@ class BugDialog(wx.Dialog): def __set_properties(self): # begin wxGlade: MyDialog.__set_properties - self.SetTitle("Bug") self.SetMinSize(wx.Size(500, 200)) self.text_ctrl_1.SetMinSize(wx.Size(500, 200)) @@ -404,21 +405,41 @@ def decoupercharact(chaine, longueur, longueurOptimale, separateurs = None) : # si on a rien trouvé return False, chaine.split(), '' + +exceptions = {'paragrapheOT' : u"Un problème de formatage (présence d'un marqueur de paragraphe (-*) en dehors d'un texte) est survenu à la ligne ", + 'EmptyText' : u"Texte vide (probablement un problème de formatage du corpus). Le problème est apparu à la ligne ", + 'CorpusEncoding' : u"Problème d'encodage.", + 'TextBeforeTextMark' : u"Problème de formatage : du texte avant le premier marqueur de texte (****). Le problème est survenu à la ligne ", +} + def BugReport(parent, error = None): for ch in parent.GetChildren(): if "" == str(type(ch)): ch.Destroy() excName, exc, excTb = formatExceptionInfo() if excName == 'Exception' : - txt = 'Message :\n' + print exc + if len(exc.split()) == 2 : + mss, linenb = exc.split() + if mss in exceptions : + txt = exceptions[mss] + linenb + else : + txt = exc + else : + if exc in exceptions : + txt = exceptions[mss] + else : + txt = exc + title = "Information" else : txt = u' !== BUG ==! \n' txt += u'*************************************\n' txt += '\n'.join(excTb).replace(' ', ' ') txt += excName + '\n' - txt += exc + txt += exc + title = "Bug" - dial = BugDialog(parent) + dial = BugDialog(parent, **{'title' : title}) if 'Rerror' in dir(parent) : txt += parent.Rerror parent.Rerror = '' -- 2.7.4