Skip to main content

Expert Systems for Python

Project description

pypi version tests Documentation Status codecov.io

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

from random import choice
from experta 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

Migrating from Pyknow

Experta is a Pyknow fork. Just replace any pyknow references in your code/examples to experta and everything should work the same.

Examples

You can find some more examples on GitHub.

TODO

CHANGELOG

1.9.1

  • Resolved #3. Rules should not be called with already retracted facts.

1.9.0

  • Drop Python 3.4 support.

  • Use setup.cfg to save all package metadata.

1.8.0-1.8.2

  • Rebranded to Experta.

1.7.0

  • Implemented the template system.

  • Replaced warnings by watchers messages.

  • Fixed freeze() with frozen objects.

  • Fixed unfreeze() with unfrozen objects.

  • Parametrized DefFacts via reset() kwargs.

1.6.0

  • Improved overall performance.

1.5.0

  • Added Python version 3.7 to tox.ini.

  • Monkey and bananas example.

  • Fixed bug, numeric index args gets repeated in a weird way introduced in 1.4.0.

  • Pass only the defined args in absence of kwargs.

1.4.0

  • Order integer facts keys after making a copy.

  • as_dict method for Fact.

  • freeze and unfreeze method documentation.

  • unfreeze method in pyknow.utils.

  • Zebra example from Clips.

1.3.0

  • pyknow.operator module.

  • Nested matching.

  • Added Talk ‘Sistemas Expertos en Python con PyKnow - PyConES 2017’ to docs folder.

1.2.0

  • Freeze fact values as the default behavior to address Issue #9.

  • Added pyknow.utils.anyof to mitigate Issue #7.

  • Raise RuntimeError if a fact value is modified after declare().

  • Added MATCH and AS objects.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

experta-1.9.1.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

experta-1.9.1-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file experta-1.9.1.tar.gz.

File metadata

  • Download URL: experta-1.9.1.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.4.8

File hashes

Hashes for experta-1.9.1.tar.gz
Algorithm Hash digest
SHA256 7ed012cda682e8bf7ba4ea0da6f9d25976bf093fa721e01f812596d8ecbf8e41
MD5 d4a14b7af3ba43013161e5c94456d9f7
BLAKE2b-256 014dc3f4bc9bcbe59bd5812912fbf67b07f3d55b0281df3297b79b3b2445dff5

See more details on using hashes here.

File details

Details for the file experta-1.9.1-py3-none-any.whl.

File metadata

  • Download URL: experta-1.9.1-py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.4.8

File hashes

Hashes for experta-1.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbcff743af5c5b05654a7af96df76150d64595b21b36884d59810717dd7aa510
MD5 d5a7e79b05c1d9d55299a35b0490a8b3
BLAKE2b-256 f22118207f6f6141c1182db30d177b1757b4dc502f3f201fe899f2465d240374

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page