How to use addRule method in avocado

Best Python code snippet using avocado_python

expert.py

Source:expert.py Github

copy

Full Screen

...16 def __init__(self, verb = True):17 self.facts=[]18 self.rules=[]19 self.verb = verb20 def addRule(self,r):21 self.rules.append(r)22 def addFact(self,f):23 print("Adding fact ", f)24 self.facts.append(f)25 def rectractFact(self,f):26 self.facts.remove(f)27 def _propagateRule(self,rule):28 empty = True29 ret = False30 for pre in rule.pre:31 if self.verb: print("evaluating ", pre)32 if pre not in self.facts:33 empty = False34 break35 if empty:36 if self.verb: print("Propagating rule " + str(rule.pre) + " => " + str(rule.post))37 for post in rule.post:38 if post not in self.facts:39 if self.verb: print("Adding " + post + " as a new fact") 40 self.addFact(post)41 ret = True # At least one fact has been added42 rule.active = False43 return ret44 def simpleFC(self):45 "Simple Forward Checking algorithm. No smart data structure used"46 loop = True # True if any fact has been added47 while loop:48 loop = False49 for rule in self.rules:50 if rule.active:51 loop |= self._propagateRule(rule)52 def _getRulesForFact(self, fact):53 "Returns the list of rules that contains this fact as a post"54 return [rule for rule in self.rules if fact in rule.post]55 def _ask(self, f):56 "Asks for the value of a fact"57 print ("Asking for " + str(f) + " to become a new fact")58 answer = input()59 # print("Forcing " + str(f) + " as a new Fact")60 if answer == "Yes" or answer == "Y" or answer == "y" or answer == "yes":61 print("Fact added")62 self.addFact(f) # By default make it true63 return True64 print("Fact refused")65 return False66 def simpleBC(self, fact):67 "Simple Backward chaining for a fact, returns after any new fact is added after any question"68 print("BC for fact " + str(fact))69 for rule in self._getRulesForFact(fact):70 print(rule)71 for pre in rule.pre:72 if pre not in self.facts:73 rulespre = self._getRulesForFact(pre)74 if not rulespre: # no rules conclude on it. This is an askable fact75 res = self._ask(pre)76 if res:77 return True78 else:79 return self.simpleBC(pre)80 return False81kb = KB()82#kb.addRule(Rule("Toto & Titi => yy & jj"))83#kb.addRule(Rule("yy & Titi => tt"))84#kb.addRule(Rule("jj & tt => youpi"))85#kb.addRule(Rule("jj & ttt => pryoupi"))86#kb.addFact("Toto")87#kb.addFact("Titi")88print("Création du système expert sur la vie")89print("Ajout des règles")90kb.addRule(Rule("mangé => rassasié"))91kb.addRule(Rule("dormi => reposé"))92kb.addRule(Rule("couple => amour"))93kb.addRule(Rule("mariage => banquet & amour"))94kb.addRule(Rule("discussion => interaction"))95kb.addRule(Rule("repas => mangé"))96kb.addRule(Rule("banquet => bien mangé"))97kb.addRule(Rule("interaction => joie sociale"))98kb.addRule(Rule("bien dormi => dormi & joie physique"))99kb.addRule(Rule("bien mangé => mangé & joie physique"))100kb.addRule(Rule("apprentissage & intelligent => joie mentale"))101kb.addRule(Rule("amour => heureux"))102kb.addRule(Rule("joie physique => partiellement heureux"))103kb.addRule(Rule("joie sociale => partiellement heureux"))104kb.addRule(Rule(" joie mentale => partiellement heureux"))105kb.addRule(Rule("joie sociale & joie physique => heureux"))106kb.addRule(Rule("joie sociale & joie mentale => heureux"))107kb.addRule(Rule(" joie physique & joie mentale => heureux"))108kb.addRule(Rule("joie sociale & joie physique & joie mentale => completement heureux"))109kb.addRule(Rule("completement heureux => heureux")) #useless, tant qu'une autre manière d'être heureux n'existe pas110kb.addRule(Rule("heureux => partiellement heureux")) #useless, tant qu'une autre manière d'être heureux n'existe pas111kb.addRule(Rule("rassasié & reposé => vivant"))112kb.addRule(Rule("vivant & complètement heureux => plénitude"))113print("Ajout des faits de base") 114print("Fin de la création du système expert")115print("Début de la simulation") #ptet faire une boucle en fin qui transforme les "rassasié 100%" en "rassasié 75%"116# faits à rechercher dans l'ordre de priorité: vivant -> plénitude117# faits constants (à définir dès le début): couple118kb.simpleFC()119print(1)120res = True121while res:122 res = kb.simpleBC("youpi")123print(2)124kb.simpleFC()...

Full Screen

Full Screen

4ab75c43343e3d5919ba318ad54b0297f9f70fa5routes.py

Source:4ab75c43343e3d5919ba318ad54b0297f9f70fa5routes.py Github

copy

Full Screen

...13 LoginReminderController, SetPasswordController14)15import purpledefrag.app.g as g16routes = g.routes17#routes.addRule("reminder", ReminderController)18routes.addRule("entrance", LoginReminderController)19#routes.addRule("entrance", HadesController)20routes.addRule("login", LoginController)21routes.addRule("logout", LogoutController)22routes.addRule("register", RegistrationController)23routes.addRule("whoami", WhoController)24routes.addRule("random", RandomMapController)25routes.addRule("findmap", RandomMapController)26routes.addRule("h", HelpController)27routes.addRule("time", TimeController)28routes.addRule("me", MeController)29routes.addRule("mapinfo", MapInfoController)30routes.addRule("clienttimerstop", FinishLineController)31routes.addRule("clientspeedaward", SpeedAwardController)32routes.addRule("top", RankingsController)33routes.addRule("topspeed", SpeedRankingsController)34routes.addRule("mytop", BestTimeController)35routes.addRule("mypr", BestTimeController)36routes.addRule("pr", RankingsController)37routes.addRule("hip", TomController)38routes.addRule("wr", WorldRecordController)39routes.addRule("mdd", WorldRecordController)40routes.addRule("setpass", SetPasswordController)41routes.addRule("trouve", RandomMapController)42'''routes.addRule("newmaps", newmaps)43routes.addRule("request", maprequest)44routes.addRule("coolmap", upvote)45routes.addRule("crapmap", downvote)46routes.addRule("lastmap", lastmap)47def tom(request):48 from purpledefrag import BunnyResponse49 return BunnyResponse("^6Hippeh is piece full. Bunny luf hippeh.")50routes.addRule("tom", tom)51def me(request):52 from purple import ChatResponse53 return ChatResponse("^2^ --- that guy likes to talk in third person.")...

Full Screen

Full Screen

pascals-triangle-puzzle-2.py

Source:pascals-triangle-puzzle-2.py Github

copy

Full Screen

1from csp import Problem2p = Problem()3pvars = "R2 R3 R5 R6 R7 R8 R9 R10 X Y Z".split()4# 0-151 is the possible finite range of the variables5p.addvars(pvars, range(152))6p.addrule("R7 == X + 11")7p.addrule("R8 == Y + 11")8p.addrule("R9 == Y + 4")9p.addrule("R10 == Z + 4")10p.addrule("R7 + R8 == 40")11p.addrule("R5 == R8 + R9")12p.addrule("R6 == R9 + R10")13p.addrule("R2 == 40 + R5")14p.addrule("R3 == R5 + R6")15p.addrule("R2 + R3 == 151")16p.addrule("Y == X + Z")17for sol in p.xsolutions():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful