- def __init__(self,nom,args,parent):
- self.nom=nom
- self.args=args
- self.children = []
- self.text=args
- self.cr = CR()
- self.cr.debut = "Début mot-clé facteur ou bloc %s" %self.nom
- self.cr.fin = "Fin mot-clé facteur ou bloc %s" %self.nom
- self.cherche_enfants()
- self.construit_liste_dico()
- parent.cr.add(self.cr)
-
- def affiche(self,ind):
- sep = ' '*5
- text = ''
- text = text + sep*ind+self.nom+'\n'
- for child in self.children :
- text = text + child.affiche(ind+1)
- return text
-
-class CATALOGUE_CATA:
- def __init__(self,parent,fichier):
- self.parent = parent
- self.fichier=fichier
- self.cr = CR()
- self.cr.debut = "Début compte-rendu catalogue %s" %self.fichier
- self.cr.fin = "Fin compte-rendu catalogue %s" %self.fichier
- self.ouvrir_fichier()
- self.liste_commandes=[]
- self.liste_textes_commandes=[]
-
- def ouvrir_fichier(self):
- try :
- f=open(self.fichier,'r')
- self.texte_complet=f.read()
- f.close()
- except e:
- print "Impossible d'ouvrir le fichier :",self.fichier
- print e
- self.cr.fatal("Impossible d'ouvrir le fichier :%s" %self.fichier)
-
- def constr_list_txt_cmd(self,text):
- text = elimine_commentaires(text)
- pattern = '\) *;'
- liste=re.split(pattern,text)
- for i in range(0,len(liste)-1):
- self.liste_textes_commandes.append(liste[i]+')')
-
- def analyse_commande_old(self,text):
- #if strip(text) == '' or strip(text) ==')': return
- liste = re.split('OPER *\(',text,1)
- if len(liste) < 2 :
- liste = re.split('PROC *\(',text,1)
- if len(liste) < 2 :
- liste = re.split('MACRO *\(',text,1)
- if len(liste) < 2 :
- print "le texte à analyser n'est pas celui d'une commande ou d'un opérateur",text
- self.cr.fatal("le texte à analyser n'est pas celui d'une commande ou d'un opérateur :%s" %text)
- return
- debut = liste[0]
- fin = liste[1]
- nom_cmd = cherche_nom(debut)
- if nom_cmd == 'erreur !':
- print "Erreur dans la recherche du nom de la commande :",debut
- args_cmd,toto = cherche_args('('+fin)
- if args_cmd == 'erreur !':
- print "Erreur dans la recherche des args de la commande :",debut
- cmd=COMMANDE_CATA(nom_cmd,args_cmd,self)
- self.liste_commandes.append(cmd)
-
- def analyse_commande(self,text):
- #if strip(text) == '' or strip(text) ==')': return
- for nom_cmd in l_noms_commandes:
- liste = re.split(nom_cmd+' *\(',text,1)
- if len(liste) == 2 : break
- if len(liste) < 2 :
- print "le texte à analyser n'est pas celui d'une commande connue :"+str(l_noms_commandes),text
- self.cr.fatal("le texte à analyser n'est pas celui d'une commande ou d'un opérateur :%s" %text)
- return
- debut = liste[0]
- fin = liste[1]
- nom_cmd = cherche_nom(debut)
- if nom_cmd == 'erreur !':
- print "Erreur dans la recherche du nom de la commande :",debut
- args_cmd,toto = cherche_args('('+fin)
- if args_cmd == 'erreur !':
- print "Erreur dans la recherche des args de la commande :",debut
- print fin
- cmd=COMMANDE_CATA(nom_cmd,args_cmd,self)
- self.liste_commandes.append(cmd)
-
- def analyse_texte(self,texte):
- self.constr_list_txt_cmd(texte)
- try:
- self.parent.configure_barre(len(self.liste_textes_commandes))
- except:
- pass
- for texte_commande in self.liste_textes_commandes :
- try:
- self.parent.update_barre()
- except:
- pass
- self.analyse_commande(texte_commande)
- self.construit_liste_dico()
-
- def ecrit_lcmd(self):
- f=open('U:\\EFICAS\\Accas\\cata.txt','w')
- for cmd in self.liste_commandes :
- f.write(cmd.affiche())
- f.close()
-
- def construit_liste_dico(self):
- l=[]
- d={}
- for cmd in self.liste_commandes:
- l.append(cmd.nom)
- d[cmd.nom]=cmd
- self.ordre_mc = l
- self.entites = d
+ def __init__(self,nom,args,parent):
+ self.nom=nom
+ self.args=args
+ self.children = []
+ self.text=args
+ self.cr = CR()
+ self.cr.debut = "Debut mot-cle facteur ou bloc %s" %self.nom
+ self.cr.fin = "Fin mot-cle facteur ou bloc %s" %self.nom
+ self.chercheEnfants()
+ self.construitListeDico()
+ parent.cr.add(self.cr)
+
+ def affiche(self,ind):
+ sep = ' '*5
+ text = ''
+ text = text + sep*ind+self.nom+'\n'
+ for child in self.children :
+ text = text + child.affiche(ind+1)
+ return text
+
+class CATALOGUE_CATA(object):
+ def __init__(self,parent,fichier):
+ self.parent = parent
+ self.fichier=fichier
+ self.cr = CR()
+ self.cr.debut = "Debut compte-rendu catalogue %s" %self.fichier
+ self.cr.fin = "Fin compte-rendu catalogue %s" %self.fichier
+ self.ouvrirFichier()
+ self.liste_commandes=[]
+ self.liste_textes_commandes=[]
+
+ def ouvrirFichier(self):
+ try :
+ with open(self.fichier) as fd:
+ self.texte_complet=fd.read()
+ except :
+ print((tr("Impossible d'ouvrir le fichier : %s ", str(self.fichier))))
+ self.cr.fatal(tr("Impossible d'ouvrir le fichier : %s ", str(self.fichier)))
+
+ def constrListTxtCmd(self,text):
+ text = elimineCommentaires(text)
+ pattern = '\) *;'
+ liste=re.split(pattern,text)
+ for i in range(0,len(liste)-1):
+ self.liste_textes_commandes.append(liste[i]+')')
+
+ def analyseCommandeOld(self,text):
+ liste = re.split(u'OPER *\(u',text,1)
+ if len(liste) < 2 :
+ liste = re.split(u'PROC *\(u',text,1)
+ if len(liste) < 2 :
+ liste = re.split(u'MACRO *\(u',text,1)
+ if len(liste) < 2 :
+ print ((tr("le texte a analyser n'est pas celui d'une commande ou d'un operateur : "), text))
+ self.cr.fatal(tr("le texte a analyser n'est pas celui d'une commande ou \
+ d'un operateur : %s", text))
+ return
+ debut = liste[0]
+ fin = liste[1]
+ nom_cmd = chercheNom(debut)
+ if nom_cmd == 'erreur !':
+ print((tr("Erreur dans la recherche du nom de la commande : "), debut))
+ args_cmd,toto = chercheArgs(u'(u'+fin)
+ if args_cmd == 'erreur !':
+ print((tr("Erreur dans la recherche des args de la commande :") , debut))
+ cmd=COMMANDE_CATA(nom_cmd,args_cmd,self)
+ self.liste_commandes.append(cmd)
+
+ def analyseCommande(self,text):
+ for nom_cmd in l_noms_commandes:
+ liste = re.split(nom_cmd+' *\(u',text,1)
+ if len(liste) == 2 : break
+ if len(liste) < 2 :
+ print((tr("le texte a analyser n'est pas celui d'une commande connue : \
+ %(v_1)s %(v_2)s", {'v_1': str(l_noms_commandes), 'v_2': text})))
+ self.cr.fatal(tr("le texte a analyser n'est pas celui d'une commande connue : \
+ %(v_1)s %(v_2)s", {'v_1': str(l_noms_commandes), 'v_2': text}))
+ return
+ debut = liste[0]
+ fin = liste[1]
+ nom_cmd = chercheNom(debut)
+ if nom_cmd == 'erreur !':
+ print(( tr("Erreur dans la recherche du nom de la commande : "), debut))
+ args_cmd,toto = chercheArgs(u'(u'+fin)
+ if args_cmd == 'erreur !':
+ print(( tr("Erreur dans la recherche des args de la commande : "), debut))
+ print((tr(fin)))
+ cmd=COMMANDE_CATA(nom_cmd,args_cmd,self)
+ self.liste_commandes.append(cmd)
+
+ def analyseTexte(self,texte):
+ self.constrListTxtCmd(texte)
+ try:
+ self.parent.configure_barre(len(self.liste_textes_commandes))
+ except:
+ pass
+ for texte_commande in self.liste_textes_commandes :
+ try:
+ self.parent.update_barre()
+ except:
+ pass
+ self.analyseCommande(texte_commande)
+ self.construitListeDico()
+
+ def ecritLcmd(self):
+ f=open(u'U:\\EFICAS\\Accas\\cata.txt','w')
+ for cmd in self.liste_commandes :
+ f.write(cmd.affiche())
+ f.close()
+
+ def construitListeDico(self):
+ l=[]
+ d={}
+ for cmd in self.liste_commandes:
+ l.append(cmd.nom)
+ d[cmd.nom]=cmd
+ self.ordre_mc = l
+ self.entites = d
+
+ def report(self):
+ """ retourne l'objet rapport du catalogue de commande """
+ return self.cr
+
+def analyseCatalogue(parent,nom_cata):
+ cata = CATALOGUE_CATA(parent,nom_cata)
+ cata.analyseTexte(cata.texte_complet)
+ return cata
+
+def analyseCatalogueCommande(parent,nom_cata):
+ cata = CATALOGUE_CATA(parent,nom_cata)
+ cata.analyseCommande(cata.texte_complet)
+ cata.construitListeDico()
+ return cata
+
+
+def makeCataPickle(ficCata):
+ """
+ Lance l'analyse de l'ordre des mots-cles dans le catalogue dont le nom
+ est passe en argument et sauvegarde ces infos dans le fichier pickle relu
+ par Eficas
+ """
+ ficCata_p = os.path.splitext(ficCata)[0]+'_pickled.py'
+ cata_ordonne = analyseCatalogue(None,ficCata)
+ f = open(ficCata_p,'w+')
+ p = six.moves.cPickle.Pickler(f)
+ p.dump(cata_ordonne.entites)
+ f.close()