use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class KBBuilderTest method testAddAll.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#addAll(fr.lirmm.graphik.util.stream.CloseableIterator)}.
* @throws KBBuilderException
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testAddAll() throws KBBuilderException, ParseException, AtomSetException {
// Given
KBBuilder kbb = new KBBuilder();
Parser<Object> parser = new DlgpParser("[R1] p(X) :- q(X). p(a).");
// When
kbb.addAll(parser);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertEquals(DlgpParser.parseRule("[R1] p(X) :- q(X)."), kb.getRule("R1"));
Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("p(a).")));
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class KBBuilderTest method testAddRulesCloseableIteratorOfObject.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#addRules(fr.lirmm.graphik.util.stream.CloseableIterator)}.
* @throws AtomSetException
* @throws ParseException
* @throws KBBuilderException
*/
@Test
public void testAddRulesCloseableIteratorOfObject() throws ParseException, AtomSetException, KBBuilderException {
// Given
KBBuilder kbb = new KBBuilder();
Parser<Object> parser = new DlgpParser("[R1] p(X) :- q(X). p(a).");
// When
kbb.addRules(parser);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertEquals(DlgpParser.parseRule("[R1] p(X) :- q(X)."), kb.getRule("R1"));
Assert.assertEquals(1, kb.getOntology().size());
Assert.assertFalse(kb.getFacts().contains(DlgpParser.parseAtom("p(a).")));
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class KBBuilderTest method testAddRulesCloseableIteratorOfObjectMapper.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#addRules(fr.lirmm.graphik.util.stream.CloseableIterator, fr.lirmm.graphik.graal.api.core.mapper.Mapper)}.
* @throws KBBuilderException
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testAddRulesCloseableIteratorOfObjectMapper() throws KBBuilderException, ParseException, AtomSetException {
// Given
KBBuilder kbb = new KBBuilder();
Parser<Object> parser = new DlgpParser("[R1] p(X) :- q(X). p(a).");
Mapper mapper = new PrefixMapper("graphik#");
// When
kbb.addRules(parser, mapper);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertEquals(DlgpParser.parseRule("[R1] <graphik#p>(X) :- <graphik#q>(X)."), kb.getRule("R1"));
Assert.assertFalse(kb.getFacts().contains(DlgpParser.parseAtom("p(a).")));
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class DefaultKnowledgeBaseQueryTest method testSaturationFirstQueryWithNoProof.
/**
* 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
* @throws KBBuilderException
*/
@Test(expected = KnowledgeBaseException.class)
public void testSaturationFirstQueryWithNoProof() throws AtomSetException, ParseException, KnowledgeBaseException, IteratorException, TimeoutException, KBBuilderException {
KBBuilder kbBuilder = new KBBuilder();
kbBuilder.setApproach(Approach.SATURATION_FIRST);
kbBuilder.addAll(new DlgpParser("p(X,Y), h(Y) :- h(X). p(X,Z) :- p(X,Y), p(Y,Z). h(a)."));
KnowledgeBase kb = kbBuilder.build();
kb.query(DlgpParser.parseQuery("? :- p(a)."));
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class DefaultKnowledgeBaseQueryTest method testRewritingFirstQueryWithNoProof.
/**
* 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
* @throws KBBuilderException
*/
@Test(expected = KnowledgeBaseException.class)
public void testRewritingFirstQueryWithNoProof() throws AtomSetException, ParseException, KnowledgeBaseException, IteratorException, TimeoutException, KBBuilderException {
KBBuilder kbBuilder = new KBBuilder();
kbBuilder.setApproach(Approach.REWRITING_FIRST);
kbBuilder.addAll(new DlgpParser("p(X,Y), h(Y) :- h(X). p(X,Z) :- p(X,Y), p(Y,Z). h(a)."));
KnowledgeBase kb = kbBuilder.build();
kb.query(DlgpParser.parseQuery("? :- p(a)."));
}
Aggregations