Python Rule Based Engine [closed]

ぐ巨炮叔叔 提交于 2019-12-03 10:00:47

Rather than re-inventing the wheel, I'd suggest you to use some readily available solution. There are several expert systems out there and I'll focus on those which are either in Python or can be used via Python.

CLIPS

CLIPS is an expert system originally developed by NASA. It's considered state of the art and used in university courses when teaching basics of AI. It's a great starting point due to its excellent documentation.

Its syntax is definitely not Python, it rather reminds of Lisp. The advantage of CLIPS is that is a solid C engine which can be fully integrated with any other Python system via its bindings: the older pyclips and the newer clipspy. The bindings allow to embed Python code within the CLIPS language making it very easy to extend.

Rules can be loaded at runtime without the need of restarting the engine which should better suit your need.

PyKE

The Python Knowledge Engine it's a fairly powerful logic programming framework. As for CLIPS, PyKE comes with its own syntax to express rules and relies on Python for implementing the mechanics.

In other words, you write what to do in Python and you express when and how via rules.

Rules can be activated and deactivated on demand. This should allow you to support releaseless updates.

Durable Rules

Durable Rules is a fairly new project with the ambition of supporting multiple programming languages (Python, Node.js and Ruby so far).

Durable Rules allow you to write the whole knowledge base (facts and rules) in Python. The syntax might look a bit weird though, a note in this regards at the end of the post.

I am not sure if you can update the rule-set while the system is online.

Apart from the multiple syntax support, what interest me of this project is the fact the core is a C based implementation of RETE built on top of Redis DB. On a long run, this might lead to some interesting development.

PyKnow, Python Intellect & Business Rules

PyKnow

Intellect

Business Rules

These projects allow to express knowledge bases mostly in Python. I have never seen them in action and I am not sure about their performance and feature support.


The main reason I recommend against brewing your own rule engine to use in production is that, despite it seems an easy task at first, it quickly becomes evident that the problem domain is way bigger than predicted.

Python OOP nature seems initially a good fit for expressing knowledge as both Rules and Facts could be simple classes. Nevertheless, as soon as the pattern matching becomes a little more complex (Employee must have worked > 3 years in Company which Stock value is < 10$ in the last 3 years) two things become evident.

  1. The limitation of simply using and, or, not, is, ... make things really hard to read
  2. The problem suddenly reveals its exponential nature and performance become a major concern

Moreover, forcing the employees of an organization to use yet-another-in-house-built-language is usually a bad idea. It prevents them from learning something used in broader contexts such as CLIPS or Drools and will get you stuck in a maintenance/documentation loop for a long time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!