Last active
October 6, 2024 10:54
-
-
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/b50d9fbd6cf3a3efc97ed1a6734a300f8fd3067f
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 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.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.* | |
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