use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWL2ParserTest method equivalentProperty.
@Test
public void equivalentProperty() {
// q(X, Y) <-> p(X, Y).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:equivalentProperty :q .");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
Rule r = (Rule) o;
Atom subProperty = (Atom) r.getBody().iterator().next();
Atom property = (Atom) r.getHead().iterator().next();
Assert.assertTrue(Q.equals(property.getPredicate()) || P.equals(property.getPredicate()));
Assert.assertTrue(Q.equals(subProperty.getPredicate()) || P.equals(subProperty.getPredicate()));
Assert.assertEquals(property.getTerm(0), subProperty.getTerm(0));
Assert.assertEquals(property.getTerm(1), subProperty.getTerm(1));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 2, nbRules);
} catch (Exception e) {
Assert.assertFalse(e.getMessage(), true);
}
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class SparqlRuleTest method testStringLiteral.
@Test
public void testStringLiteral() {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX : <" + PREFIX + ">" + "CONSTRUCT" + "{" + " ?x :q 'toto' " + "}" + "WHERE" + "{" + " ?x :p 'toto' ." + "}";
Rule rule = new SparqlRuleParser(query).getRule();
CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(P, a.getPredicate());
Assert.assertEquals(STRING, a.getTerm(1));
}
it = rule.getHead().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(Q, a.getPredicate());
Assert.assertEquals(STRING, a.getTerm(1));
}
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class SparqlRuleTest method testRDFType.
@Test
public void testRDFType() {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX : <" + PREFIX + ">" + "CONSTRUCT" + "{" + " ?x rdf:type :B " + "}" + "WHERE" + "{" + " ?x a :A ." + "}";
Rule rule = new SparqlRuleParser(query).getRule();
CloseableIteratorWithoutException<Atom> it = rule.getBody().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(A, a.getPredicate());
}
it = rule.getHead().iterator();
while (it.hasNext()) {
Atom a = it.next();
Assert.assertEquals(B, a.getPredicate());
}
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class DefaultKnowledgeBaseTest method testGetRuleNames.
/**
* Test method for
* {@link fr.lirmm.graphik.graal.kb.DefaultKnowledgeBase#getRuleNames()}.
* @throws ParseException
*/
@Test
public void testGetRuleNames() throws ParseException {
Rule r1 = DlgpParser.parseRule("[R1] p(x) :- q(X).");
Rule r2 = DlgpParser.parseRule("[R2] q(x) :- r(X).");
AtomSet store = new DefaultInMemoryGraphStore();
RuleSet ruleset = new LinkedListRuleSet();
ruleset.add(r1);
ruleset.add(r2);
KnowledgeBase kb = new DefaultKnowledgeBase(store, ruleset);
Assert.assertTrue(kb.getRuleNames().contains("R1"));
Assert.assertTrue(kb.getRuleNames().contains("R2"));
Assert.assertEquals(r1, kb.getRule("R1"));
Assert.assertEquals(r2, kb.getRule("R2"));
kb.close();
}
use of fr.lirmm.graphik.graal.api.core.Rule 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();
}
Aggregations