Search in sources :

Example 11 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase 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 12 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class KBBuilderTest method testSetStore.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#setStore(fr.lirmm.graphik.graal.api.store.Store)}.
 */
@Test
public void testSetStore() {
    // Given
    KBBuilder kbb = new KBBuilder();
    Store store = new DefaultInMemoryGraphStore();
    // When
    kbb.setStore(store);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertTrue(kb.getFacts() == store);
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Store(fr.lirmm.graphik.graal.api.store.Store) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) Test(org.junit.Test)

Example 13 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class KBBuilderTest method testAddRule.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#add(fr.lirmm.graphik.graal.api.core.Rule)}.
 * @throws ParseException
 */
@Test
public void testAddRule() throws ParseException {
    // Given
    KBBuilder kbb = new KBBuilder();
    Rule r1 = DlgpParser.parseRule("[R1] p(X) :- q(X).");
    // When
    kbb.add(r1);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertEquals(r1, kb.getRule("R1"));
    Assert.assertEquals(1, kb.getOntology().size());
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Rule(fr.lirmm.graphik.graal.api.core.Rule) Test(org.junit.Test)

Example 14 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase in project graal by graphik-team.

the class KBBuilderTest method testAddAtom.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#add(fr.lirmm.graphik.graal.api.core.Atom)}.
 * @throws ParseException
 * @throws KBBuilderException
 * @throws AtomSetException
 */
@Test
public void testAddAtom() throws ParseException, KBBuilderException, AtomSetException {
    // Given
    KBBuilder kbb = new KBBuilder();
    Atom a = DlgpParser.parseAtom("p(a).");
    // When
    kbb.add(a);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertTrue(kb.getFacts().contains(a));
}
Also used : KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 15 with KnowledgeBase

use of fr.lirmm.graphik.graal.api.kb.KnowledgeBase 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)

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