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/9422d38b4f0c47917361d477c06bfef1 to your computer and use it in GitHub Desktop.
Save dacr/9422d38b4f0c47917361d477c06bfef1 to your computer and use it in GitHub Desktop.
Drools knowledge base error management / published by https://github.com/dacr/code-examples-manager #859b0e08-dfbd-49f9-bb3a-f0b253c56011/1d1112fd6322eb7543213516e26517456c3d4a6e
// summary : Drools knowledge base error management
// 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 : 859b0e08-dfbd-49f9-bb3a-f0b253c56011
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
// created-on : 2019-10-18T14:45:12+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._
import org.kie.api._
import org.kie.api.runtime._
import org.kie.api.builder.Message.Level
import scala.jdk.CollectionConverters._
object KBIssuesTest extends AnyFlatSpec with should.Matchers {
override def suiteName: String = "KBIssuesTest"
def getErrorMessagesOrNone(kbName:String, container:KieContainer): Option[String] = {
val results = container.verify(kbName)
if (results.hasMessages(Level.ERROR, Level.WARNING)) {
val text =
results
.getMessages
.asScala
.map(m => m.getPath + ": Line#" + m.getLine + " :\n" + m.getText)
.mkString("\n")
Some(text)
} else None
}
"Drools" should "allow to manage knowledge base syntaxic or grammatical errors" ignore {
val drl =
"""package diagnosis
|rule "gloups" when
| TrucNotValid(x== 1)
|then
| insert(new Machin()) // and with missing ;
|end
|""".stripMargin
val engine = DroolsEngine(drl, DroolsEngineConfig.configWithEquality)
// TODO - provide a way to better propagate drools errors through drools-scripting
}
}
KBIssuesTest.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment