【发布时间】:2013-03-27 19:53:18
【问题描述】:
我们想用 Go 来实现我们的业务逻辑,但是我们找不到任何好的 Go 规则引擎/推理引擎实现。有人有什么经验或建议吗?
【问题讨论】:
标签: go rule-engine
我们想用 Go 来实现我们的业务逻辑,但是我们找不到任何好的 Go 规则引擎/推理引擎实现。有人有什么经验或建议吗?
【问题讨论】:
标签: go rule-engine
有一个项目旨在在 Go 中实现 ISO Prolog 编译器:
我还没有测试过,但鉴于它实现了一些基本的 Prolog,这应该是一个非常强大的基于规则的推理引擎,AFAIS。
否则,在godoc.org 上搜索“规则”也会产生一堆包:
【讨论】:
据我所知,最好的例子是在许多标准库中采用的“表驱动”单元测试方法。例如,fmttests。
除此之外,Go 是一种强大的、富有表现力的语言。你真正需要什么? Go 中有许多状态机实现示例,以及许多具有声明性 JSON 配置的 Web 框架。
如果您的意思是正确的逻辑编程,那么目前还没有流行的 Go 库。
【讨论】:
如果您熟悉 JBoss Drools,那么现在 Golang 中也有类似的东西。 看看这个https://github.com/newm4n/grool
它有类似于 Drools DRL 的 DSL,称为 GRL。
rule SlowDown "When testcar is slowing down we keep decreasing the speed." salience 10 {
when
TestCar.SpeedUp == false && TestCar.Speed > 0
then
TestCar.Speed = TestCar.Speed - TestCar.SpeedIncrement;
DistanceRecord.TotalDistance = DistanceRecord.TotalDistance + TestCar.Speed;
}
【讨论】:
看看https://github.com/antonmedv/expr
它可以解析下一个表达式:
# Get the special price if
user.Group in ["good_customers", "collaborator"]
# Promote article to the homepage when
len(article.Comments) > 100 and article.Category not in ["misc"]
# Send an alert when
product.Stock < 15
类型检查并评估。
【讨论】: