Search in sources :

Example 11 with DlgpParser

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

Example 12 with DlgpParser

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

Example 13 with DlgpParser

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

Example 14 with DlgpParser

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

Example 15 with DlgpParser

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