Search in sources :

Example 6 with Ontology

use of fr.lirmm.graphik.graal.api.core.Ontology in project graal by graphik-team.

the class DefaultOntologyTest method testSize.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.core.ruleset.DefaultOntology#size()}.
 */
@Test
public void testSize() {
    // given
    Ontology onto = new DefaultOntology();
    onto.add(r1);
    onto.add(noName);
    onto.add(r1);
    // when
    int size = onto.size();
    // then
    Assert.assertEquals(2, size);
}
Also used : Ontology(fr.lirmm.graphik.graal.api.core.Ontology) Test(org.junit.Test)

Example 7 with Ontology

use of fr.lirmm.graphik.graal.api.core.Ontology in project graal by graphik-team.

the class ChaseTest method test.

@Test
public void test() throws ParseException, ChaseException {
    Ontology onto = new DefaultOntology();
    onto.add(DlgpParser.parseRule("p(X) :- q(X)."));
    onto.add(DlgpParser.parseRule("q(X) :- p(X)."));
    InMemoryAtomSet store = new DefaultInMemoryGraphStore();
    store.add(DlgpParser.parseAtom("p(a)."));
    Chase chase = new BreadthFirstChase(onto, store);
    Assert.assertTrue(chase.hasNext());
    chase.next();
    Assert.assertTrue(chase.hasNext());
    chase.next();
    Assert.assertFalse(chase.hasNext());
}
Also used : Ontology(fr.lirmm.graphik.graal.api.core.Ontology) DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) BreadthFirstChase(fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase) InMemoryAtomSet(fr.lirmm.graphik.graal.api.core.InMemoryAtomSet) DefaultInMemoryGraphStore(fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore) DefaultOntology(fr.lirmm.graphik.graal.core.ruleset.DefaultOntology) Chase(fr.lirmm.graphik.graal.api.forward_chaining.Chase) BreadthFirstChase(fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase) Test(org.junit.Test)

Example 8 with Ontology

use of fr.lirmm.graphik.graal.api.core.Ontology 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 9 with Ontology

use of fr.lirmm.graphik.graal.api.core.Ontology in project graal by graphik-team.

the class DefaultOntologyTest method testGetRuleNames.

// /////////////////////////////////////////////////////////////////////////
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.core.ruleset.DefaultOntology#getRuleNames()}.
 */
@Test
public void testGetRuleNames() {
    // given
    Ontology onto = new DefaultOntology();
    onto.add(r1);
    onto.add(noName);
    // when
    Set<String> ruleNames = onto.getRuleNames();
    // then
    Assert.assertTrue(ruleNames.contains(r1.getLabel()));
    Assert.assertEquals(2, ruleNames.size());
}
Also used : Ontology(fr.lirmm.graphik.graal.api.core.Ontology) Test(org.junit.Test)

Example 10 with Ontology

use of fr.lirmm.graphik.graal.api.core.Ontology in project graal by graphik-team.

the class DefaultOntologyTest method testContainsSameRuleLabel.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.core.ruleset.DefaultOntology#contains(fr.lirmm.graphik.graal.api.core.Rule)}.
 */
@Test
public void testContainsSameRuleLabel() {
    // given
    Ontology onto = new DefaultOntology();
    onto.add(same1);
    // when
    boolean b = onto.contains(same2);
    // then
    Assert.assertFalse(b);
}
Also used : Ontology(fr.lirmm.graphik.graal.api.core.Ontology) Test(org.junit.Test)

Aggregations

Ontology (fr.lirmm.graphik.graal.api.core.Ontology)13 Test (org.junit.Test)13 Rule (fr.lirmm.graphik.graal.api.core.Rule)3 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)2 DefaultOntology (fr.lirmm.graphik.graal.core.ruleset.DefaultOntology)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 Chase (fr.lirmm.graphik.graal.api.forward_chaining.Chase)1 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)1 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)1 BreadthFirstChase (fr.lirmm.graphik.graal.forward_chaining.BreadthFirstChase)1