use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testIsConsistentFalse.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#isConsistent()}.
* @throws KnowledgeBaseException
* @throws AtomSetException
*/
@Test
public void testIsConsistentFalse() throws KnowledgeBaseException, AtomSetException {
KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("[R] p(X) :- q(X). q(a). [NC] ! :- q(X), p(X)."));
Assert.assertFalse(kb.isConsistent());
kb.close();
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testGetRuleNames.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#getRuleNames()}.
* @throws ParseException
*/
@Test
public void testGetRuleNames() throws ParseException {
Rule r1 = DlgpParser.parseRule("[R1] p(x) :- q(X).");
Rule r2 = DlgpParser.parseRule("[R2] q(x) :- r(X).");
AtomSet store = new DefaultInMemoryGraphStore();
RuleSet ruleset = new LinkedListRuleSet();
ruleset.add(r1);
ruleset.add(r2);
KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
Assert.assertTrue(kb.getRuleNames().contains("R1"));
Assert.assertTrue(kb.getRuleNames().contains("R2"));
Assert.assertEquals(r1, kb.getRule("R1"));
Assert.assertEquals(r2, kb.getRule("R2"));
kb.close();
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testAddTwoQueryWithSameNames.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#addQuery(fr.lirmm.graphik.graal.api.core.Query)}.
* @throws ParseException
*/
@Test
public void testAddTwoQueryWithSameNames() throws ParseException {
Query q1 = DlgpParser.parseQuery("[Q] ? :- q1(X).");
Query q2 = DlgpParser.parseQuery("[Q] ? :- q2(X).");
KnowledgeBase kb = new KBBuilder().build();
kb.addQuery(q1);
kb.addQuery(q2);
Assert.assertTrue(kb.getQueryNames().contains("Q"));
Assert.assertEquals(q1, kb.getQuery("Q"));
Assert.assertEquals(2, kb.getQueryNames().size());
kb.close();
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseParserOfObject.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.io.Parser)}.
*
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testDefaultKnowledgeBaseParserOfObject() 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).");
KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("[R] p(X) :- q(X). q(a), 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();
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetRuleSet.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.core.RuleSet)}.
* @throws AtomSetException
* @throws ParseException
*/
@Test
public void testDefaultKnowledgeBaseAtomSetRuleSet() throws AtomSetException, ParseException {
Atom aa = DlgpParser.parseAtom("q(a).");
Atom ab = DlgpParser.parseAtom("q(b).");
Atom ac = DlgpParser.parseAtom("q(c).");
Rule r = DlgpParser.parseRule("[R1] p(x) :- q(X).");
NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
AtomSet store = new DefaultInMemoryGraphStore();
store.add(aa);
store.add(ab);
store.add(ac);
RuleSet ruleset = new LinkedListRuleSet();
ruleset.add(r);
ruleset.add(nc);
KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
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();
}
Aggregations