use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method symetricObjectPropertyOf.
@Test
public void symetricObjectPropertyOf() {
// p(X, Y) :- p(Y, X).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:SymmetricProperty . ");
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 = (Atom) it.next();
Assert.assertFalse(it.hasNext());
it = r.getHead().iterator();
Atom h = (Atom) it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(P, b.getPredicate());
Assert.assertEquals(P, h.getPredicate());
Assert.assertNotEquals(b.getTerm(0), b.getTerm(1));
Assert.assertEquals(b.getTerm(0), h.getTerm(1));
Assert.assertEquals(b.getTerm(1), h.getTerm(0));
}
}
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 unionOfObjectOneOf.
@Test
public void unionOfObjectOneOf() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + "[ owl:unionOf ( [ owl:oneOf ( :i1 :i2 ) ] [ owl:oneOf ( :i3 :i4 ) ] ) ] rdfs:subClassOf :A. ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof InMemoryAtomSet) {
CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
while (it.hasNext()) {
it.next();
++nbRules;
}
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 4, nbRules);
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method objectOneOf.
@Test
public void objectOneOf() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + "[ owl:oneOf ( :i1 :i2 :i3 ) ] rdfs:subClassOf :A . ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof InMemoryAtomSet) {
CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
while (it.hasNext()) {
Atom a = it.next();
++nbRules;
Assert.assertTrue(a.getTerm(0).equals(I1) || a.getTerm(0).equals(I2) || a.getTerm(0).equals(I3));
Assert.assertEquals(A, a.getPredicate());
}
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 3, nbRules);
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method objectMinCardinality1.
@Test
public void objectMinCardinality1() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + " [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onClass :A ; " + " owl:minCardinality 1 ] " + " " + " rdfs:subClassOf :B . ");
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 body1 = bodyIt.next();
Atom body2 = bodyIt.next();
Atom head = headIt.next();
Assert.assertFalse(bodyIt.hasNext());
Assert.assertFalse(headIt.hasNext());
Assert.assertTrue(A.equals(body1.getPredicate()) || A.equals(body2.getPredicate()));
Assert.assertTrue(P.equals(body1.getPredicate()) || P.equals(body2.getPredicate()));
Assert.assertTrue(A.equals(body1.getPredicate()) || P.equals(body1.getPredicate()));
Assert.assertTrue(A.equals(body2.getPredicate()) || P.equals(body2.getPredicate()));
Assert.assertEquals(B, head.getPredicate());
}
}
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 complexClassAssertion.
@Test
public void complexClassAssertion() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":i1 a [owl:intersectionOf ( :A [owl:complementOf :B] ) ] ." + "");
int nbFacts = 0;
int nbConstraint = 0;
while (parser.hasNext()) {
Object o = parser.next();
if ((o instanceof InMemoryAtomSet)) {
++nbFacts;
CloseableIteratorWithoutException<Atom> it = ((InMemoryAtomSet) o).iterator();
Assert.assertTrue(it.hasNext());
Atom a = it.next();
Assert.assertEquals(A, a.getPredicate());
Assert.assertEquals(I1, a.getTerm(0));
}
if ((o instanceof DefaultNegativeConstraint)) {
++nbConstraint;
CloseableIteratorWithoutException<Atom> it = ((DefaultNegativeConstraint) o).getBody().iterator();
Assert.assertTrue(it.hasNext());
Atom a = it.next();
Assert.assertEquals(B, a.getPredicate());
Assert.assertEquals(I1, a.getTerm(0));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbFacts);
Assert.assertEquals("Number of assertions found:", 1, nbConstraint);
}
Aggregations