Search in sources :

Example 1 with PrefixMapper

use of fr.lirmm.graphik.graal.core.mapper.PrefixMapper 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 2 with PrefixMapper

use of fr.lirmm.graphik.graal.core.mapper.PrefixMapper in project graal by graphik-team.

the class KBBuilderTest method testAddAtomMapper.

/**
 * Test method for {@link fr.lirmm.graphik.graal.kb.KBBuilder#add(fr.lirmm.graphik.graal.api.core.Atom, fr.lirmm.graphik.graal.api.core.mapper.Mapper)}.
 * @throws ParseException
 * @throws KBBuilderException
 * @throws AtomSetException
 */
@Test
public void testAddAtomMapper() throws ParseException, KBBuilderException, AtomSetException {
    // Given
    KBBuilder kbb = new KBBuilder();
    Atom a = DlgpParser.parseAtom("p(a).");
    Mapper mapper = new PrefixMapper("graphik#");
    // When
    kbb.add(a, mapper);
    KnowledgeBase kb = kbb.build();
    // Then
    Assert.assertTrue(kb.getFacts().contains(DlgpParser.parseAtom("<graphik#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) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) Atom(fr.lirmm.graphik.graal.api.core.Atom) Test(org.junit.Test)

Example 3 with PrefixMapper

use of fr.lirmm.graphik.graal.core.mapper.PrefixMapper 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 4 with PrefixMapper

use of fr.lirmm.graphik.graal.core.mapper.PrefixMapper 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

Mapper (fr.lirmm.graphik.graal.api.core.mapper.Mapper)4 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)4 PrefixMapper (fr.lirmm.graphik.graal.core.mapper.PrefixMapper)4 Test (org.junit.Test)4 DlgpParser (fr.lirmm.graphik.graal.io.dlp.DlgpParser)2 Atom (fr.lirmm.graphik.graal.api.core.Atom)1 Rule (fr.lirmm.graphik.graal.api.core.Rule)1