From 6bb2d3abcde920ef5ce2db425b2e95f678d29c63 Mon Sep 17 00:00:00 2001 From: ignazio Date: Sun, 14 Jan 2024 09:47:13 +0000 Subject: [PATCH] Fix #1112 force use of oboInOwl ns translating OBO IDs. This commit rewrites part of the OWLAPIObo2Owl#oboIdToIRI_load() method so that the oboInOwlDefault parameter is only used when translating unprefixed IDs (where it instructs to create an IRI in the oboInOwl namespace instead of the ontology's default namespace). When translating a prefixed ID, the IRI to construct should always use the URL prefix dictated by the prefix. --- .../obolibrary/oboformat/BasicsTestCase.java | 10 ++--- .../org/obolibrary/obo2owl/OWLAPIObo2Owl.java | 40 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) 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");