background preloader

Scala Rule Tools

Facebook Twitter

  Just Do I.T.: Two-Minutes Scala Rules Engine. Scala is really seductive. To drive my learning of this JVM programming language, I thought I should go beyond the obvious experiments and try to tackle a subject dear to my heart: building a general purpose rules engine. Of course, the implementation I am going to talk about here is naive and inefficient but the rules engine is just a pretext here: this is about Scala and how it shines. And it is also a subset of what Scala is good at: I mainly scratch the surface by focusing on pattern matching and collections handling.

The fact representation I use is the same than the one used by RuleML: a fact is a named relationship between predicates. For example, in "blue is the color of the sky", color is the relationship between blue and sky. In Scala, I naturally opted for using a case class to define a fact, as the pattern matching feature it offers is all what is needed to build inference rules: For rules, I opted to have them created as objects constrained by a particular trait:

Mikeaddison93/NewsGogglesScala. Maxant/rules.   Just Do I.T.: Two-Minutes Scala Rules Engine. RuleML Wiki. Drools with Scala | bleibinha.us/blog. 1 Rules Engines 1.1 Motivation When I started becoming interested in business rules engines [3] , I first found the concept hard to grasp. Why should I externalize application logic to a rules engine, when I can just code it? Now that I understand the concept better, I see use cases for business rules engines everywhere. For a basic understanding of a rules engine, Wikipedia summaries it nicely in one sentence: "A business rules engine is a software system that executes one or more business rules in a runtime production environment" [3] . I also like the answer given here on Stackoverflow [5] as it explains the concept of a rules engine more from a programmer perspective. For me, a rules engine is like a container I can fill with different typed domain objects and then activate the rules engine to execute a set of predefined functions which might modify the content of the container and/or the objects already in there and/or have other side effects. 1.2 Drools 1.3 Drools with Scala.

Daveray/rooscaloo. Hammurabi - The Scala Rule Engine. I will give a talk about hammurabi during the next Devoxx - Don't miss it! "Any fool can write code that a computer can understand. Good programmers write code that humans can understand" - Martin Fowler "Domain users shouldn't be writing code in our DSL but it must be designed for them to understand and validate" - Debasish Ghosh What Hammurabi is Hammurabi is a rule engine written in Scala that tries to leverage the features of this language making it particularly suitable to implement extremely readable internal Domain Specific Languages. Indeed, what actually makes Hammurabi different from all other rule engines is that it is possible to write and compile its rules directly in the host language.

Anyway the Hammurabi's rules also have the important property of being readable even by non technical person. The golfers problem This logical puzzle has been taken from the first chapter of the Jess in Action book written by Ernest Friedman-Hill and published by Manning. The Jess solution. Tutorial: how to write Scala rules for Bazel. Bazel comes with built-in support for several languages and allows you to write your own support for any other languages in Python. Although you could probably get more abstract, let’s define a rule as something that takes some files, does something to them, and then gives you some output files. Specifically, for this example, we want a scala_binary rule where we can give it a Scala source file and it turns it into an executable binary.

Part 1: Creating a Scala source file Let’s create a simple example of a Scala source file (mercilessly ripped from the Scala hello world example): Note that I’ve never used Scala before today, so please let me know in the comments if I’ve made an mistakes. Before proceeding, I think it’s a good idea to try building this without bazel (especially if you’re not too familiar with the language’s build tool… ahem) as a sanity check: Looking good! Adding a BUILD file and dummy scala_binary rule This adds an action to the build. References. Sirthias/parboiled2. Gilt/the-hand.