Search in sources :

Example 1 with UnexpectedOntologyStructureException

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);
            }
        }
    }
}
Also used : UnexpectedOntologyStructureException(uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException) OWLClass(org.semanticweb.owlapi.model.OWLClass)

Example 2 with UnexpectedOntologyStructureException

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);
    }
}
Also used : OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) UnexpectedOntologyStructureException(uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Aggregations

UnexpectedOntologyStructureException (uk.ac.ebi.spot.goci.ontology.exception.UnexpectedOntologyStructureException)2 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLClass (org.semanticweb.owlapi.model.OWLClass)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1