Skip to content

Commit

Permalink
Merge pull request #249 from owlcollab/bugfix-get-identifier
Browse files Browse the repository at this point in the history
Fixed the null exception error in GetIdentifier
  • Loading branch information
kltm authored Apr 24, 2018
2 parents c498f85 + 8a676df commit a2d32ee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
5 changes: 0 additions & 5 deletions OWLTools-Core/.settings/org.eclipse.jdt.core.prefs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<OWLAnnotation> 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<OWLLiteral> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
6 changes: 5 additions & 1 deletion OWLTools-Core/src/test/resources/graph/dummy-ontology.owl
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
<owl:Class rdf:about="http://example.com/X_005">
<oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">X:5</oboInOwl:id>
</owl:Class>
</rdf:RDF>

<owl:Class rdf:about="http://example.com/X_010">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">test4</rdfs:label>
</owl:Class>
</rdf:RDF>

0 comments on commit a2d32ee

Please sign in to comment.