Search in sources :

Example 1 with DlgpParser

use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Test(org.junit.Test)

Example 2 with DlgpParser

use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Example 3 with DlgpParser

use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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 4 with DlgpParser

use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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 5 with DlgpParser

use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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)

Aggregations

KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)16 DlgpParser (fr.lirmm.graphik.graal.io.dlp.DlgpParser)16 Test (org.junit.Test)16 Atom (fr.lirmm.graphik.graal.api.core.Atom)2 NegativeConstraint (fr.lirmm.graphik.graal.api.core.NegativeConstraint)2 Rule (fr.lirmm.graphik.graal.api.core.Rule)2 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)2 Mapper (fr.lirmm.graphik.graal.api.core.mapper.Mapper)2 PrefixMapper (fr.lirmm.graphik.graal.core.mapper.PrefixMapper)2 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)1 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)1