PyKnow: Expert Systems for Python

https://img.shields.io/pypi/v/pyknow.svg https://img.shields.io/pypi/pyversions/pyknow.svg 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('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.

Release History

1.1.1

  • Removing the borg optimization for P field constraints.
  • Use the hash of the check in the sorting of the nodes to always generate the same alpha part of the network.

1.1.0

  • Allow any kind of callable in Predicate Field Constraints (P()).

1.0.1

  • DNF of OR clause inside AND or Rule was implemented wrong.

1.0.0

  • RETE matching algorithm.
  • Better Rule decorator system.
  • Facts are dictionaries.
  • Documentation.

<1.0.0

  • Unestable API.
  • Wrong matching algorithm.
  • Bad performance
  • PLEASE DON’T USE THIS.

Source documentation