diff --git a/contract/src/test/java/org/obolibrary/oboformat/BasicsTestCase.java b/contract/src/test/java/org/obolibrary/oboformat/BasicsTestCase.java index 5b5dc15f4c..6fc050fff5 100644 --- a/contract/src/test/java/org/obolibrary/oboformat/BasicsTestCase.java +++ b/contract/src/test/java/org/obolibrary/oboformat/BasicsTestCase.java @@ -839,11 +839,11 @@ void testIDs() { assertEquals("http://purl.obolibrary.org/obo/GO_001", iri.toString()); // OWL 2 obo String oboId = OWLAPIOwl2Obo.getIdentifier(iri); - assertEquals(GO_001, oboId); + assertEquals("GO:001", oboId); iri = obo2owl.oboIdToIRI("My_Ont:FOO_002"); - assertEquals("http://purl.obolibrary.org/obo/My_Ont#_FOO_002", iri.toString()); + assertEquals("http://purl.obolibrary.org/obo/My_Ont_#FOO_002", iri.toString()); oboId = OWLAPIOwl2Obo.getIdentifier(iri); - assertEquals("My_Ont:FOO_002", oboId); + assertEquals("FOO_002", oboId); iri = obo2owl.oboIdToIRI("My_Ont:002"); assertEquals("http://purl.obolibrary.org/obo/My_Ont_002", iri.toString()); // OWL 2 obo @@ -864,10 +864,10 @@ void testIDs() { oboId = OWLAPIOwl2Obo.getIdentifier(iri); assertEquals(PART_OF, oboId); iri = obo2owl.oboIdToIRI(OBO_REL_PART_OF); - assertEquals("http://purl.obolibrary.org/obo/OBO_REL#_part_of", iri.toString()); + assertEquals("http://purl.obolibrary.org/obo/OBO_REL_#part_of", iri.toString()); // OWL 2 obo oboId = OWLAPIOwl2Obo.getIdentifier(iri); - assertEquals(OBO_REL_PART_OF, oboId); + assertEquals("part_of", oboId); iri = obo2owl.oboIdToIRI(TESTONT); assertEquals(TESTONT, iri.toString()); // OWL 2 obo diff --git a/oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java b/oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java index 3501203aed..0c6063f408 100644 --- a/oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java +++ b/oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java @@ -1558,33 +1558,33 @@ public IRI loadOboToIRI(String id, boolean oboInOwlDefault) { } } String[] idParts = id.split(":", 2); - String db; + String uriPrefix; String localId; - if (idParts.length > 1) { - db = idParts[0]; + if (idParts.length > 1) { // Prefixed-ID (canonical or not) localId = idParts[1]; + uriPrefix = idSpaceMap.getOrDefault(idParts[0], DEFAULT_IRI_PREFIX + idParts[0] + '_'); + + // Non-canonical prefixed IDs use a '#' separator + // TODO - recognize all non-canonical prefixed IDs if (localId.contains("_")) { - db += "#_";// NonCanonical-Prefixed-ID - } else { - db += "_"; + uriPrefix += "#"; + } + } else { // Unprefixed-ID + // Special case for relation xrefs (5.9.3. Special Rules for Relations) + String xid = translateShorthandIdToExpandedId(id); + if (!xid.equals(id)) { + return oboIdToIRI(xid); } - } else if (idParts.length == 0) { - db = getDefaultIDSpace() + '#'; + localId = id; - } else { - // TODO use owlOntology IRI - db = getDefaultIDSpace() + '#'; - localId = idParts[0]; - } - String uriPrefix; - if (oboInOwlDefault) { - uriPrefix = OIOVOCAB_IRI_PREFIX; - } else { - uriPrefix = DEFAULT_IRI_PREFIX + db; - if (idSpaceMap.containsKey(db)) { - uriPrefix = idSpaceMap.get(db); + if (oboInOwlDefault) { + uriPrefix = OIOVOCAB_IRI_PREFIX; + } else { + // TODO - use ontology ID as specified in OBO-Format 5.9.2? + uriPrefix = DEFAULT_IRI_PREFIX + getDefaultIDSpace() + '#'; } } + String safeId; try { safeId = java.net.URLEncoder.encode(localId, "US-ASCII");