use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method inverseFunctionalObjectProperty.
@Test
public void inverseFunctionalObjectProperty() {
// Y = Z :- p(Y, X), p(Z, X).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:InverseFunctionalProperty . ");
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 = it.next();
Atom b2 = it.next();
Assert.assertFalse(it.hasNext());
it = r.getHead().iterator();
Atom h = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(P, b1.getPredicate());
Assert.assertEquals(P, b2.getPredicate());
Assert.assertEquals(Predicate.EQUALITY, h.getPredicate());
Assert.assertEquals(b1.getTerm(1), b2.getTerm(1));
Assert.assertTrue(b1.getTerm(0).equals(h.getTerm(0)) || b1.getTerm(0).equals(h.getTerm(1)));
Assert.assertTrue(b2.getTerm(0).equals(h.getTerm(0)) || b2.getTerm(0).equals(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 complexSubClassExpression.
@Test
public void complexSubClassExpression() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + ":D rdf:type owl:Class . " + ":E rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + "[ owl:intersectionOf ( " + " :B [ owl:unionOf ( " + " :E [rdf:type owl:Restriction ; " + " owl:onProperty :p ;" + " owl:someValuesFrom [" + " owl:unionOf ( :C :D ) ]" + " ] ) " + " ] )" + "] rdfs:subClassOf :A . ");
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());
bodyIt.next();
Assert.assertTrue(bodyIt.hasNext());
Assert.assertTrue(headIt.hasNext());
Atom head = headIt.next();
Assert.assertEquals(A, head.getPredicate());
Assert.assertFalse(headIt.hasNext());
}
}
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 intersectionOfUnion.
// /////////////////////////////////////////////////////////////////////////
// DISJUNCTIVE NORMAL FORM TEST
// /////////////////////////////////////////////////////////////////////////
@Test
public void intersectionOfUnion() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":ClassA rdf:type owl:Class . " + ":ClassB rdf:type owl:Class . " + ":ClassC rdf:type owl:Class . " + ":ClassD rdf:type owl:Class . " + "[ owl:intersectionOf ( :ClassA [ owl:unionOf ( :ClassB :ClassC ) ] ) ] rdfs:subClassOf :ClassD. ");
int nbRules = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof Rule) {
++nbRules;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 2, nbRules);
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method complexAssertionWithExistential.
@Test
public void complexAssertionWithExistential() throws OWL2ParserException {
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A a owl:Class . " + ":B a owl:Class . " + ":p a owl:ObjectProperty . " + "_:x1 a :A. " + "_:y1 a :B. " + "_:x1 :p _:y1. " + "_:x2 a :A. " + "_:y2 a :B. " + "_:x2 :p _:y2. ");
int nbFacts = 0;
int nbAtoms = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (o instanceof AtomSet) {
Term a0 = null, b0 = null, p0 = null, p1 = null;
++nbFacts;
CloseableIterator<Atom> it = ((AtomSet) o).iterator();
while (it.hasNext()) {
Atom a = it.next();
++nbAtoms;
if (a.getPredicate().equals(P)) {
p0 = a.getTerm(0);
p1 = a.getTerm(1);
} else if (a.getPredicate().equals(A)) {
a0 = a.getTerm(0);
} else if (a.getPredicate().equals(B)) {
b0 = a.getTerm(0);
}
}
Assert.assertEquals(p0, a0);
Assert.assertEquals(p1, b0);
}
}
parser.close();
Assert.assertEquals("Number of facts found:", 2, nbFacts);
Assert.assertEquals("Number of atoms found:", 6, nbAtoms);
} catch (Throwable e) {
Assert.fail("An exception was found: " + e);
}
}
use of fr.lirmm.graphik.graal.io.owl.OWL2Parser in project graal by graphik-team.
the class OWL2ParserTest method complexObjectMaxCardinality1.
@Test
public void complexObjectMaxCardinality1() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":A rdf:type owl:Class . " + ":B rdf:type owl:Class . " + ":C rdf:type owl:Class . " + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":r rdf:type owl:ObjectProperty . " + " [a owl:Restriction; owl:onProperty :r; owl:someValuesFrom :A ] rdfs:subClassOf [ rdf:type owl:Restriction ; " + " owl:onProperty :p ; " + " owl:onClass [ owl:unionOf ( [a owl:Restriction; owl:onProperty :q; owl:someValuesFrom :B ] :C ) ] ; " + " owl:maxCardinality 1 ] . ");
int nbRules = 0;
while (parser.hasNext()) {
if (parser.next() instanceof Rule)
++nbRules;
}
parser.close();
Assert.assertEquals("Number of assertions found:", 3, nbRules);
}
Aggregations