Description
This is a very simple and basic "Expert system" that i built for a
school assignment.
It handles rule matching, rule firing, logging and a basic facts database.
It has no support for things like certainty factors or fuzzy values.
expert.py
TODO: Flesh this out
class expert.Expert()
The expert engine
class expert.Logger()
Logs rule firings and fact changes
class expert.Facts()
Facts container.
Reponsible for getting and setting fact attributes.
class expert.Rule()
The base rule which other rules should inheirit from.
Example code
"""Example code"""
import expert # download expert.py
import rules1 # download rules1.py
# This function determines if an answer has been found.
# (i.e. the system is in a 'final' state)
# It is run everytime a matched rule fires.
def is_final(facts):
"""Return true when 'final_flag' is set"""
return facts.get('final_flag')
# Initialize the expert engine
e = expert.Expert()
# Initialize rules in module 'rules1'
e.rules_init(rules1)
# Initial facts
e.facts.set('initial', True)
# The 'is_final' function is used to determine if an answer has been found.
# The system stops when 'is_final' returns True
if e.get_answer(is_final):
print "is_final() returned True, that means an answer has been found."
print
print "> Facts"
e.facts.show()
print
print "> Log"
e.logger.show()
else:
print "No answer found! This is probably a bad thing."