Coder Social home page Coder Social logo

gengine's Introduction

Gengine

other

  • 简体中文 使用交流Q群1132683357(群内有官方交流微信群二维码,解答所有的gengine问题)

gengine's People

Contributors

rencalo770 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gengine's Issues

not a issue, it is a sugguestion

You may need to make a BSD licence file for your framework "gengine" to make everyone use it without worry. not only just a BSD label.

咨询一下

B 站新一代 golang 规则引擎的设计与实现

这个文章是否撤掉?
是的,有没有地方可以看到。

建议弄个最佳实践。针对没接触过和想用的人。

ps:此为建议,非BUG反馈。

对于一个新出来的东西,可能有一些人特别是像我们这种刚开始接触用的人,
一看一脸懵逼,不知道咋用。
建议增加一个使用案例,各种方式实践的,这对于入门使用感觉还是很重要的。

当然这是在你们实践允许的情况下弄。

往往好的例子,让新手入门简单可能对拓广面比较有帮助吧。
同时,可否建立个交流群,一起讨论使用啥的也好

谢谢

Is there any example for use StopTag

I try to compose rule like this

rule "whitelist" "use in white list pass" salience 10
BEGIN
	if InWhitelist(userNo) {
		// pass
	} else {
		// continue
	}
END
rule "blacklist" "use in black list deny" salience 5
BEGIN
	if InBlacklist(User.UserNo) {
            // deny
        }
END
...

how can i use ExecuteWithStopTag achieve stop run rest rule if user in whitelist?

发现一个加法类型错误的问题

您好!

首先非常感觉您提供一个很好的开源项目。我在使用时遇到这个的问题,我感觉是一个Bug但不确定。

以下是我的测试脚本:

rule "test01" "test" begin
a =1.0 x=0.0
b = req.GetArgs(@name,0)
x = a + b + 2000
end

参数InArgs是在初始化req结构时定义好的,通过注入的req结构方法来获得每个规则执行时的输入参数。

//Request . 规则请求结构
type Request struct {
//当前账户系统信息
pubstruct.AccountInfo
// 规则执行设置 [规则名][参数1~n]
InArgs map[string][]interface{}
}

func (me *Request) GetArgs(ruleName string, idx int) interface{} {
if v, ok := me.InArgs[ruleName]; ok {
return v[idx]
}
return nil
}

规则在执行到math.go 第49行时报错,程序终止,原因是因为req.GetArgs 返回的是一个interface{} 【实际是float64】

if strings.HasPrefix(bkind, "int") { // 这里会放行所有int,interface也会放行 我在测试时 bkind刚好是interface
return a.Float() + float64(b.Int()), nil //math.go:49
}

我已修正了GetArgs的返回类型,目前运行正常。以上报告供您参考。

再次感谢

浙江嘉兴 老李

execute rules on list of data objects

Hello, I read the example:

...

type User struct {
Name string
Age int64
Male bool
}

func (u *User)GetNum(i int64) int64 {
return i
}

func (u *User)Print(s string){
fmt.Println(s)
}

func (u *User)Say(){
fmt.Println("hello world")
}

const (
base_rule = ...
func exe(user *User){
dataContext := context.NewDataContext()
//inject struct
dataContext.Add("User", user)
...
//init rule engine
knowledgeContext := base.NewKnowledgeContext()
ruleBuilder := builder.NewRuleBuilder(knowledgeContext, dataContext)

//读取规则
start1 := time.Now().UnixNano()
err := ruleBuilder.BuildRuleFromString(base_rule)
end1 := time.Now().UnixNano()

logrus.Infof("rules num:%d, load rules cost time:%d ns", len(knowledgeContext.RuleEntities), end1-start1 )

if err != nil{
	logrus.Errorf("err:%s ", err)
}else{
	eng := engine.NewGengine()

	start := time.Now().UnixNano()
	// true: means when there are many rules, if one rule execute error,continue to execute rules after the occur error rule
	err := eng.Execute(ruleBuilder, true)

...
}
}

func Test_Base(t *testing.T){
user := &User{
Name: "Calo",
Age: 0,
Male: true,
}
exe(user) // HERE: If I have a list of user, for example I have 10 user object, how to run exe(user) efficiently?
}

My questions is: if I have a list of user, with 10 user objects. How to run exe(user) 10 times but more efficiently.
Because in the exe it will execute the functions in sequence as below:
NewDataContext, then NewKnowledgeContext, NewRuleBuilder, NewGengine and eng.Execute(ruleBuilder, true). I think those methods are just duplicated running for 10 times, how can I inject each of the user object in the list by the function dataContext.Add("User",user), but do not execute other function each time I inject a new user object?

有个小bug,engine执行那里有个闭包问题

engine/gengine.go ExecuteConcurrent函数 r变量闭包了,应该用rr
eMsg = append(eMsg, fmt.Sprintf("rule: \"%s\" executed, error:\n %+v ", r.RuleName, e))

其他几个模式,带有并发的都有这个bug,可以修改下~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.