java C 或 Python 中的规则引擎

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1925360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:33:17  来源:igfitidea点击:

Rules Engine in C or Python

javapythoncrule-engine

提问by Yanik

I am looking for a rules engine in C or Python, but if you know a rules engine that is implemented in another language I would be glad to know about it.

我正在寻找用 C 或 Python 编写的规则引擎,但如果您知道用另一种语言实现的规则引擎,我会很高兴知道它。

The engine will be used as way to automate a house, like turning the light off when somebody leaves a room etc. So no "office" rules there (aka do you rules in Excel or such).

该引擎将用作自动化房屋的方式,例如当有人离开房间时关灯等。因此那里没有“办公室”规则(也就是您在 Excel 等中的规则)。

I have looked into Jess and Drools which are in Java and do a perfect job. I would like to know of others and possibly using less memory than Java does. I have heard of RuleCore in Python but couldn't really find any documentation on it (version 1.0 is available at SourceForge but it looks like they are selling v. 2.0).

我研究了 Java 中的 Jess 和 Drools,并且做得很好。我想知道其他人,并且可能使用的内存比 Java 少。我听说过 Python 中的 RuleCore,但找不到任何关于它的文档(SourceForge 上有 1.0 版,但看起来他们正在销售 2.0 版)。

EDIT: By rules engine (inference engine), I mean an implementation of RETE or equivalent.

编辑:通过规则引擎(推理引擎),我的意思是 RETE 或等效的实现。

回答by ardsrk

In your search for RETE based rules engine in Python either Pykeor PyCLIPScould be the one you would want to use.

在 Python 中搜索基于RETE的规则引擎时,您可能想要使用PykePyCLIPS

PS: I had left a comment to S.Lott's answer about Pyke. I have posted a separate answer as per his suggestion and also to let other readers readily know that the rules engine mentioned in this answer could be a probable choice if they are searching for one.

PS:我对 S.Lott 关于 Pyke 的回答发表了评论。我根据他的建议发布了一个单独的答案,同时也让其他读者很容易知道,如果他们正在寻找一个规则引擎,这个答案中提到的规则引擎可能是一个可能的选择。

回答by Hymanson

You could look at CLIPSas already suggested or, if you want to pay money or need it Rete2. I've used CLIPS in the past on Unix and sucessfully embedded it into other applications.

您可以按照已经建议的方式查看CLIPS,或者,如果您想付钱或需要它Rete2。我过去曾在 Unix 上使用过 CLIPS,并成功地将其嵌入到其他应用程序中。

Hope this helps.

希望这可以帮助。

回答by miku

rulebyis a rule engine in written in ruby. It was subject of a presentation at rubyhoedown 2008: ruleby-the-rule-engine-for-ruby

ruleby是一个用 ruby​​ 编写的规则引擎。它是 2008 年rubyhoedown演讲的主题:ruleby-the-rule-engine-for-ruby

回答by codekaizen

Pychinko has been around for a while. I've never used it in production, but investigated it for possible production application a while back. It looks like it has pretty good features and a decent community of users.

Pychinko 已经存在一段时间了。我从未在生产中使用过它,但不久前研究了它可能的生产应用。看起来它具有相当不错的功能和不错的用户社区。

http://www.mindswap.org/~katz/pychinko/

http://www.mindswap.org/~katz/pychinko/

回答by S.Lott

In effect, Python isa rules engine.

实际上,Python一个规则引擎。

"The engine will be used as way to automate a house, like turning the light off when somebody leaves a room etc."

“发动机将被用作自动化房屋的方式,例如当有人离开房间时关灯等。”

You need sensors and controllers. You write your "rules" as ordinary Python objects.

您需要传感器和控制器。您将“规则”编写为普通的 Python 对象。

Your main "program" collects events from your sensors and sends events to your controllers.

您的主要“程序”从您的传感器收集事件并将事件发送到您的控制器。

If you can read from your sensors via ordinary USB, that's even better. The marine industry uses a couple of closely related standards like NMEA 0183 and NMEA 2000 for specifying the traffic on the bus from sensor to controller.

如果您可以通过普通 USB 从传感器读取数据,那就更好了。船舶行业使用几个密切相关的标准,如 NMEA 0183 和 NMEA 2000,用于指定从传感器到控制器的总线流量。

You don't need Yet Another Rules Language. You have Python.

您不需要另一种规则语言。你有 Python。

回答by Nick

Rulecore is indeed written partly in Python. But it does not really matter. You as an user would not see any of these implementation details anyway.

Rulecore 确实部分是用 Python 编写的。但这并不重要。无论如何,您作为用户将看不到任何这些实现​​细节。

The rules are purely declarative and defined using XML. The XML is sent into ruleCore CEP Server as events using a web services or JMS or other protocols.

这些规则纯粹是声明性的,并使用 XML 定义。XML 使用 Web 服务或 JMS 或其他协议作为事件发送到 ruleCore CEP 服务器。

回答by Peter Lawrey

Here is a list of 13 open source rules engines in java, Drools is possibly the best of these. http://java-sources.org/open-source/rule-engines

这是 Java 中 13 个开源规则引擎的列表,Drools 可能是其中最好的。http://java-sources.org/open-source/rule-engines

回答by Stjoan

I know ruleCore has some parts written in Python. But the API uses XML and ActiveMQ or WebServices so it is on a higher abstraction level.

我知道 ruleCore 有一些部分是用 Python 编写的。但是 API 使用 XML 和 ActiveMQ 或 WebServices,因此它处于更高的抽象级别。

回答by Adam

Nebriis the easiest way to write rules for home automation AND other software/machines. Here's an example to accomplish the light shutoff:

Nebri是为家庭自动化和其他软件/机器编写规则的最简单方法。下面是一个完成关灯的例子:

class high_temp_shutdown(NebriOS):
    listens_to == ['shared.pebble_location'] 


    def check(self):
        # if pebble dongle is out or room, return true
        return shared.pebble_location > 3 # in meters

    def action(self):
        smartthings.lights(2,"off")

It's a perfect tool for automating your house since you can pip install existing libraries for use in your script. Nest, SmartThings, Sen.se and so on. It's just Python!

它是自动化房屋的完美工具,因为您可以通过 pip 安装现有库以在脚本中使用。Nest、SmartThings、Sen.se 等。这只是 Python!

And for a fuller explanation of why Python isn't a rules engine by itself, see this article. Just because Python itself can execute rules, you don't have a rules engine on your hands. It's a huge architectural shift in fact.

要更全面地解释为什么 Python 本身不是规则引擎,请参阅这篇文章。仅仅因为 Python 本身可以执行规则,所以您手头没有规则引擎。事实上,这是一个巨大的架构转变。

回答by Harry Lee

I write a simple rule engine in python. You can store your rules in json or yaml string, and use this rule engine to match the rule with the context.

我用python编写了一个简单的规则引擎。您可以将规则存储在 json 或 yaml 字符串中,并使用此规则引擎将规则与上下文进行匹配。

https://github.com/tclh123/rule

https://github.com/tclh123/rule