Search in sources :

Example 46 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project Vitro by vivo-project.

the class TBoxInferencesAccumulator method populateEquivalentClasses.

private void populateEquivalentClasses(OWLClass c, OWLReasoner r, Model m) {
    for (OWLClass equiv : r.getEquivalentClasses(c).getEntities()) {
        log.debug("Equivalent class: " + c + ", " + equiv);
        m.add(toResource(c), OWL_EQUIVALENT_CLASS, toResource(equiv));
    }
}
Also used : OWLClass(org.semanticweb.owlapi.model.OWLClass)

Example 47 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project onprom by onprom.

the class OBDAMaterializerImpl method retrieveAllClassInstances.

// ////////////////////////////////////////////////////////////////////////////
// Some supporting methods
// ////////////////////////////////////////////////////////////////////////////
public List<OWLClassAssertionAxiom> retrieveAllClassInstances() throws OWLException {
    // Collect all class names in the target ontology
    Set<OWLClass> classes = this.targetOntology.getClassesInSignature();
    ArrayList<OWLClassAssertionAxiom> results = new ArrayList<OWLClassAssertionAxiom>();
    QuestOWLConnection conn = questReasoner.getConnection();
    QuestOWLStatement st = conn.createStatement();
    try {
        OWLIndividual clsInstance;
        for (OWLClass cls : classes) {
            clsInstance = null;
            // System.out.println("\n\n------------------------------------\nProcessing the OWLClass "+ cls+"\n------------------------------------");
            String q = String.format(this.qClassRetrieverTemplate, cls.toString());
            // System.out.println("query: \n\t" + q +"\n");
            QuestOWLResultSet rs = st.executeTuple(q);
            // System.out.println("Creating Class Axiom for the class "+ cls);
            while (rs.nextRow()) {
                clsInstance = rs.getOWLIndividual(this.qClassRetrieverTemplateAnsVar);
                // System.out.println("clsInstance: "+clsInstance);
                results.add(this.owlDataFactory.getOWLClassAssertionAxiom(cls, clsInstance));
            }
        }
    } finally {
        if (st != null && !st.isClosed())
            st.close();
        if (conn != null && !conn.isClosed())
            conn.close();
    }
    return results;
}
Also used : QuestOWLConnection(it.unibz.inf.ontop.owlrefplatform.owlapi.QuestOWLConnection) QuestOWLStatement(it.unibz.inf.ontop.owlrefplatform.owlapi.QuestOWLStatement) QuestOWLResultSet(it.unibz.inf.ontop.owlrefplatform.owlapi.QuestOWLResultSet) ArrayList(java.util.ArrayList) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 48 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.

the class AssertedOntologyLoader method indexOntology.

protected OWLOntology indexOntology(final OWLOntology ontology) throws OWLOntologyCreationException {
    Set<OWLClass> allClasses = ontology.getClassesInSignature();
    removeExcludedClasses(ontology, allClasses, superclass -> getSubClasses(ontology, superclass));
    int labelCount = 0;
    int labelledClassCount = 0;
    int synonymCount = 0;
    int synonymedClassCount = 0;
    getLog().debug("Loading labels and synonyms...");
    for (OWLClass ontologyClass : allClasses) {
        IRI clsIri = ontologyClass.getIRI();
        // get IRI fragment/path
        Optional<String> accession = evaluateAccessionValue(ontology, ontologyClass);
        if (accession.isPresent()) {
            addClassAccession(clsIri, accession.get());
        }
        // get label annotations
        Optional<String> label = evaluateLabelAnnotationValue(ontology, ontologyClass);
        if (label.isPresent()) {
            addClassLabel(clsIri, label.get());
            labelledClassCount++;
            labelCount++;
        }
        // get all synonym annotations
        getLog().debug("Loading synonyms...");
        Set<String> synonyms = evaluateSynonymAnnotationValues(ontology, ontologyClass);
        if (!synonyms.isEmpty()) {
            addSynonyms(clsIri, synonyms);
            synonymCount += synonyms.size();
            synonymedClassCount++;
        }
        // get parent labels
        getLog().debug("Loading parents...");
        Set<String> parentLabelSet = new HashSet<>();
        Set<OWLClass> parents = getSuperClasses(ontology, ontologyClass);
        // only add type if the parent isn't excluded
        parents.stream().filter(allClasses::contains).forEach(parentClass -> {
            // only add type if the parent isn't excluded
            getLog().debug("Next parent of " + label + ": " + parentClass);
            evaluateLabelAnnotationValue(ontology, parentClass).ifPresent(parentLabelSet::add);
        });
        addClassParentLabels(clsIri, parentLabelSet);
        // get child labels
        getLog().debug("Loading children...");
        Set<String> childLabelSet = new HashSet<>();
        // always add current class to the parents
        label.ifPresent(childLabelSet::add);
        Set<OWLClass> children = getSubClasses(ontology, ontologyClass);
        // only add type if the child isn't excluded
        children.stream().filter(allClasses::contains).forEach(childClass -> {
            // only add type if the parent isn't excluded
            getLog().debug("Next child of " + label + ": " + childClass);
            evaluateLabelAnnotationValue(ontology, childClass).ifPresent(childLabelSet::add);
        });
        addClassChildLabels(clsIri, childLabelSet);
    // todo - get relationships
    }
    getLog().debug("Successfully indexed " + labelCount + " labels on " + labelledClassCount + " classes and " + synonymCount + " synonyms on " + synonymedClassCount + " classes!");
    return ontology;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLClass(org.semanticweb.owlapi.model.OWLClass) HashSet(java.util.HashSet)

Example 49 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.

the class AbstractOntologyLoader method getStringLiteralAnnotationValues.

protected Set<String> getStringLiteralAnnotationValues(OWLOntology ontology, OWLClass ontologyClass, OWLAnnotationProperty annotationProperty) {
    Set<String> vals = new HashSet<>();
    Collection<OWLAnnotation> annotations = ontologyClass.getAnnotations(ontology, annotationProperty);
    annotations.stream().filter(annotation -> annotation.getValue() instanceof OWLLiteral).forEach(annotation -> {
        OWLLiteral val = (OWLLiteral) annotation.getValue();
        vals.add(val.getLiteral());
    });
    return vals;
}
Also used : OWLRDFVocabulary(org.semanticweb.owlapi.vocab.OWLRDFVocabulary) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) OWLManager(org.semanticweb.owlapi.apibinding.OWLManager) Initializable(uk.ac.ebi.spot.goci.ontology.Initializable) HashSet(java.util.HashSet) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) IRI(org.semanticweb.owlapi.model.IRI) Map(java.util.Map) URI(java.net.URI) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Resource(org.springframework.core.io.Resource) SimpleIRIMapper(org.semanticweb.owlapi.util.SimpleIRIMapper) Iterator(java.util.Iterator) Collection(java.util.Collection) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) Set(java.util.Set) Collectors(java.util.stream.Collectors) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) Optional(java.util.Optional) Collections(java.util.Collections) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLAnnotation(org.semanticweb.owlapi.model.OWLAnnotation) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) HashSet(java.util.HashSet)

Example 50 with OWLClass

use of org.semanticweb.owlapi.model.OWLClass in project goci by EBISPOT.

the class CheckingService method validateEfoTrait.

public void validateEfoTrait(EfoTrait trait) {
    String uri = trait.getUri();
    String traitLabel = trait.getTrait();
    OWLClass cls = null;
    try {
        cls = ontologyService.getOWLClassByURI(uri);
    } catch (Exception e) {
        getLog().debug("IRI " + uri + " is not a valid IRI");
    }
    if (cls != null) {
        String label = ontologyLoader.getLabel(cls.getIRI());
        if (label != null) {
            boolean found = false;
            if (label.equalsIgnoreCase(traitLabel)) {
                found = true;
            }
            if (!found) {
                Set<String> syns = ontologyLoader.getSynonyms(cls.getIRI());
                for (String syn : syns) {
                    if (syn.equalsIgnoreCase(traitLabel)) {
                        found = true;
                    }
                }
                if (!found) {
                    getLog().info("Class " + uri + " (label: " + label + ") does not have a label or synonym of " + traitLabel + ". DB ID is " + trait.getId());
                }
            }
        } else {
            getLog().info("Class " + uri + " does not have a label");
        }
    } else {
        getLog().info(uri + " is not a valid EFO URI");
        Collection<OWLClass> classes = ontologyService.getOWLClassesByLabel(traitLabel);
        if (classes.isEmpty()) {
            getLog().info("No EFO classes match the label " + traitLabel);
        }
    }
}
Also used : OWLClass(org.semanticweb.owlapi.model.OWLClass)

Aggregations

OWLClass (org.semanticweb.owlapi.model.OWLClass)163 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)85 Set (java.util.Set)64 Collectors (java.util.stream.Collectors)62 List (java.util.List)59 ValidationError (com.opensimulationplatform.core.validation.ValidationError)53 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)29 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)20 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)20 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)18 IRI (org.semanticweb.owlapi.model.IRI)17 HashSet (java.util.HashSet)16 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)16 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)14 OWLAnnotation (org.semanticweb.owlapi.model.OWLAnnotation)13 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)13 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)9 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)8