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());
}
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());
}
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();
}
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();
}
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();
}
Aggregations