Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:21
Show Gist options
  • Select an option

  • Save dacr/919291796fb8f970657fcd1dd1c5bb76 to your computer and use it in GitHub Desktop.

Select an option

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/9ce30529f96bceace3376058e513c1cf7c1a98af
// summary : Drools forever loop knowledge base
// keywords : scala, drools, mvel, scalatest, ai, knowledgebase
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// 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.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 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