Golang 中的规则引擎实现
"Gopher 制定规则"
import "github.com/hyperjumptech/grule-rule-engine"Grule 是一个用于 Go (Golang) 编程语言的规则引擎库。它受到广受好评的 JBOSS Drools 的启发,但实现方式要简单得多。 与 Drools 类似, Grule 具有自己的 DSL 或域特定语言。 以下是 Drools 的 DRL 或 Drools 规则语言的示例:
rule "SpeedUp"
salience 10
when
$TestCar : TestCarClass( speedUp == true && speed < maxSpeed )
$DistanceRecord : DistanceRecordClass()
then
$TestCar.setSpeed($TestCar.Speed + $TestCar.SpeedIncrement);
update($TestCar);
$DistanceRecord.setTotalDistance($DistanceRecord.getTotalDistance() + $TestCar.Speed);
update($DistanceRecord);
endGrule 的 GRL 如下:
rule SpeedUp "When testcar is speeding up we keep increase the speed." salience 10 {
when
TestCar.SpeedUp == true && TestCar.Speed < TestCar.MaxSpeed
then
TestCar.Speed = TestCar.Speed + TestCar.SpeedIncrement;
DistanceRecord.TotalDistance = DistanceRecord.TotalDistance + TestCar.Speed;
}没有比 Martin Fowler 所撰写的文章更好的解释了。您可以在 RulesEngine by Martin Fowler 中阅读该文章。 来自 TutorialsPoint 网站(略有修改)
Grule 规则引擎是一种生产规则系统,它采用基于规则的方法来实现专家系统。专家系统是基于知识的系统,它使用知识表示法将获得的知识转换为可用于推理的知识库。生产规则系统是图灵完备的,其重点是知识表示,以简洁、非歧义和声明性的方式表达命题逻辑和第一次序逻辑。
生产规则系统的大脑是一个 推理引擎,可以扩展到大量的规则和事实。推理引擎将事实和数据与生产规则(也称为 生产 或 规则)进行匹配,以推断结论。
暂无开放 Issues,或尚未同步最近议题。