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/f029b4c19a1631c9120a78eff4e3c4f6 to your computer and use it in GitHub Desktop.
Save dacr/f029b4c19a1631c9120a78eff4e3c4f6 to your computer and use it in GitHub Desktop.
Drools pet knowledge base / published by https://github.com/dacr/code-examples-manager #d5786f29-dd7b-4635-a95d-c2cb8fc57cb4/fc55309a85fe564cc7fd4a742fcbc9aa1e482567
// summary : Drools pet 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 : d5786f29-dd7b-4635-a95d-c2cb8fc57cb4
// created-on : 2019-10-03T08:46:39+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 animals
|
|import java.util.Date
|
|declare Pet
| name: String
| birth: Date
|end
|
|declare Cat extends Pet
| lifeCount:int
|end
|
|""".stripMargin
"Animals KB" should "work" in {
val facts = List(
"animals.Cat"->"""{"name":"minou", "birth":"2019-01-01T14:00:00Z", "lifeCount":7}""",
)
val engine = DroolsEngine(drl)
facts.foreach{case (kind, json) => engine.insertJson(json, kind)}
engine.fireAllRules()
engine.getObjects should have size(1)
val cats = engine.getModelInstances("animals.Cat")
cats.size shouldBe 1
}
}
KbTest.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment