diff --git a/OWLTools-Core/.settings/org.eclipse.jdt.core.prefs b/OWLTools-Core/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 714351aec..000000000 --- a/OWLTools-Core/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java index 68c5cbd58..940104231 100644 --- a/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java +++ b/OWLTools-Core/src/main/java/owltools/graph/OWLGraphWrapperExtended.java @@ -1,6 +1,7 @@ package owltools.graph; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -893,30 +894,36 @@ public String getIdentifier(IRI iriId) { return (String) SerializationUtils.clone(Owl2Obo.getIdentifier(iriId)); final OWLAnnotationProperty oboIdInOwl = getDataFactory().getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_ID.getTag())); - OWLClass oc = getOWLClass(iriId); for (OWLOntology o : getAllOntologies()) { - for (OWLAnnotation oa: EntitySearcher.getAnnotations(oc.getIRI(), o)) { - if (oa.getProperty().equals(oboIdInOwl) != true) + Collection oas = EntitySearcher.getAnnotations(iriId, o); + if (oas == null) continue; + + for (OWLAnnotation oa: oas) { + // We specifically look for the annotation property, oboInOwl:id; ignore others. + if (oa.getProperty().equals(oboIdInOwl) != true) continue; + // We then get the object value of this property, which is supposed to be a literal. OWLAnnotationValue objValue = oa.getValue(); if (objValue.isLiteral() != true) { - LOG.warn(objValue + " is supposed to be an literal, but it is not?!"); + LOG.warn("Odd. " + objValue + " of oboInOw#id for "+ iriId + ", is supposed to be an literal, but it is not."); continue; } Optional literalOpt = objValue.asLiteral(); if (literalOpt.isPresent() != true) { - LOG.warn("Is the literal value of oboInOw#id, " + objValue + ", null?"); + LOG.warn("Odd. " + objValue + " of oboInOw#id for "+ iriId + ", does not exist."); continue; } OWLLiteral literal = literalOpt.get(); return (String) SerializationUtils.clone(literal.getLiteral()); } - } + } - throw new RuntimeException("The IRI " + iriId + " does not start with the obolib prefix nor have any oboInOw#id?!"); + // In the case where the input class does not have oboInOwl#id, we return its original URL. + LOG.warn("Unable to retrieve the value of oboInOw#id as the identifier for " + iriId + "; we will use an original iri as the identifier."); + return (String) SerializationUtils.clone(iriId.toString()); } public IRI getIRIByIdentifier(String id) { diff --git a/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java b/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java index e17ee43cd..d4107732d 100644 --- a/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java +++ b/OWLTools-Core/src/test/java/owltools/graph/OWLGraphWrapperExtendedTest.java @@ -43,9 +43,11 @@ public void testGetIdentifier() throws Exception { String id1 = wrapper.getIdentifier(IRI.create("http://purl.obolibrary.org/obo/GO_0000001")); String id2 = wrapper.getIdentifier(IRI.create("http://purl.obolibrary.org/obo/GO_0000002")); String id3 = wrapper.getIdentifier(IRI.create("http://example.com/X_005")); + String id4 = wrapper.getIdentifier(IRI.create("http://example.com/X_010")); assertEquals(id1, "GO:0000001"); assertEquals(id2, "GO:0000002"); assertEquals(id3, "X:5"); + assertEquals(id4, "http://example.com/X_010"); } } \ No newline at end of file diff --git a/OWLTools-Core/src/test/resources/graph/dummy-ontology.owl b/OWLTools-Core/src/test/resources/graph/dummy-ontology.owl index deeab08a5..020f49bac 100644 --- a/OWLTools-Core/src/test/resources/graph/dummy-ontology.owl +++ b/OWLTools-Core/src/test/resources/graph/dummy-ontology.owl @@ -28,4 +28,8 @@ X:5 - + + + test4 + + \ No newline at end of file