Last active
February 3, 2026 20:21
-
-
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/5eff26e5f83e4d1ac2c371b77c20294201b95709
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 pet knowledge base | |
| // keywords : scala, drools, mvel, scalatest, ai, knowledgebase, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // 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.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 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