Search in sources :

Example 16 with KnowledgeBase

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

Example 17 with KnowledgeBase

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

Example 18 with KnowledgeBase

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

Example 19 with KnowledgeBase

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());
}
Also used : DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) Ontology(fr.lirmm.graphik.graal.api.core.Ontology) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) Test(org.junit.Test)

Example 20 with KnowledgeBase

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());
}
Also used : Mapper(fr.lirmm.graphik.graal.api.core.mapper.Mapper) PrefixMapper(fr.lirmm.graphik.graal.core.mapper.PrefixMapper) PrefixMapper(fr.lirmm.graphik.graal.core.mapper.PrefixMapper) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Aggregations

KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)28 Test (org.junit.Test)28 DlgpParser (fr.lirmm.graphik.graal.io.dlp.DlgpParser)16 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 Atom (fr.lirmm.graphik.graal.api.core.Atom)5 Mapper (fr.lirmm.graphik.graal.api.core.mapper.Mapper)4 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)4 PrefixMapper (fr.lirmm.graphik.graal.core.mapper.PrefixMapper)4 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)3 NegativeConstraint (fr.lirmm.graphik.graal.api.core.NegativeConstraint)3 Query (fr.lirmm.graphik.graal.api.core.Query)3 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)2 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)2 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)2 Ontology (fr.lirmm.graphik.graal.api.core.Ontology)1 Store (fr.lirmm.graphik.graal.api.store.Store)1 DefaultOntology (fr.lirmm.graphik.graal.core.ruleset.DefaultOntology)1