pyknow
pyknow copied to clipboard
Declare new fact in RHS function?
Hi I want to declare new facts in rule RHS. Is there an example of this?
Thanks!
Hi,
Please see;
''' from pyknow import *
class Greetings(KnowledgeEngine): @DefFacts() def _initial_action(self): yield Fact(action="greet")
@Rule(Fact(action='greet'),
NOT(Fact(name=W())))
def ask_name(self):
self.declare(Fact(name=input("What's your name? ")))
@Rule(Fact(action='greet'),
NOT(Fact(location=W())))
def ask_location(self):
self.declare(Fact(location=input("Where are you? ")))
@Rule(Fact(action='greet'),
Fact(name=MATCH.name),
Fact(location=MATCH.location))
def greet(self, name, location):
print("Hi %s! How is the weather in %s?" % (name, location))
engine = Greetings() engine.reset() # Prepare the engine for the execution. engine.run() # Run it! '''
From the documentation :)
I think this is what you are after?