use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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();
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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();
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class KBBuilderTest method testAddAtomsCloseableIteratorOfObjectMapper.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#addAtoms(fr.lirmm.graphik.util.stream.CloseableIterator, fr.lirmm.graphik.graal.api.core.mapper.Mapper)}.
* @throws KBBuilderException
* @throws AtomSetException
* @throws ParseException
*/
@Test
public void testAddAtomsCloseableIteratorOfObjectMapper() 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.addAtoms(parser, mapper);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("<graphik#p>(a).")));
Assert.assertEquals(0, kb.getOntology().size());
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser in project graal by graphik-team.
the class KBBuilderTest method testAddAtomsCloseableIteratorOfObject.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#addAtoms(fr.lirmm.graphik.util.stream.CloseableIterator)}.
* @throws KBBuilderException
* @throws AtomSetException
* @throws ParseException
*/
@Test
public void testAddAtomsCloseableIteratorOfObject() throws KBBuilderException, ParseException, AtomSetException {
// Given
KBBuilder kbb = new KBBuilder();
Parser<Object> parser = new DlgpParser("[R1] p(X) :- q(X). p(a).");
// When
kbb.addAtoms(parser);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("p(a).")));
Assert.assertEquals(0, kb.getOntology().size());
}
use of fr.lirmm.graphik.graal.io.dlp.DlgpParser 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();
}
Aggregations