use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method reflexiveObjectPropertyOf.
@Test
public void reflexiveObjectPropertyOf() {
// p(X,X) :- Top(X).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ReflexiveProperty . ");
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 b = it.next();
Assert.assertFalse(it.hasNext());
it = r.getHead().iterator();
Atom h = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(Predicate.TOP, b.getPredicate());
Assert.assertEquals(P, h.getPredicate());
Assert.assertEquals(b.getTerm(0), h.getTerm(0));
Assert.assertEquals(b.getTerm(0), h.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.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method dataExactCardinality0.
@Test
public void dataExactCardinality0() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Datatype . " + ":p rdf:type owl:DatatypeProperty . " + " :A rdfs:subClassOf [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onDataRange :B ; " + " owl:qualifiedCardinality 0 ] . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method hasKey.
// /////////////////////////////////////////////////////////////////////////
// HAS KEY
// /////////////////////////////////////////////////////////////////////////
@Test
public void hasKey() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":p a owl:ObjectProperty . " + ":q a owl:ObjectProperty . " + ":A owl:hasKey (:p :q) .");
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:", 1, nbAssertions);
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method objectPropertyDomain.
@Test
public void objectPropertyDomain() {
// C(Y) :- p(X, Y).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:domain :A .");
boolean found = false;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
Rule r = (Rule) o;
Atom property = (Atom) r.getBody().iterator().next();
Assert.assertEquals(P, property.getPredicate());
Atom classs = (Atom) r.getHead().iterator().next();
Assert.assertEquals(A, classs.getPredicate());
Assert.assertEquals(property.getTerm(0), classs.getTerm(0));
found = true;
}
}
parser.close();
Assert.assertTrue("Number of assertions found:", found);
} catch (Exception e) {
Assert.assertFalse(e.getMessage(), true);
}
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method subDataPropertyOfAxiom.
// /////////////////////////////////////////////////////////////////////////
// Data Property
// /////////////////////////////////////////////////////////////////////////
@Test
public void subDataPropertyOfAxiom() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":q rdf:type owl:DatatypeProperty . " + ":p rdfs:subPropertyOf :q. ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
Rule r = (Rule) o;
CloseableIteratorWithoutException<Atom> bodyIt = r.getBody().iterator();
CloseableIteratorWithoutException<Atom> headIt = r.getHead().iterator();
Assert.assertTrue(bodyIt.hasNext());
Assert.assertTrue(headIt.hasNext());
Atom body = bodyIt.next();
Atom head = headIt.next();
Assert.assertTrue(!body.getTerm(0).isConstant());
Assert.assertTrue(body.getTerm(0).equals(head.getTerm(0)));
Assert.assertTrue(!body.getTerm(1).isConstant());
Assert.assertTrue(body.getTerm(1).equals(head.getTerm(1)));
Assert.assertEquals(P, body.getPredicate());
Assert.assertEquals(Q, head.getPredicate());
Assert.assertFalse(bodyIt.hasNext());
Assert.assertFalse(headIt.hasNext());
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
Aggregations