public class RoundTripCardinalityTest extends RoundTripTest {
@Test
public void testRoundTripCardinality() throws Exception {
// create minimal ontology
OBODoc oboDocSource = parseOBOFile("roundtrip_cardinality.obo");
// convert to OWL and retrieve def
OWLAPIObo2Owl bridge = new OWLAPIObo2Owl(
OWLManager.createOWLOntologyManager());
OWLOntology owlOntology = bridge.convert(oboDocSource);
OWLDataFactory factory = owlOntology.getOWLOntologyManager()
.getOWLDataFactory();
OWLClass c = factory.getOWLClass(bridge.oboIdToIRI("PR:000027136"));
// Relations
boolean foundRel1 = false;
boolean foundRel2 = false;
Set<OWLSubClassOfAxiom> axioms = owlOntology
.getSubClassAxiomsForSubClass(c);
assertEquals(3, axioms.size());
for (OWLSubClassOfAxiom axiom : axioms) {
OWLClassExpression superClass = axiom.getSuperClass();
if (superClass instanceof OWLObjectExactCardinality) {
OWLObjectExactCardinality cardinality = (OWLObjectExactCardinality) superClass;
OWLClassExpression filler = cardinality.getFiller();
assertFalse(filler.isAnonymous());
IRI iri = filler.asOWLClass().getIRI();
if (iri.equals(bridge.oboIdToIRI("PR:000005116"))) {
foundRel1 = true;
assertEquals(1, cardinality.getCardinality());
} else if (iri.equals(bridge.oboIdToIRI("PR:000027122"))) {
foundRel2 = true;
assertEquals(2, cardinality.getCardinality());
}
}
}
assertTrue(foundRel1);
assertTrue(foundRel2);
// convert back to OBO
OWLAPIOwl2Obo owl2Obo = new OWLAPIOwl2Obo(
OWLManager.createOWLOntologyManager());
OBODoc convertedOboDoc = owl2Obo.convert(owlOntology);
Frame convertedFrame = convertedOboDoc.getTermFrame("PR:000027136");
Collection<Clause> clauses = convertedFrame
.getClauses(OboFormatTag.TAG_RELATIONSHIP);
// check that round trip still contains relationships
assertEquals(2, clauses.size());
for (Clause clause : clauses) {