diff --git a/lab4/unificateur.py b/lab4/unificateur.py index 24c8ae0..3fd6c96 100755 --- a/lab4/unificateur.py +++ b/lab4/unificateur.py @@ -67,7 +67,7 @@ ## @ret une substitution {variable:datum} ################################################################################ def construitSubstitution(variable, datum): - ... + return {variable: datum} ################################################################################ ############################################################################### @@ -75,8 +75,8 @@ ## @param substitution la substitution ## @ret la variable de la substitution ################################################################################ -def retourneVariable(substituion): - ... +def retourneVariable(sub): + return sub.keys()[0] ################################################################################ ############################################################################### @@ -84,8 +84,8 @@ ## @param substitution la substitution ## @ret la valeur de la substitution ################################################################################ -def retourneValeur(substituion): - ... +def retourneValeur(sub): + return sub.values()[0] ################################################################################ ############################################################################### @@ -94,8 +94,11 @@ ## @param substituions la liste des substituion ## @ret la substitution associ� � la varibale si elle existe, sinon retourn False ################################################################################ -def trouveSubstitution(variable, substitutions): - ... +def trouveSubstitution(variable, subs): + if testeSubstitution(subs) and subs.has_key(variable): + return {variable: subs[variable]} + else: + return False ################################################################################ ########################..####################################################### @@ -104,8 +107,8 @@ ## @param substituions la liste des substituion ## @ret True <=> variable est dans les substitutions; else False ################################################################################ -def variableDansSubstitutions(variable, substitutions): - ... +def variableDansSubstitutions(variable, subs): + return subs.has_key(variable) ################################################################################ ############################################################################### @@ -114,8 +117,12 @@ ## @param substitution2 la deuxieme substitution ## @ret substitution1 UNION substitution2; echec if substitution1 ou substitution2 ne sont pas des substitutions ############################################################################### -def unionSubstitution(substitution1,substitution2): - ... +def unionSubstitution(sub1,sub2): + if testSubstitution(sub1) and testeSubstitution(sub2): + sub1.update(sub2) + return sub1 + else: + return echec ############################################################################### ## retourne la proposition avec les variables remplacees par leurs valeurs ## @param pattern la proposition (contient des variables, atomes,... sous forme [' ',' ', ' '] OU ' ' ou ['[]'...]) @@ -142,7 +149,7 @@ ## @ret substitution dans un dico is le filtrage reussi : {'?x':'a',...}, 'FAIL' sinon ############################################################################### def unifit(proposition1, proposition2): - ... + pass ###############################################################################