Last active
May 25, 2024 10:20
-
-
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/e2cbb25548c6c3a0e0394fe0ca9717ffe987c0f3
This file contains 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 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.4.2" | |
//> 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