All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ggp.base.util.prover.aima.knowledge.KnowledgeBase Maven / Gradle / Ivy

The newest version!
package org.ggp.base.util.prover.aima.knowledge;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.ggp.base.util.gdl.grammar.Gdl;
import org.ggp.base.util.gdl.grammar.GdlConstant;
import org.ggp.base.util.gdl.grammar.GdlPool;
import org.ggp.base.util.gdl.grammar.GdlRule;
import org.ggp.base.util.gdl.grammar.GdlSentence;


public final class KnowledgeBase
{
    private final Map> contents;

    public KnowledgeBase(Set description)
    {
        contents = new HashMap>();
        for (Gdl gdl : description)
        {
            GdlRule rule = (gdl instanceof GdlRule) ? (GdlRule) gdl : GdlPool.getRule((GdlSentence) gdl);
            GdlConstant key = rule.getHead().getName();

            if (!contents.containsKey(key))
            {
                contents.put(key, new ArrayList());
            }
            contents.get(key).add(rule);
        }
    }

    public synchronized List fetch(GdlSentence sentence)
    {
        GdlConstant key = sentence.getName();

        if (contents.containsKey(key))
        {
            return contents.get(key);
        }
        else
        {
            return new ArrayList();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy