use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWL2ParserTest method irreflexiveObjectPropertyOf.
@Test
public void irreflexiveObjectPropertyOf() {
// ! :- p(X,X) .
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:IrreflexiveProperty . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof DefaultNegativeConstraint) {
++nbRules;
Rule r = (Rule) o;
CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
Atom b = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(P, b.getPredicate());
Assert.assertEquals(b.getTerm(0), b.getTerm(1));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, 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 OWL2ParserTest method subDataRange.
@Test
public void subDataRange() throws OWL2ParserException {
// p(X,Y) D(Y) :- A(X).
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class. " + ":D1 a rdfs:Datatype. " + ":D2 a rdfs:Datatype. " + ":D3 a rdfs:Datatype. " + ":p rdf:type owl:DatatypeProperty . " + "[a owl:Restriction; owl:onProperty :p; owl:someValuesFrom [a rdfs:Datatype; owl:unionOf (:D1 :D2 :D3)]] rdfs:subClassOf :A.");
int nbAssertions = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
Assert.assertTrue(o instanceof Rule);
++nbAssertions;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 3, nbAssertions);
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class OWL2ParserTest method transitiveObjectPropertyOf.
@Test
public void transitiveObjectPropertyOf() {
// p(X, Z) :- p(X, Y), p(Y, Z).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:TransitiveProperty . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
Rule r = (Rule) o;
CloseableIteratorWithoutException<Atom> it = r.getBody().iterator();
Atom b1 = (Atom) it.next();
Atom b2 = (Atom) it.next();
Assert.assertFalse(it.hasNext());
it = r.getHead().iterator();
Atom h = (Atom) it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(P, b1.getPredicate());
Assert.assertEquals(P, b2.getPredicate());
Assert.assertEquals(P, h.getPredicate());
Assert.assertTrue(b1.getTerm(0).equals(b2.getTerm(1)) || b1.getTerm(1).equals(b2.getTerm(0)));
Assert.assertTrue(h.getTerm(0).equals(b1.getTerm(0)) || h.getTerm(0).equals(b2.getTerm(0)));
Assert.assertTrue(h.getTerm(1).equals(b1.getTerm(1)) || h.getTerm(1).equals(b2.getTerm(1)));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, 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 OWL2ParserTest method dataRangeUnionOf.
@Test
public void dataRangeUnionOf() throws OWL2ParserException {
// D(Y) :- p(X, Y).
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":D1 a rdfs:Datatype." + ":D2 a rdfs:Datatype." + ":p rdfs:range [a rdfs:Datatype; owl:complementOf [a rdfs:Datatype; owl:unionOf ( :D1 :D2 ) ]] .");
int nbAssertions = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
Assert.assertTrue(o instanceof Rule);
++nbAssertions;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 2, nbAssertions);
}
use of fr.lirmm.graphik.graal.api.core.Rule in project graal by graphik-team.
the class DlgpParserTest method parseRule.
// /////////////////////////////////////////////////////////////////////////
// RULE
// /////////////////////////////////////////////////////////////////////////
@Test
public void parseRule() throws ParseException {
Rule r = DlgpParser.parseRule("p(X,Y) :- q(X,Z).");
Atom body = r.getBody().iterator().next();
Assert.assertTrue(body.getTerm(0).isVariable());
Assert.assertTrue(body.getTerm(1).isVariable());
Atom head = r.getHead().iterator().next();
Assert.assertTrue(head.getTerm(0).isVariable());
Assert.assertTrue(head.getTerm(1).isVariable());
}
Aggregations