use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase 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.api.kb.KnowledgeBase 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)."));
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class DefaultKnowledgeBaseQueryTest method testInfinityQueryWithTimeout.
/**
* 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 = TimeoutException.class)
public void testInfinityQueryWithTimeout() throws AtomSetException, ParseException, KnowledgeBaseException, IteratorException, TimeoutException, KBBuilderException {
KBBuilder kbBuilder = new KBBuilder();
kbBuilder.setApproach(Approach.SATURATION_ONLY);
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)."), 10000);
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class KBBuilderTest method testSetOntology.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#setOntology(fr.lirmm.graphik.graal.api.core.RuleSet)}.
* @throws ParseException
*/
@Test
public void testSetOntology() throws ParseException {
// Given
KBBuilder kbb = new KBBuilder();
Ontology ontology = new DefaultOntology();
Rule r1 = DlgpParser.parseRule("[R1] p(X) :- q(X).");
ontology.add(r1);
// When
kbb.setOntology(ontology);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertEquals(r1, kb.getRule("R1"));
Assert.assertEquals(1, kb.getOntology().size());
}
use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.
the class KBBuilderTest method testAddRuleMapper.
/**
* Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#add(fr.lirmm.graphik.graal.api.core.Rule, fr.lirmm.graphik.graal.api.core.mapper.Mapper)}.
* @throws ParseException
* @throws AtomSetException
*/
@Test
public void testAddRuleMapper() throws ParseException, AtomSetException {
// Given
KBBuilder kbb = new KBBuilder();
Mapper mapper = new PrefixMapper("graphik#");
Rule r1 = DlgpParser.parseRule("[R1] p(X) :- q(X).");
// When
kbb.add(r1, mapper);
KnowledgeBase kb = kbb.build();
// Then
Assert.assertEquals(DlgpParser.parseRule("[R1] <graphik#p>(X) :- <graphik#q>(X)."), kb.getRule("R1"));
Assert.assertEquals(1, kb.getOntology().size());
}
Aggregations