Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare new fact in RHS function? #49

Open
radiantone opened this issue Jun 25, 2019 · 1 comment
Open

Declare new fact in RHS function? #49

radiantone opened this issue Jun 25, 2019 · 1 comment

Comments

@radiantone
Copy link

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

Thanks!

@8ball030
Copy link

8ball030 commented Jun 25, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants