Search in sources :

Example 6 with DlgpParser

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

Example 7 with DlgpParser

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

Example 8 with DlgpParser

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());
}
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 9 with DlgpParser

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

Example 10 with DlgpParser

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();
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) DlgpParser(fr.lirmm.graphik.graal.io.dlp.DlgpParser) AtomSet(fr.lirmm.graphik.graal.api.core.AtomSet) Rule(fr.lirmm.graphik.graal.api.core.Rule) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) 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