Search in sources :

Example 1 with ScriptKnowledgeBaseInterpreter

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);
    }
}
Also used : ScriptKnowledgeBaseInterpreter(org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter) InteractiveModeConsole(org.openksavi.sponge.engine.interactive.InteractiveModeConsole)

Example 2 with ScriptKnowledgeBaseInterpreter

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;
}
Also used : KnowledgeBase(org.openksavi.sponge.kb.KnowledgeBase) SpongeException(org.openksavi.sponge.SpongeException) ScriptKnowledgeBaseInterpreter(org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter) KnowledgeBaseInterpreter(org.openksavi.sponge.kb.KnowledgeBaseInterpreter) ScriptKnowledgeBaseInterpreter(org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter)

Example 3 with ScriptKnowledgeBaseInterpreter

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();
    }
}
Also used : ScriptKnowledgeBaseInterpreter(org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Aggregations

ScriptKnowledgeBaseInterpreter (org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter)3 Test (org.junit.Test)1 SpongeException (org.openksavi.sponge.SpongeException)1 DefaultSpongeEngine (org.openksavi.sponge.core.engine.DefaultSpongeEngine)1 SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)1 InteractiveModeConsole (org.openksavi.sponge.engine.interactive.InteractiveModeConsole)1 KnowledgeBase (org.openksavi.sponge.kb.KnowledgeBase)1 KnowledgeBaseInterpreter (org.openksavi.sponge.kb.KnowledgeBaseInterpreter)1