Search in sources :

Example 26 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class DefaultKnowledgeBaseTest method testAddSameQueryTwice.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#addQuery(fr.lirmm.graphik.graal.api.core.Query)}.
 * @throws ParseException
 */
@Test
public void testAddSameQueryTwice() throws ParseException {
    Query q1 = DlgpParser.parseQuery("[Q1] ? :- p(X).");
    KnowledgeBase kb = new KBBuilder().build();
    kb.addQuery(q1);
    kb.addQuery(q1);
    Assert.assertTrue(kb.getQueryNames().contains("Q1"));
    Assert.assertEquals(q1, kb.getQuery("Q1"));
    Assert.assertEquals(1, kb.getQueryNames().size());
    kb.close();
}
Also used : Query(fr.lirmm.graphik.graal.api.core.Query) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Test(org.junit.Test)

Example 27 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class DefaultKnowledgeBaseTest method testAddQuery.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#addQuery(fr.lirmm.graphik.graal.api.core.Query)}.
 * @throws ParseException
 */
@Test
public void testAddQuery() throws ParseException {
    Query q1 = DlgpParser.parseQuery("[Q1] ? :- p(X).");
    KnowledgeBase kb = new KBBuilder().build();
    kb.addQuery(q1);
    Assert.assertTrue(kb.getQueryNames().contains("Q1"));
    Assert.assertEquals(q1, kb.getQuery("Q1"));
    kb.close();
}
Also used : Query(fr.lirmm.graphik.graal.api.core.Query) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Test(org.junit.Test)

Example 28 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetParserOfObject.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.io.Parser)}.
 * @throws ParseException
 * @throws AtomSetException
 */
@Test
public void testDefaultKnowledgeBaseAtomSetParserOfObject() throws ParseException, AtomSetException {
    Atom aa = DlgpParser.parseAtom("q(a).");
    Atom ab = DlgpParser.parseAtom("q(b).");
    Atom ac = DlgpParser.parseAtom("q(c).");
    Rule r = DlgpParser.parseRule("[R] p(X) :- q(X).");
    NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
    AtomSet store = new DefaultInMemoryGraphStore();
    store.add(aa);
    KnowledgeBase kb = new DefaultKnowledgeBase(store, new DlgpParser("[R] p(X) :- q(X). q(b). q(c). [NC] ! :- q(X), p(X)."));
    Assert.assertTrue(kb.getOntology().contains(r));
    Assert.assertTrue(kb.getOntology().contains(nc));
    Assert.assertTrue(kb.getFacts().contains(aa));
    Assert.assertTrue(kb.getFacts().contains(ab));
    Assert.assertTrue(kb.getFacts().contains(ac));
    kb.close();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Aggregations

KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)28 Test (org.junit.Test)28 DlgpParser (fr.lirmm.graphik.graal.io.dlp.DlgpParser)16 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 Atom (fr.lirmm.graphik.graal.api.core.Atom)5 Mapper (fr.lirmm.graphik.graal.api.core.mapper.Mapper)4 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)4 PrefixMapper (fr.lirmm.graphik.graal.core.mapper.PrefixMapper)4 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)3 NegativeConstraint (fr.lirmm.graphik.graal.api.core.NegativeConstraint)3 Query (fr.lirmm.graphik.graal.api.core.Query)3 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)2 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)2 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)2 Ontology (fr.lirmm.graphik.graal.api.core.Ontology)1 Store (fr.lirmm.graphik.graal.api.store.Store)1 DefaultOntology (fr.lirmm.graphik.graal.core.ruleset.DefaultOntology)1