use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class OWL2ParserTest method assertionDataProperty.
@Test
public void assertionDataProperty() throws OWL2ParserException, IteratorException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:DatatypeProperty . " + ":i1 :p 7 ." + "");
boolean found = false;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
AtomSet atomset = (AtomSet) o;
Atom a = atomset.iterator().next();
Assert.assertEquals(P, a.getPredicate());
Iterator<Term> it = a.iterator();
Assert.assertEquals(I1, it.next());
Assert.assertEquals(L1, it.next());
found = true;
}
}
parser.close();
Assert.assertTrue("Number of assertions found:", found);
}
use of fr.lirmm.graphik.graal.api.core.Atom 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.api.core.Atom in project graal by graphik-team.
the class OWL2ParserTest method objectInverseOf.
// /////////////////////////////////////////////////////////////////////////
// OTHERS
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectInverseOf() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p rdfs:subPropertyOf [owl:inverseOf :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.assertEquals(P, subProperty.getPredicate());
Assert.assertEquals(Q, property.getPredicate());
Assert.assertEquals(subProperty.getTerm(0), property.getTerm(1));
Assert.assertEquals(subProperty.getTerm(1), property.getTerm(0));
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbRules);
}
use of fr.lirmm.graphik.graal.api.core.Atom in project graal by graphik-team.
the class OWL2ParserTest method inverseObjectProperty.
@Test
public void inverseObjectProperty() {
// q(X, Y) <-> p(Y, X).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":q rdf:type owl:ObjectProperty . " + ":p owl:inverseOf :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(1));
Assert.assertEquals(property.getTerm(1), subProperty.getTerm(0));
}
}
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.Atom in project graal by graphik-team.
the class OWL2ParserTest method objectPropertyRange.
// /////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////
@Test
public void objectPropertyRange() {
// C(Y) :- p(X, Y).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:range :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(1), classs.getTerm(0));
found = true;
}
}
parser.close();
Assert.assertTrue("Number of assertions found:", found);
} catch (Exception e) {
Assert.assertFalse(e.getMessage(), true);
}
}
Aggregations