Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active June 24, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/563ff368d7f8693ff7139ad1efede13d to your computer and use it in GitHub Desktop.
Save dacr/563ff368d7f8693ff7139ad1efede13d to your computer and use it in GitHub Desktop.
Drools rules loop knowledge base / published by https://github.com/dacr/code-examples-manager #6b3ee4ec-6f57-4587-b0ea-1be4118b5a2f/6e053dca54cea9f277fd2dfe8e970e63c2864008
// summary : Drools rules loop knowledge base
// keywords : scala, drools, mvel, scalatest, ai, knowledgebase, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 6b3ee4ec-6f57-4587-b0ea-1be4118b5a2f
// created-on : 2019-10-04T09:15:21+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.3.0"
//> using dep "fr.janalyse::drools-scripting:1.1.0"
//> using dep "org.scalatest::scalatest:3.2.16"
// ---------------------
import fr.janalyse.droolscripting._, org.scalatest._, flatspec._, matchers._, OptionValues._
object KbTest extends AnyFlatSpec with should.Matchers {
val drl =
"""package test
|
|declare That
| count:int
|end
|
|rule "init" when then insert(new That(0)); end
|
|rule "count"
|when
| //$that:That($count:count)
| $that:That($count:count , count < 100)
|then
| modify($that) {
| setCount($count+1)
| }
|end
|""".stripMargin
"test KB" should "work" in {
val engine = DroolsEngine(drl)
engine.fireAllRules()
engine.getModelFirstInstanceAttribute("test.That", "count").value.asInstanceOf[Int] shouldBe 100
}
}
KbTest.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment