import expert """ Rule database Any rules starting with "Rule_" will be automatically intantiated by Expert.rules_init() Rules not starting with "Rule_" must be manually intantiated and added to the system via 'Expert.rule_add(rule)' """ class Rule_1a(expert.Rule): """determine weather: if temp > 70, it's warm""" def match(self, facts): return int(facts.get('temp')) >= 70 def fire(self, facts): facts.set('weather', 'warm') class Rule_1b(expert.Rule): """determine weather: if temp < 70, it's cold""" def match(self, facts): return int(facts.get('temp')) < 70 def fire(self, facts): facts.set('weather', 'cold') class Rule_1a1(expert.Rule): """if it's warm and not cloudy, wear shorts""" def match(self, facts): return facts.get('weather') == 'warm' and not facts.get('cloudy') def fire(self, facts): facts.set('action', "Wear Shorts") class Rule_1a2(expert.Rule): """if it's warm and cloudy, bring an umbrella""" def match(self, facts): return facts.get('weather') == 'warm' and facts.get('cloudy') def fire(self, facts): facts.set('action', "Bring Umbrella") class Rule_1b1(expert.Rule): """if it's cold and not cloudy, wear pants""" def match(self, facts): return facts.get('weather') == 'cold' and not facts.get('cloudy') def fire(self, facts): facts.set('action', "Wear Pants") class Rule_1b2(expert.Rule): """if it's cold and cloudy, wear galoshes""" def match(self, facts): return facts.get('weather') == 'cold' and facts.get('cloudy') def fire(self, facts): facts.set('action', "Wear Galoshes")