Last active
October 6, 2024 10:54
-
-
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/4aeaa57ada6c669be1f06ee02d44c44170f9c8ed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.5.1" | |
//> using dep "fr.janalyse::drools-scripting:1.2.0" | |
//> using dep "org.scalatest::scalatest:3.2.19" | |
// --------------------- | |
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