Skip to content

Commit

Permalink
Fix #1112 force use of oboInOwl ns translating OBO IDs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ignazio1977 committed Jan 14, 2024
1 parent d63b26b commit 6bb2d3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 20 additions & 20 deletions oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 6bb2d3a

Please sign in to comment.