Search in sources :

Example 1 with DefaultScriptKnowledgeBase

use of org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase in project sponge by softelnet.

the class EngineBuilder method knowledgeBase.

/**
 * Adds the knowledge base.
 *
 * @param name the knowledge base name.
 * @param type the knowledge base type.
 * @param scripts the knowledge base scripts.
 * @return this Engine Builder.
 */
public EngineBuilder<T> knowledgeBase(String name, KnowledgeBaseType type, List<KnowledgeBaseScript> scripts) {
    ScriptKnowledgeBase knowledgeBase = new DefaultScriptKnowledgeBase(name, type);
    scripts.forEach(script -> knowledgeBase.addScript(script));
    knowledgeBases.add(knowledgeBase);
    return this;
}
Also used : DefaultScriptKnowledgeBase(org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase) ScriptKnowledgeBase(org.openksavi.sponge.kb.ScriptKnowledgeBase) DefaultScriptKnowledgeBase(org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase)

Example 2 with DefaultScriptKnowledgeBase

use of org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase in project sponge by softelnet.

the class DefaultKnowledgeBaseManager method createScriptKnowledgeBaseFromConfiguration.

protected DefaultScriptKnowledgeBase createScriptKnowledgeBaseFromConfiguration(String name, String typeCode, Configuration[] fileNodes) {
    List<KnowledgeBaseScript> scripts = new ArrayList<>();
    for (Configuration fileNode : fileNodes) {
        String fileName = fileNode.getValue();
        if (StringUtils.isEmpty(fileName)) {
            throw new SpongeException("Knowledge base file name must not be empty");
        }
        scripts.add(new FileKnowledgeBaseScript(fileName, fileNode.getAttribute(CFG_KB_FILE_ATTR_CHARSET, null), fileNode.getBooleanAttribute(CFG_KB_FILE_ATTR_REQUIRED, KnowledgeBaseScript.DEFAULT_REQUIRED)));
    }
    DefaultScriptKnowledgeBase knowledgeBase;
    if (scripts.isEmpty()) {
        if (StringUtils.isEmpty(typeCode)) {
            throw new SpongeException("Knowledge base type for script knowledge bases with no files must not be empty");
        }
        knowledgeBase = new DefaultScriptKnowledgeBase(name, getKnowledgeBaseInterpreterFactory(typeCode).getSupportedType());
    } else {
        KnowledgeBaseType inferredKnowledgeBaseType = inferKnowledgeBaseType(name, scripts);
        if (!StringUtils.isEmpty(typeCode) && !inferredKnowledgeBaseType.getTypeCode().equals(typeCode)) {
            throw new SpongeException("The inferred knowledge base type '" + inferredKnowledgeBaseType.getTypeCode() + "' is different that the specified '" + typeCode + "'");
        }
        knowledgeBase = new DefaultScriptKnowledgeBase(name, inferredKnowledgeBaseType);
    }
    scripts.forEach(script -> knowledgeBase.addScript(script));
    return knowledgeBase;
}
Also used : KnowledgeBaseType(org.openksavi.sponge.kb.KnowledgeBaseType) Configuration(org.openksavi.sponge.config.Configuration) DefaultScriptKnowledgeBase(org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase) SpongeException(org.openksavi.sponge.SpongeException) ArrayList(java.util.ArrayList) FileKnowledgeBaseScript(org.openksavi.sponge.core.kb.FileKnowledgeBaseScript) FileKnowledgeBaseScript(org.openksavi.sponge.core.kb.FileKnowledgeBaseScript) KnowledgeBaseScript(org.openksavi.sponge.kb.KnowledgeBaseScript)

Aggregations

DefaultScriptKnowledgeBase (org.openksavi.sponge.core.kb.DefaultScriptKnowledgeBase)2 ArrayList (java.util.ArrayList)1 SpongeException (org.openksavi.sponge.SpongeException)1 Configuration (org.openksavi.sponge.config.Configuration)1 FileKnowledgeBaseScript (org.openksavi.sponge.core.kb.FileKnowledgeBaseScript)1 KnowledgeBaseScript (org.openksavi.sponge.kb.KnowledgeBaseScript)1 KnowledgeBaseType (org.openksavi.sponge.kb.KnowledgeBaseType)1 ScriptKnowledgeBase (org.openksavi.sponge.kb.ScriptKnowledgeBase)1