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/919291796fb8f970657fcd1dd1c5bb76 to your computer and use it in GitHub Desktop.
Save dacr/919291796fb8f970657fcd1dd1c5bb76 to your computer and use it in GitHub Desktop.
Drools forever loop knowledge base / published by https://github.com/dacr/code-examples-manager #f5215bd9-2dff-4529-bdbf-13b5b134b744/b361ef296c4158d27e1d08f5e6fb873d2b8d2b28
// summary : Drools forever loop knowledge base
// keywords : scala, drools, mvel, scalatest, ai, knowledgebase
// 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 : f5215bd9-2dff-4529-bdbf-13b5b134b744
// 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 A end
|declare B end
|declare B end
|rule "init" when not A() then insert(new A()); end
|rule "A -> B" when A() then insert(new B()); end
|rule "B and A -> not A" when $a:A() B() then delete($a); end
|""".stripMargin
"test KB" should "work" in {
val engine = DroolsEngine(drl)
engine.fireAllRules()
}
}
KbTest.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment