"Gopher Holds The Rules"
Grule-Rule-EngineRule Engine for Go
Grule is a Rule Engine library for the Go (Golang) programming language. Inspired by the acclaimed JBOSS Drools, and done in a much simpler manner.
Like Drools, Grule has its own DSL or Domain-Specific Language.
Below is an example of Drools's DRL or Drools Rule Language:
Grule's GRL is as follows:
What is a Rule EngineThere isn't a better explanation than the article authored by Martin Fowler. You can read the article here (RulesEngine by Martin Fowler).
Taken from TutorialsPoint website (with slight modifications),
The Grule Rule Engine is a Production Rule System that uses the rule-based approach to implement an Expert System. Expert Systems are knowledge-based systems that use knowledge representations to process acquired knowledge into a knowledgebase that can be used for reasoning.
A Production Rule System is Turing complete with a focus on knowledge representation to express propositional and first-order logic in a concise, non-ambiguous and declarative manner.
The brain of a Production Rules System is an Inference Engine that can scale to a large number of rules and facts. The Inference Engine matches facts and data against Production Rules – also called Productions or just Rules – to infer conclusions which result in actions.
A Production Rule is a two-part structure that uses first-order logic for reasoning over knowledge representation. A business rule engine is a software system that executes one or more business rules in a runtime production environment.
A Rule Engine allows you to define “What to Do” and not “How to do it.”
What is a Rule
(also taken from TutorialsPoint)
Rules are pieces of knowledge often expressed as, "When some conditions occur, then do some tasks."
The most important part of a Rule is its when part. If the when part is satisfied, the then part is triggered.
Advantages of a Rule Engine
Declarative Programming
Rules make it easy to express solutions to difficult problems and get the verifications as well. Unlike code, Rules are written with less complex language; Business Analysts can easily read and verify a set of rules.
Logic and Data Separation
The data resides in the Domain Objects and the business logic resides in the Rules. Depending upon the kind of project, this kind of separation can be very advantageous.
Centralization of Knowledge
By using Rules, you create a repository of knowledge (a knowledge base) which is executable. It is a single point of truth for business policy. Ideally, Rules are so readable that they can also serve as documentation.
Agility To Change
Since business rules are actually treated as data. Adjusting the rule according to business's dynamic nature becomes trivial. No need to re-build code or deploy as normal software development does - you only need to roll out sets of rules and apply them to knowledge repository.
Use Cases
The following cases are better solved with a rule-engine:
ifelse
There are many other use-cases that would benefit from the use of a Rule-Engine. The above cases represent only a small number of the potential ones.
ifelse
Theres's something else to note: some rule engine implementations are extremely expensive, yet many businesses gain so much value from them that the cost of running them is easily offset by that value. For even moderately complex use cases, the benefit of a strong rule engine that can decouple teams and tame business complexity seems to be quite clear.
Docs
Documentation page here
To dive into the Tutorial, see the Wiki Docs here on Github.
Benchmark
Loading rules into KnowledgeBase
10099342047 ns/op~99.342047ms49295906 B/op~49.295906MB1000933617752 ns/op~933.617752ms488126636 B/op~488.126636
Executing rules against a fact
~9697 ns/op~0.009697ms3957 B/op~568959 ns/op~0.568959ms293710 B/op
Tasks and Help Wanted
Yes. We need contributors to make Grule even better and useful to the Open Source Community.
- Need to do more and more and more tests.
- Better code coverage test.
- Better commenting for go doc best practice.
- Improve function argument handling to be more fluid and intuitive.
Fork