Package medite :: Package Donnees :: Module resultatAppli
[hide private]
[frames] | no frames]

Source Code for Module medite.Donnees.resultatAppli

  1  # -*- coding: iso-8859-1 -*- 
  2  # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) 
  3  # This file is part of MEDITE. 
  4  # 
  5  #    MEDITE is free software; you can redistribute it and/or modify 
  6  #    it under the terms of the GNU General Public License as published by 
  7  #    the Free Software Foundation; either version 2 of the License, or 
  8  #    (at your option) any later version. 
  9  # 
 10  #    MEDITE is distributed in the hope that it will be useful, 
 11  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  #    GNU General Public License for more details. 
 14  # 
 15  #    You should have received a copy of the GNU General Public License 
 16  #    along with Foobar; if not, write to the Free Software 
 17  #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 18  #---------------------------------------------------------------------------- 
 19  # Nom:          resultatAppli.py 
 20  # Objet:        Classe qui regroupe les donnees d'une comparaison d'un couple 
 21  #               de etats  ( utilisee par l'interface )               
 22  #---------------------------------------------------------------------------- 
 23  import sys,logging,contract,Utile.decodage 
 24  import numpy 
 25  import planTravail 
 26  import MediteAppli.utile 
 27  contract.checkmod(__name__) 
 28   
29 -class Resultat(object):
30 """ Classe qui retourne le resulat obtenu apres comparaison de deux etats """
31 - def __init__(self, pLI, pLS, pLD, pLR, pLgSource, pTextes, pBlocsCommuns, pairesBlocsDepl):
32 self._li = pLI # liste des insertions 33 self._ls = pLS # liste des suppression 34 self._ld = pLD # liste des deplacements 35 self._lr = pLR # liste des remplacements 36 self._lgTexteS = pLgSource # longueur du texte source 37 self._textes = pTextes # les deux etats concatenes 38 self._blocsCom = pBlocsCommuns # blocs communs 39 self._pairesBlocsDepl = pairesBlocsDepl #paires de blocs déplacés
40
41 - def getListeInsertions(self):
42 return self._li
43
44 - def getListeSuppressions(self):
45 return self._ls
46
47 - def getListeDeplacements(self):
48 return self._ld
49
50 - def _filtre(self,liste,deb,fin):
51 """ Renvoie la sous-liste des items de liste compris entre deb et fin 52 53 pre: 0<=deb<fin #<=len(self._textes) 54 post: isinstance(__return__,list) 55 forall([x in __return__],deb<=x[0]<=x[1]<=fin) 56 """ 57 res=[] 58 for x in liste: 59 if deb <= x[0] < x[1] <= fin: 60 res.append(x) 61 return res
62
63 - def getListeDeplacementsT1(self):
64 return self._filtre(self._ld,0,self._lgTexteS)
65
66 - def getListeDeplacementsT2(self):
67 return self._filtre(self._ld,self._lgTexteS,len(self._textes))
68
69 - def getListeRemplacements(self):
70 return self._lr
71
72 - def getListeRemplacementsT1(self):
73 return self._filtre(self._lr,0,self._lgTexteS)
74
75 - def getListeRemplacementsT2(self):
76 return self._filtre(self._lr,self._lgTexteS,len(self._textes))
77
78 - def getTextesConcatenes(self):
79 return self._textes
80
81 - def getLgSource(self):
82 return self._lgTexteS
83
84 - def getBlocsCommuns(self):
85 return self._blocsCom
86
87 - def getBlocsCommunsT1(self):
88 return self._filtre(self._blocsCom,0,self._lgTexteS)
89
90 - def getBlocsCommunsT2(self):
91 return self._filtre(self._blocsCom,self._lgTexteS,len(self._textes))
92
93 - def getPairesBlocsDeplaces(self):
94 return self._pairesBlocsDepl
95
96 - def setPairesBlocsDeplaces(self,liste):
97 self._pairesBlocsDepl = liste
98
99 - def toString_(self):
100 s = u"Type RESULTAT \nInsertions : " 101 for i in self._li: 102 s += unicode(i).encode("iso-8859-2", "replace")+u" / " 103 s += u"\nSuppressions : " 104 for i in self._ls: 105 s += unicode(i).encode("iso-8859-2", "replace")+u" / " 106 s += u"\nDéplacements : " 107 for i in self._ld: 108 s += unicode(i).encode("iso-8859-2", "replace")+u" / " 109 s += "\nRemplacements : " 110 if self._lr != []: 111 for i in self._lr: 112 s += unicode(i).encode("iso-8859-2", "replace")+" / " 113 114 # s2,x,y = Utile.decodage.decode_string_heuristically(self._texteCible.toxml()) 115 # s += s2 116 # s += unicode(self._texteCible).encode("iso-8859-2", "replace") 117 s += "\nBlocs communs : " 118 if self._blocsCom != []: 119 for i in self._blocsCom: 120 s += "[" 121 for ii in i: 122 #iii,x,y=Utile.decodage.decode_string_heuristically(ii) 123 s += str(ii)+"/" 124 s +="]" 125 s += "\n lgTexteSource : "+str(self._lgTexteS) 126 sys.stderr.write(unicode(s).encode("iso-8859-2", "replace")) 127 sys.stderr.flush()
128
129 - def toString(self):
130 """Retourne le texte correspondant aux listes de blocs""" 131 f = lambda res,l: [res.append(self.getTextesConcatenes()[x[0]:x[1]]) for x in l] 132 def f(res,l): 133 """Fonction anonyme permettant de traiter les paires de blocs déplacés""" 134 for x in l: 135 if isinstance(x,tuple):#les paires de Bloc deplacé sont des tuples 136 res.extend(['(', self.getTextesConcatenes()[x[0][0]:x[0][1]], 137 '/',self.getTextesConcatenes()[x[1][0]:x[1][1]],')']) 138 else:# bloc normal 139 res.extend(['(',self.getTextesConcatenes()[x[0]:x[1]],')'])
140 return self.__str(f)
141
142 - def __str__(self):
143 """Retourne uniquement les listes de blocs""" 144 f = lambda res,l: [res.append(str(x)) for x in l] 145 return "longueur T1="+str(self._lgTexteS)+"\n"+self.__str(f)
146
147 - def __str(self,f):
148 """Fonction privée construisant la chaine à retourner 149 150 f est une fonction concaténant de la manière souhaitée le bloc courant 151 152 pre: callable(f)""" 153 res = ['BC :'] 154 #f = lambda l: [res.append(str(x)) for x in l] 155 f(res,self.getBlocsCommuns()) 156 res.append('\nDEP: ') 157 f(res,self.getListeDeplacements()) 158 res.append('\nPDEP: ') 159 f(res,self.getPairesBlocsDeplaces()) 160 res.append('\nSUP: ') 161 f(res,self.getListeSuppressions()) 162 res.append('\nINS: ') 163 f(res,self.getListeInsertions()) 164 res.append('\nREMP: ') 165 f(res,self.getListeRemplacements()) 166 return ''.join(res) 167
168 - def __xor__(self,res):
169 """Différence symétrique 170 171 Extrait les intervalles de chaque liste présents dans l'un ou l'autre des 2 objets 172 mais pas dans les 2, cad une différence symétrique de chaque liste. 173 174 pre: isinstance(res,Resultat) """ 175 assert self.getTextesConcatenes() == res.getTextesConcatenes() # on traite bien le meme texte 176 assert self.getLgSource() == res.getLgSource() 177 bc = self.__diff_sym(self.getBlocsCommuns(), res.getBlocsCommuns()) 178 dep = self.__diff_sym(self.getListeDeplacements(), res.getListeDeplacements()) 179 pdep = self.__diff_sym(self.getPairesBlocsDeplaces(), res.getPairesBlocsDeplaces()) 180 ins = self.__diff_sym(self.getListeInsertions(), res.getListeInsertions()) 181 sup = self.__diff_sym(self.getListeSuppressions(), res.getListeSuppressions()) 182 remp = self.__diff_sym(self.getListeRemplacements(), res.getListeRemplacements()) 183 184 return Resultat(ins, sup, dep, remp, self.getLgSource(), 185 self.getTextesConcatenes(),bc, pdep)
186
187 - def __diff_sym(self,L1,L2):
188 """Différence symétrique effective de 2 listes: (L1 - L2) U (L2 - L1) """ 189 tool = MediteAppli.utile.Utile() 190 res = [] 191 for x in L1: 192 if x not in L2: res = tool.addition_intervalle(res,x) # addition sans fusion 193 for x in L2: 194 if x not in L1: res = tool.addition_intervalle(res,x) 195 return res
196
197 - def __sub__(self,res):
198 """Différence: objet courant - res""" 199 assert self.getTextesConcatenes() == res.getTextesConcatenes() # on traite bien le meme texte 200 assert self.getLgSource() == res.getLgSource() 201 bc = self.__diff(self.getBlocsCommuns(), res.getBlocsCommuns()) 202 dep = self.__diff(self.getListeDeplacements(), res.getListeDeplacements()) 203 pdep = self.__diff(self.getPairesBlocsDeplaces(), res.getPairesBlocsDeplaces()) 204 ins = self.__diff(self.getListeInsertions(), res.getListeInsertions()) 205 sup = self.__diff(self.getListeSuppressions(), res.getListeSuppressions()) 206 remp = self.__diff(self.getListeRemplacements(), res.getListeRemplacements()) 207 208 return Resultat(ins, sup, dep, remp, self.getLgSource(), 209 self.getTextesConcatenes(),bc, pdep)
210 - def __diff(self,L1,L2):
211 """Différence effective de 2 listes: (L1 - L2)""" 212 tool = MediteAppli.utile.Utile() 213 res = [] 214 for x in L1: 215 if x not in L2: res = tool.addition_intervalle(res,x) # addition sans fusion 216 return res
217
218 -class Resultat__(Resultat): #buggé
219 - def __init__(self, pLI, pLS, pLD, pLR, pLgSource, pTextes, pBlocsCommuns, pairesBlocsDepl):
220 ResultatListe.__init__(self,[], [], [], [], pLgSource, pTextes, [], []) 221 self._li = self.__listeToTab(pLI) 222 self._ls = self.__listeToTab(pLS) 223 self._ld = self.__listeToTab(pLD) 224 self._lr = self.__listeToTab(pLR) 225 self._blocsCom = self.__listeToTab(pBlocsCommuns) 226 self._pairesBlocsDepl = self.__listeToTab(pairesBlocsDepl)
227
228 - def __listeToTab(self, liste):
229 if isinstance(liste,list): 230 tab = numpy.array(liste)#, Numeric.Int16) 231 else: tab = liste # c deja un array 232 return tab
233
234 - def getListeInsertions(self):
235 return self._li.tolist()
236 - def getListeSuppressions(self):
237 return self._ls.tolist()
238 - def getListeDeplacements(self):
239 return self._ld.tolist()
240 - def getListeDeplacementsT1(self):
241 return self._filtre(self._ld,0,self._lgTexteS)
242 - def getListeDeplacementsT2(self):
243 return self._filtre(self._ld,self._lgTexteS,len(self._textes))
244 - def getListeRemplacements(self):
245 return self._lr.tolist()
246 - def getListeRemplacementsT1(self):
247 return self._filtre(self._lr,0,self._lgTexteS)
248 - def getListeRemplacementsT2(self):
249 return self._filtre(self._lr,self._lgTexteS,len(self._textes))
250 - def getBlocsCommuns(self):
251 return self._blocsCom.tolist()
252 - def getBlocsCommunsT1(self):
253 return self._filtre(self._blocsCom,0,self._lgTexteS)
254 - def getBlocsCommunsT2(self):
255 return self._filtre(self._blocsCom,self._lgTexteS,len(self._textes))
256 - def getPairesBlocsDeplaces(self):
257 return self._pairesBlocsDepl.tolist()
258 - def setPairesBlocsDeplaces(self,liste):
259 self._pairesBlocsDepl = self.__listeToTab(liste)
260
261 -class Informations(object):
262 - def __init__(self, pVersionSource, pEtatSource, pVersionCible, pEtatCible, 263 pParametres, pTransformations, pCommentaire = None):
264 """ pre: isinstance(pVersionSource,str) and isinstance(pEtatSource,str) 265 isinstance(pVersionCible,str) and isinstance(pEtatCible,str) 266 isinstance(pParametres,planTravail.Parametres) 267 isinstance(pTransformations,Transformations) 268 (pCommentaire==None or isinstance(pCommentaire,Commentaire)) """ 269 self.__versionSource = pVersionSource 270 self.__etatSource = pEtatSource 271 self.__versionCible = pVersionCible 272 self.__etatCible = pEtatCible 273 self.__parametres = pParametres 274 self.__transformations = pTransformations 275 self.__commentaire = pCommentaire
276 277 # Methodes d'acces aux attributs
278 - def getVersionSource(self):
279 return self.__versionSource
280 - def getEtatSource(self):
281 return self.__etatSource
282 - def getVersionCible(self):
283 return self.__versionCible
284 - def getEtatCible(self):
285 return self.__etatCible
286 - def getParametres(self):
287 return self.__parametres
288 - def getTransformations(self):
289 return self.__transformations
290 - def getCommentaire(self):
291 return self.__commentaire
292
293 - def existeCommentaire(self):
294 """ Verifie si le commentaire existe """ 295 if self.__commentaire == None: 296 return 1 ## FAUX 297 else: 298 return 0 ## VRAI
299 - def existeTransformations(self):
300 """ Verifie si les transformations existent """ 301 if self.__transformations == None: 302 return 1 ## FAUX 303 else: 304 return 0 ## VRAI
305 # Methode de modification d'attribut 306 # Seul le commentaire est modifiable
307 - def setCommentaire(self, pCommentaire):
308 self.__commentaire = pCommentaire
309
310 -class Transformations(object):
311 - def __init__(self, pInsertions, pSuppressions, pDeplacements, pRemplacements, pTexteSource, pTexteCible):
312 ## les attributs ci-dessous sont des listes de sequence de caracteres 313 self.__insertions =pInsertions 314 self.__suppressions =pSuppressions 315 self.__deplacements = pDeplacements 316 self.__remplacements = pRemplacements 317 ## les attributs ci-dessous sont des noeuds xml 318 self.__texteSource = pTexteSource 319 self.__texteCible = pTexteCible
320
321 - def getInsertions(self):
322 return self.__insertions
323
324 - def getSuppressions(self):
325 return self.__suppressions
326
327 - def getDeplacements(self):
328 return self.__deplacements
329
330 - def getRemplacements(self):
331 return self.__remplacements
332
333 - def getSource(self):
334 return self.__texteSource
335
336 - def getCible(self):
337 return self.__texteCible
338
339 - def toString(self):
340 s = u"Type TRANSFORMATION\nInsertions : " 341 for i in self.__insertions: 342 s += i+u" / " 343 s += u"\nSuppressions : " 344 for i in self.__suppressions: 345 s += i+u" / " 346 s += u"\nDéplacements : " 347 for i in self.__deplacements: 348 s += i+u" / " 349 s += "\nRemplacements : " 350 if self.__remplacements: 351 for i in self.__remplacements: 352 s += unicode(i).encode("iso-8859-2", "replace")+" / " 353 s += "\nTexteSource : " 354 #s += unicode(self.__texteSource.toxml()).encode("iso-8859-2", "replace") 355 s2,x,y = Utile.decodage.decode_string_heuristically(self.__texteSource.toxml()) 356 s += s2 357 # if self.__texteSource != []: 358 # for i in self.__texteSource: 359 # s += unicode(i).encode("iso-8859-2", "replace")+" / " 360 s += "\nTexteCible : " 361 s2,x,y = Utile.decodage.decode_string_heuristically(self.__texteCible.toxml()) 362 s += s2 363 # s += unicode(self.__texteCible).encode("iso-8859-2", "replace") 364 # if self.__texteCible != []: 365 # for i in self.__texteCible: 366 # s += unicode(i).encode("iso-8859-2", "replace")+" / " 367 sys.stderr.write(unicode(s).encode("iso-8859-2", "replace")) 368 sys.stderr.flush()
369 370
371 -class Commentaire(object):
372 - def __init__(self, pCommentaire):
373 self.__commentaire = pCommentaire
374 # Methode d'acces a l'attribut
375 - def getCommentaire(self):
376 return self.__commentaire
377 # Methodes de modification de l'attribut 378 # Methode qui remplace le commentaire
379 - def setCommentaire(self, pCommentaire):
380 self.__commentaire = pCommentaire
381 # Methode qui ajoute du texte au commentaire
382 - def addCommentaire(self, pCommentaire):
383 self.__commentaire += ' ' + pCommentaire
384