Search in sources :

Example 1 with NegativeConstraint

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

the class DlgpParserTest method parseNegativeConstraintWithPrefix.

@Test
public void parseNegativeConstraintWithPrefix() throws ParseException {
    NegativeConstraint r = DlgpParser.parseNegativeConstraint("@prefix ex: <http://example.com/> [N1]!:-ex:p(X,Y), ex:q(X,Y).");
    CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
    Atom body = it.next();
    Assert.assertTrue(body.getTerm(0).isVariable());
    Assert.assertTrue(body.getTerm(1).isVariable());
    body = it.next();
    Assert.assertTrue(body.getTerm(0).isVariable());
    Assert.assertTrue(body.getTerm(1).isVariable());
    Assert.assertEquals("N1", r.getLabel());
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Example 2 with NegativeConstraint

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

the class DlgpParserTest method parseNegativeConstraint.

// /////////////////////////////////////////////////////////////////////////
// NEGATIVE CONSTRAINT
// /////////////////////////////////////////////////////////////////////////
@Test
public void parseNegativeConstraint() throws ParseException {
    NegativeConstraint r = DlgpParser.parseNegativeConstraint("[N1]!:-p(X,Y), q(X,Y).");
    CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
    Atom body = it.next();
    Assert.assertTrue(body.getTerm(0).isVariable());
    Assert.assertTrue(body.getTerm(1).isVariable());
    body = it.next();
    Assert.assertTrue(body.getTerm(0).isVariable());
    Assert.assertTrue(body.getTerm(1).isVariable());
    Assert.assertEquals("N1", r.getLabel());
}
Also used : Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Example 3 with NegativeConstraint

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

the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseParserOfObject.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.io.Parser)}.
 *
 * @throws ParseException
 * @throws AtomSetException
 */
@Test
public void testDefaultKnowledgeBaseParserOfObject() 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).");
    KnowledgeBase kb = new DefaultKnowledgeBase(new DlgpParser("[R] p(X) :- q(X). q(a), 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) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Example 4 with NegativeConstraint

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

the class DefaultKnowledgeBaseTest method testDefaultKnowledgeBaseAtomSetRuleSet.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#DefaultKnowledgeBase(fr.lirmm.graphik.graal.api.core.AtomSet, fr.lirmm.graphik.graal.api.core.RuleSet)}.
 * @throws AtomSetException
 * @throws ParseException
 */
@Test
public void testDefaultKnowledgeBaseAtomSetRuleSet() throws AtomSetException, ParseException {
    Atom aa = DlgpParser.parseAtom("q(a).");
    Atom ab = DlgpParser.parseAtom("q(b).");
    Atom ac = DlgpParser.parseAtom("q(c).");
    Rule r = DlgpParser.parseRule("[R1] p(x) :- q(X).");
    NegativeConstraint nc = DlgpParser.parseNegativeConstraint("[NC] ! :- q(X), p(X).");
    AtomSet store = new DefaultInMemoryGraphStore();
    store.add(aa);
    store.add(ab);
    store.add(ac);
    RuleSet ruleset = new LinkedListRuleSet();
    ruleset.add(r);
    ruleset.add(nc);
    KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
    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 : RuleSet(fr.lirmm.graphik.graal.api.core.RuleSet) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) KnowledgeBase(fr.lirmm.graphik.graal.api.kb.KnowledgeBase) 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) LinkedListRuleSet(fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet) Atom(fr.lirmm.graphik.graal.api.core.Atom) NegativeConstraint(fr.lirmm.graphik.graal.api.core.NegativeConstraint) Test(org.junit.Test)

Example 5 with NegativeConstraint

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

Atom (fr.lirmm.graphik.graal.api.core.Atom)5 NegativeConstraint (fr.lirmm.graphik.graal.api.core.NegativeConstraint)5 Test (org.junit.Test)5 Rule (fr.lirmm.graphik.graal.api.core.Rule)3 KnowledgeBase (fr.lirmm.graphik.graal.api.kb.KnowledgeBase)3 AtomSet (fr.lirmm.graphik.graal.api.core.AtomSet)2 DefaultInMemoryGraphStore (fr.lirmm.graphik.graal.core.atomset.graph.DefaultInMemoryGraphStore)2 DlgpParser (fr.lirmm.graphik.graal.io.dlp.DlgpParser)2 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)1 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)1