Skip to content

buguroo/pyknow

Folders and files

NameName
Last commit message
Last commit date
May 10, 2018
May 18, 2018
Mar 29, 2017
May 18, 2018
Jun 1, 2015
Apr 6, 2018
Apr 6, 2017
May 10, 2018
Jun 1, 2015
Jun 1, 2015
Mar 27, 2018
Mar 29, 2017
Mar 2, 2017
May 10, 2018
Apr 5, 2018

Repository files navigation

PyKnow: Expert Systems for Python

https://travis-ci.org/buguroo/pyknow.svg?branch=master Documentation Status codecov.io

PyKnow is a Python library for building expert systems strongly inspired by CLIPS.

from random import choice
from pyknow import *


class Light(Fact):
    """Info about the traffic light."""
    pass


class RobotCrossStreet(KnowledgeEngine):
    @Rule(Light(color='green'))
    def green_light(self):
        print("Walk")

    @Rule(Light(color='red'))
    def red_light(self):
        print("Don't walk")

    @Rule(AS.light << Light(color=L('yellow') | L('blinking-yellow')))
    def cautious(self, light):
        print("Be cautious because light is", light["color"])
>>> engine = RobotCrossStreet()
>>> engine.reset()
>>> engine.declare(Light(color=choice(['green', 'yellow', 'blinking-yellow', 'red'])))
>>> engine.run()
Be cautious because light is blinking-yellow

You can find some more examples on GitHub.