• Stars
    star
    2
  • Language
    Scala
  • License
    Other
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Drools made easy to use for scripting or testing purposes

Drools scripting Build Status License Maven

Drools made easy to use for scripting or testing purposes.

This library allows you to easily design proof of concepts based on the drools expert system. It greatly simplifies how you can quickly write drools based code examples or small experiments.

Just insert JSON facts into your drools working memory, and use the available engine methods to interact with the expert system and extract data from it. Data extraction can be done through simple accessors or through the JSON format. Check the documented methods in the DroolsEngine class or take a look to the large amount of example I've made available. (Most of them can be run directly by using the great ammonite REPL solution from Li Haoyi)

A selection of my drools shared code examples based on drools-scripting project :

A hello world drools example runnable with ammonite :

import $ivy.`fr.janalyse::drools-scripting:1.0.11`, $ivy.`org.scalatest::scalatest:3.2.2`
import fr.janalyse.droolscripting._, org.scalatest.flatspec._, org.scalatest.matchers._

object HelloTest extends AnyFlatSpec with should.Matchers {
  "Drools" should "say hello" in {
    val drl =
      """package test
        |rule "hello" when
        |then
        |  insert("HELLO WORLD");
        |end
        |""".stripMargin
    val engine = DroolsEngine(drl)
    engine.fireAllRules()
    engine.strings shouldBe List("HELLO WORLD")
  }
}
HelloTest.execute()

or an other one runnable with ammonite :

import $ivy.`fr.janalyse::drools-scripting:1.0.11`, $ivy.`org.scalatest::scalatest:3.2.2`
import fr.janalyse.droolscripting._, org.scalatest._, flatspec._, matchers._, OptionValues._

object HelloTest extends AnyFlatSpec with should.Matchers {
  "Drools" should "say hello" in {
    val drl =
      """package test
        |
        |declare Someone
        |  name:String
        |end
        |
        |declare Message
        |  message:String
        |end
        |
        |rule "hello" when
        |  Someone($name:name)
        |then
        |  insert(new Message("HELLO "+$name));
        |end
        |""".stripMargin
    val engine = DroolsEngine(drl)
    engine.insertJson("""{"name":"John"}""","test.Someone")
    engine.fireAllRules()
    val msgOption = engine.getModelFirstInstanceAttribute("test.Message", "message")
    msgOption.value shouldBe "HELLO John"
  }
}
HelloTest.execute()

Ammonite notes

Ammonite resolves by default both binary and source artifacts, with recent release of drools it generates a runtime error as drools can't deal with several kie.conf file for a given module, so you'll have to change ammonite default start up behavior in order to avoid sources resolutions. Just add those following lines at the beginning of all your drools scripts (@ separates bootstrapping code from regular one, this is required as we change the behavior of the import $ivy. instruction):

interp.resolutionHooks += { fetch =>
  // -- This is mandatory with drools >= 7.0.46 because drools sources artifacts also brings kie.conf
  // -- (it generates resources conflict at KIE init) and because by default ammonite also load sources artifact...
  import scala.jdk.CollectionConverters._
  fetch.withClassifiers(fetch.getClassifiers.asScala.filter(_ != "sources").asJava)
}

@

import $ivy.`fr.janalyse::drools-scripting:1.0.13`

The interp.resolutionHooks instruction can also instead be added into your default ammonite configuration, in the file $HOME/.ammonite/predefShared.sc which is probably a better workaround to add those lines into all your scripts.

More Repositories

1

jassh

High level scala SSH API for easy and fast operations on remote servers.
Scala
71
star
2

code-examples-manager

Software tool to manage your notes, scripts, code examples, configs,... to publish them as gists or snippets
Scala
37
star
3

zio-lmdb

Lightning Memory Database (LMDB) for scala ZIO
Scala
36
star
4

jajmx

scala JMX API
Scala
31
star
5

sotohp

Photos management
Scala
27
star
6

scala-drools-dummy-project

Minimalist scala drools project
Scala
19
star
7

coursier-launcher

coursier docker container for efficient application or service download and startup
Makefile
9
star
8

zwords

A wordle game for communities
Scala
8
star
9

jaseries

scala API for time numerical series operations.
Scala
7
star
10

primes

Playing with primes using scala language. Draw Ulam spiral, ...
Scala
7
star
11

zio-worksheet

Simplified ZIO user experience in REPL, worksheet or script contexts
Scala
6
star
12

bootstrap

scala script bootstrap mechanism with #include support
Scala
6
star
13

the-weakest-link

Scala
4
star
14

custom-collection

Custom scala collection examples
Scala
4
star
15

scala-dummy-project

scala dummy project with standalone executable jar
Shell
3
star
16

codingame-with-scalakit-example

codingame scalakit example using git submodule to reference the scalakit
Scala
2
star
17

simple-plugin-architecture

Scala simple plugin architecture (with plugin automatic compilation if required)
Scala
2
star
18

exproxy

a 2005 personal project...
Java
2
star
19

cntlm

dockerized cntlm
Shell
2
star
20

primes-scalatra-app

Scala
1
star
21

naturalsort

scala naturalsort algorithm
Scala
1
star
22

web-echo

A websocket/webhook JSON data recorder with API
Scala
1
star
23

akka-sandbox

temporary project to test and learn AKKA 2
Scala
1
star
24

advent-of-code-2023

Scala
1
star
25

bullyboy

sha1 brute force attack
Scala
1
star
26

the-rules-for-good-code-examples

Several rules to write the best possible source code examples
1
star
27

data-recorder

Scala
1
star
28

advent-of-code-2020

Scala
1
star
29

jenkins-phantomjs-slave

jenkins slave with phantomjs 1.9 docker image
1
star
30

dock-primesui

Shell
1
star
31

jenkins

Jenkins docker image
Shell
1
star