Search in sources :

Example 1 with KnowledgeBase

use of org.openksavi.sponge.kb.KnowledgeBase in project sponge by softelnet.

the class DefaultKnowledgeBaseManager method onInitializeKnowledgeBases.

/**
 * Initialize knowledge bases.
 */
protected void onInitializeKnowledgeBases() {
    for (KnowledgeBase knowledgeBase : knowledgeBases.values()) {
        if (knowledgeBase instanceof ScriptKnowledgeBase) {
            ScriptKnowledgeBase scriptKnowledgeBase = (ScriptKnowledgeBase) knowledgeBase;
            if (knowledgeBase.getType() == null) {
                knowledgeBase.setType(inferKnowledgeBaseType(scriptKnowledgeBase.getName(), scriptKnowledgeBase.getScripts()));
            }
            verifyKnowledgeBaseFileTypes(scriptKnowledgeBase);
        }
        if (knowledgeBase.getInterpreter() == null) {
            knowledgeBase.setInterpreter(createKnowledgeBaseInterpreter(knowledgeBase.getType().getTypeCode(), knowledgeBase));
        }
        if (knowledgeBase instanceof ScriptKnowledgeBase) {
            ((ScriptKnowledgeBase) knowledgeBase).load();
        }
        knowledgeBase.onInit();
    }
}
Also used : DefaultKnowledgeBase(org.openksavi.sponge.core.kb.DefaultKnowledgeBase) KnowledgeBase(org.openksavi.sponge.kb.KnowledgeBase) ScriptKnowledgeBase(org.openksavi.sponge.kb.ScriptKnowledgeBase) DefaultScriptKnowledgeBase(org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase) ScriptKnowledgeBase(org.openksavi.sponge.kb.ScriptKnowledgeBase) DefaultScriptKnowledgeBase(org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase)

Example 2 with KnowledgeBase

use of org.openksavi.sponge.kb.KnowledgeBase in project sponge by softelnet.

the class DefaultPluginManager method loadPlugin.

/**
 * Loads a plugin.
 *
 * @param pluginStub a plugin stub.
 * @return loaded plugin.
 */
protected Plugin loadPlugin(KnowledgeBasePluginStub pluginStub) {
    try {
        KnowledgeBase knowledgeBase = pluginStub.getKnowledgeBaseName() != null ? getEngine().getKnowledgeBaseManager().getKnowledgeBase(pluginStub.getKnowledgeBaseName()) : getEngine().getKnowledgeBaseManager().getDefaultKnowledgeBase();
        Plugin plugin = knowledgeBase.getInterpreter().createPluginInstance(pluginStub.getPluginClassName());
        if (pluginStub.getName() != null) {
            plugin.setName(pluginStub.getName());
        }
        plugin.setEngine(getEngine());
        plugin.setKnowledgeBase(knowledgeBase);
        plugin.setConfiguration(pluginStub.getConfiguration(), true);
        return plugin;
    } catch (Throwable e) {
        throw SpongeUtils.wrapException(e);
    }
}
Also used : KnowledgeBase(org.openksavi.sponge.kb.KnowledgeBase) Plugin(org.openksavi.sponge.plugin.Plugin)

Example 3 with KnowledgeBase

use of org.openksavi.sponge.kb.KnowledgeBase 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)

Aggregations

KnowledgeBase (org.openksavi.sponge.kb.KnowledgeBase)3 SpongeException (org.openksavi.sponge.SpongeException)1 DefaultKnowledgeBase (org.openksavi.sponge.core.kb.DefaultKnowledgeBase)1 DefaultScriptKnowledgeBase (org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase)1 KnowledgeBaseInterpreter (org.openksavi.sponge.kb.KnowledgeBaseInterpreter)1 ScriptKnowledgeBase (org.openksavi.sponge.kb.ScriptKnowledgeBase)1 ScriptKnowledgeBaseInterpreter (org.openksavi.sponge.kb.ScriptKnowledgeBaseInterpreter)1 Plugin (org.openksavi.sponge.plugin.Plugin)1