use of uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException in project goci by EBISPOT.
the class IRITreeBuilder method recurse.
private void recurse(OWLReasoner reasoner, OWLOntology efo, OWLClassExpression parentClass, IRINode parentNode) {
NodeSet<OWLClass> subclasses = reasoner.getSubClasses(parentClass, true);
// get subclasses
for (Node<OWLClass> node : subclasses) {
// get next child class
OWLClass childClass = node.getRepresentativeElement();
if (!childClass.getIRI().toString().equals(owlNothingIRI)) {
getLog().debug("Next child of " + parentClass + " is " + childClass);
String label;
try {
label = getClassLabel(efo, childClass);
} catch (UnexpectedOntologyStructureException e) {
label = "<not exactly 1 label>";
}
IRINode childNode = new IRINode(childClass.getIRI(), label);
if (!parentNode.getChildNodes().contains(childNode)) {
// only need to recurse deeper if this child was not already added
parentNode.addChildNode(childNode);
recurse(reasoner, efo, childClass, childNode);
}
}
}
}
use of uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException in project goci by EBISPOT.
the class IRITreeBuilder method getClassLabel.
private String getClassLabel(OWLOntology ontology, OWLClass cls) {
OWLDataFactory factory = ontology.getOWLOntologyManager().getOWLDataFactory();
OWLAnnotationProperty label = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
String className = null;
for (OWLAnnotation annotation : cls.getAnnotations(ontology, label)) {
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteral val = (OWLLiteral) annotation.getValue();
className = val.getLiteral();
}
if (cls.getAnnotations(ontology, label).size() != 1) {
throw new UnexpectedOntologyStructureException("More than one label for class " + cls);
}
}
if (className != null) {
return className;
} else {
throw new UnexpectedOntologyStructureException("There is no label for class " + cls);
}
}
Aggregations