Search in sources :

Example 6 with KnowledgeBase

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

the class DefaultKnowledgeBaseTest method testIsConsistentFalse2.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#isConsistent()}.
 * @throws KnowledgeBaseException
 * @throws AtomSetException
 * @throws KBBuilderException
 */
@Test
public void testIsConsistentFalse2() throws KnowledgeBaseException, AtomSetException, KBBuilderException {
    KBBuilder kbb = new KBBuilder();
    kbb.addAll(new DlgpParser("q2(X) :- q(X). pr(X) :- p(X), r(X). q(a), p(a), r(a). [NC] ! :- q2(X), pr(X)."));
    kbb.setApproach(Approach.REWRITING_FIRST);
    KnowledgeBase kb = kbb.build();
    Assert.assertFalse(kb.isConsistent());
    kb.close();
}
Also used : DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Test(org.junit.Test)

Example 7 with KnowledgeBase

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

the class DefaultKnowledgeBaseTest method testIsConsistentTrue.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#isConsistent()}.
 */
@Test
public void testIsConsistentTrue() throws KnowledgeBaseException, AtomSetException {
    KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("[R] p(X) :- q(X). p(a). [NC] ! :- q(X), p(X)."));
    Assert.assertTrue(kb.isConsistent());
    kb.close();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Test(org.junit.Test)

Example 8 with KnowledgeBase

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

the class DefaultKnowledgeBaseTest method testSaturate.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#saturate()}.
 * @throws AtomSetException
 * @throws ParseException
 * @throws KnowledgeBaseException
 */
@Test
public void testSaturate() throws ParseException, AtomSetException, KnowledgeBaseException {
    KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("p(X) :- q(X). q(X) :- r(X). r(X) :- s(X).  s(a)."));
    kb.saturate();
    Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("r(a).")));
    Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("q(a).")));
    Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("p(a).")));
    kb.close();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Test(org.junit.Test)

Example 9 with KnowledgeBase

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

the class DefaultKnowledgeBaseQueryTest method testQuery.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#query(fr.lirmm.graphik.graal.api.core.Query)}.
 * @throws AtomSetException
 * @throws KnowledgeBaseException
 * @throws ParseException
 * @throws IteratorException
 */
@Test
public void testQuery() throws AtomSetException, ParseException, KnowledgeBaseException, IteratorException {
    KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("p(X) :- q(X). q(X) :- r(X). r(X) :- s(X).  s(a)."));
    CloseableIterator<Substitution> res = kb.query(DlgpParser.parseQuery("? :- p(a)."));
    Assert.assertTrue(res.hasNext());
    res.close();
    kb.close();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Test(org.junit.Test)

Example 10 with KnowledgeBase

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

the class DefaultKnowledgeBaseQueryTest method testQueryWithTimeout0.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#query(fr.lirmm.graphik.graal.api.core.Query, long)}.
 * @throws AtomSetException
 * @throws KnowledgeBaseException
 * @throws ParseException
 * @throws IteratorException
 * @throws TimeoutException
 */
@Test
public void testQueryWithTimeout0() throws AtomSetException, ParseException, KnowledgeBaseException, IteratorException, TimeoutException {
    KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("p(X) :- q(X). q(X) :- r(X). r(X) :- s(X).  s(a)."));
    CloseableIterator<Substitution> res = kb.query(DlgpParser.parseQuery("? :- p(a)."), 0);
    Assert.assertTrue(res.hasNext());
    res.close();
    kb.close();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) 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