1 # -*- coding: utf-8 -*-
4 from parseur import FactNode
12 def __init__(self,liste_regles):
14 for item in liste_regles :
16 r=regle(clefRegle,args)
19 def verif(self,commande) :
21 for regle in self.liste :
22 result=regle.verif(commande)
26 #--------------------------------
27 class pasDeRegle(ensembleRegles):
28 #--------------------------------
32 def verif (self,commande) :
40 def __init__(self,clef_regle,args):
41 self.fonction=dictionnaire_regle[clef_regle]
45 def verif(self,commande):
46 f=self.fonction(self.list_args)
47 return f.verif(commande)
49 #---------------------
50 class existeMCFParmi :
51 #---------------------
52 def __init__(self,list_arg):
53 self.listeMCF=list_arg;
55 def verif(self,commande):
57 for c in commande.childNodes :
58 if c.name in self.listeMCF :
63 #----------------------
64 class existeMCsousMCF :
65 #----------------------
66 def __init__(self,list_arg):
68 self.MCF=self.liste[0]
71 def verif(self,commande):
73 for mcf in commande.childNodes :
74 if mcf.name != self.MCF : continue
78 for mc in ll.childNodes:
79 if mc.name != self.MC : continue
83 #-----------------------------------------
84 class nexistepasMCsousMCF(existeMCsousMCF):
85 #-----------------------------------------
86 def __init__(self,list_arg):
87 existeMCsousMCF.__init__(self,list_arg)
90 def verif(self,commande):
91 bool=existeMCsousMCF.verif(self,commande)
98 def __init__(self,list_arg):
101 def cherche_mot(self,niveau,commande):
102 if commande == None : return 0
103 if niveau == len(self.genea) : return 1
104 texte=self.genea[niveau]
105 for c in commande.childNodes :
108 return self.cherche_mot(niveau,c)
111 def verif(self,commande):
112 bool=self.cherche_mot(0,commande)
113 if bool == None : bool = 0
119 def __init__(self,list_arg):
122 def cherche_mot(self,niveau,commande):
123 if commande == None : return 0
124 if niveau == len(self.genea) : return 1
125 texte=self.genea[niveau]
126 for c in commande.childNodes :
129 return self.cherche_mot(niveau,c)
132 def verif(self,commande):
133 bool=self.cherche_mot(0,commande)
137 #-------------------------------
138 class MCsousMCFaPourValeur :
139 #------------------------------
140 def __init__(self,list_arg):
141 assert (len(list_arg)==4)
142 self.genea=list_arg[0:-2]
148 def verif(self,commande):
150 for mcf in commande.childNodes :
151 if mcf.name != self.MCF : continue
155 for mc in ll.childNodes:
156 if mc.name != self.MC : continue
157 TexteMC=mc.getText(self.Jdc)
158 if (TexteMC.find(self.Val) < 0 ): continue
162 #-------------------------------
163 class MCaPourValeur :
164 #------------------------------
165 def __init__(self,list_arg):
166 assert (len(list_arg)==3)
171 def verif(self,commande):
173 for mc in commande.childNodes :
174 if mc.name != self.MC : continue
175 TexteMC=mc.getText(self.Jdc)
176 if (TexteMC.find(self.Val) < 0 ): continue
180 dictionnaire_regle={"existe":existe,"nexistepas":nexistepas,"existeMCFParmi":existeMCFParmi,"existeMCsousMCF":existeMCsousMCF,"nexistepasMCsousMCF":nexistepasMCsousMCF,"MCsousMCFaPourValeur":MCsousMCFaPourValeur,"MCaPourValeur":MCaPourValeur}
181 SansRegle=pasDeRegle()