pyknow icon indicating copy to clipboard operation
pyknow copied to clipboard

Declare new fact in RHS function?

Open radiantone opened this issue 5 years ago • 1 comments

Hi I want to declare new facts in rule RHS. Is there an example of this?

Thanks!

radiantone avatar Jun 25 '19 22:06 radiantone

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?

8ball030 avatar Jun 25 '19 22:06 8ball030