use of org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter in project sponge by softelnet.
the class DefaultInteractiveMode method loop.
@Override
public void loop() {
running.set(true);
try (InteractiveModeConsole console = consoleSupplier.get()) {
activeConsole = console;
if (!console.isOpen()) {
console.open();
}
ScriptKnowledgeBaseInterpreter scriptInterpreter = getScriptKnowledgeBaseInterpreter();
console.print(getWelcomeMessage());
while (true) {
try {
if (!iteration(console, scriptInterpreter)) {
break;
}
} catch (Throwable e) {
handleException("interactive", e);
}
}
} finally {
running.set(false);
}
}
use of org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter in project sponge by softelnet.
the class DefaultInteractiveMode method getScriptKnowledgeBaseInterpreter.
protected ScriptKnowledgeBaseInterpreter getScriptKnowledgeBaseInterpreter() {
KnowledgeBase knowledgeBase = kbName != null ? engine.getKnowledgeBaseManager().getKnowledgeBase(kbName) : engine.getKnowledgeBaseManager().getMainKnowledgeBase();
KnowledgeBaseInterpreter interpreter = knowledgeBase.getInterpreter();
if (!(interpreter instanceof ScriptKnowledgeBaseInterpreter)) {
throw new SpongeException("Knowledge base '" + kbName + "' is not script-based.");
}
return (ScriptKnowledgeBaseInterpreter) interpreter;
}
use of org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter in project sponge by softelnet.
the class CoreRulesTest method testRulesImmediateNoDuration.
@Test
public void testRulesImmediateNoDuration() {
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase(TestUtils.DEFAULT_KB, "examples/core/rules_immediate_no_duration.py").build();
engine.getConfigurationManager().setAutoEnable(false);
engine.startup();
try {
doTestRulesImmediate(engine, createCommonExpectedSequences());
ScriptKnowledgeBaseInterpreter interpreter = SpongeUtils.getScriptInterpreter(engine, TestUtils.DEFAULT_KB);
evalEnableRuleWithException(interpreter, "RuleFFL");
evalEnableRuleWithException(interpreter, "RuleFFN");
evalEnableRuleWithException(interpreter, "RuleFLL");
evalEnableRuleWithException(interpreter, "RuleFLN");
evalEnableRuleWithException(interpreter, "RuleFAL");
evalEnableRuleWithException(interpreter, "RuleFNL");
evalEnableRuleWithException(interpreter, "RuleFAN");
assertFalse(engine.isError());
} finally {
engine.shutdown();
}
}
Aggregations