Search in sources :

Example 1 with OWLOntologyCreationException

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

the class DefaultGWASOWLConverter method createConversionOntology.

public OWLOntology createConversionOntology() throws OWLConversionException {
    try {
        // create a new graph to represent our data dump
        OWLOntology conversion = getManager().createOntology(IRI.create(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI + "/" + new SimpleDateFormat("yyyy/MM/dd").format(new Date())));
        // import the gwas ontology schema and efo
        OWLImportsDeclaration gwasImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.GWAS_ONTOLOGY_SCHEMA_IRI));
        ImportChange gwasImport = new AddImport(conversion, gwasImportDecl);
        getManager().applyChange(gwasImport);
        OWLImportsDeclaration efoImportDecl = getDataFactory().getOWLImportsDeclaration(IRI.create(OntologyConstants.EFO_ONTOLOGY_SCHEMA_IRI));
        ImportChange efoImport = new AddImport(conversion, efoImportDecl);
        getManager().applyChange(efoImport);
        return conversion;
    } catch (OWLOntologyCreationException e) {
        throw new OWLConversionException("Failed to create new ontology", e);
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLImportsDeclaration(org.semanticweb.owlapi.model.OWLImportsDeclaration) SimpleDateFormat(java.text.SimpleDateFormat) AddImport(org.semanticweb.owlapi.model.AddImport) Date(java.util.Date) ImportChange(org.semanticweb.owlapi.model.ImportChange)

Example 2 with OWLOntologyCreationException

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

the class KBMetricsDriver method generateMetricsReport.

/**
     * Generate a report on the data metrics of the knowledgebase and write them this report to the supplied output
     * stream
     *
     * @param out the output stream to write the report to
     */
public void generateMetricsReport(OutputStream out) throws MetricsCalculationException, IOException {
    try {
        // first, calculate data spread in KB
        Map<IRI, Integer> metrics = loader.quantifyKnowledgeBase(_efoLocation, _gwasSchemaLocation, _kbLocation);
        // build the efo tree
        IRITree tree = treeBuilder.buildIRITree(_efoLocation);
        // now tree is constructed, overlay counts onto it
        walkTreeAndAddCounts(tree.getRootNode(), metrics);
        // process the tree and write the "ideal legend" report
        treeProcessor.processTree(tree, out);
        // write the tree into a report
        tree.prettyPrint(out);
    } catch (OWLOntologyCreationException e) {
        throw new MetricsCalculationException("Failed to calculate metrics because one or more ontologies failed to load " + "(" + e.getMessage() + ")", e);
    } catch (URISyntaxException e) {
        throw new MetricsCalculationException("Failed to calculate metrics - a reference to a supplied location was not valid " + "(" + e.getMessage() + ")", e);
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) MetricsCalculationException(uk.ac.ebi.spot.goci.exception.MetricsCalculationException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) URISyntaxException(java.net.URISyntaxException) IRITree(uk.ac.ebi.spot.goci.tree.IRITree)

Example 3 with OWLOntologyCreationException

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

the class AbstractOntologyLoader method loadOntology.

/**
     * Extracts and loads into memory all the class labels and corresponding IRIs.  This class makes the assumption that
     * one primary label per class exists. If any classes contain multiple rdfs:labels, these classes are ignored.
     * <p>
     * Once loaded, this method must set the IRI of the ontology, and should add class labels, class types (however you
     * chose to implement the concept of a "type") and synonyms, where they exist.
     * <p>
     * Implementations do not need to concern themselves with resolving imports or physical/logical mappings as this is
     * done in initialisation at the abstract level.  Subclasses can simply do <code>OWLOntology ontology =
     * getManager().loadOntology(IRI.create(getOntologyURI()));</code> as a basic implementation before populating the
     * various required caches
     */
protected OWLOntology loadOntology() throws OWLOntologyCreationException {
    try {
        getLog().debug("Loading ontology...");
        OWLOntology ontology = getManager().loadOntology(IRI.create(getOntologyURI()));
        IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI();
        if (ontologyIRI == null) {
            throw new OWLOntologyCreationException("Failed to load ontology from " + getOntologyURI() + ": " + "no IRI present for this ontology");
        } else {
            setOntologyIRI(ontologyIRI);
            if (getOntologyName() == null) {
                URI ontologyURI = ontologyIRI.toURI();
                String name = ontologyURI.getFragment() != null ? ontologyURI.getFragment() : ontologyURI.getPath();
                if (name == null) {
                    getLog().warn("Can't shorten the name for " + ontologyIRI.toString());
                    name = ontologyURI.toString();
                }
                setOntologyName(name);
            }
            getLog().debug("Successfully loaded ontology " + ontologyIRI);
            getLog().debug("Computing indexes...");
            return indexOntology(ontology);
        }
    } finally {
        getLog().debug("Done loading/indexing");
    }
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) URI(java.net.URI)

Example 4 with OWLOntologyCreationException

use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.

the class HermitReasoningServiceTest method testRun.

private void testRun(String testID, String expectedID) {
    log.info("Testing the run() method");
    OWLOntologyManager manager = TestData.manager;
    // We prepare the input ontology
    try {
        OWLOntology testOntology = manager.createOntology();
        OWLOntologyID testOntologyID = testOntology.getOntologyID();
        log.debug("Created test ontology with ID: {}", testOntologyID);
        AddImport addImport = new AddImport(testOntology, TestData.factory.getOWLImportsDeclaration(IRI.create(testID)));
        manager.applyChange(addImport);
        // We just test class assertions
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        gens.add(new InferredClassAssertionAxiomGenerator());
        // Maybe we want to see what is in before
        if (log.isDebugEnabled())
            TestUtils.debug(manager.getOntology(testOntologyID), log);
        // Now we test the method
        log.debug("Running HermiT");
        Set<OWLAxiom> inferred = this.theinstance.run(manager.getOntology(testOntologyID), gens);
        // Maybe we want to see the inferred axiom list
        if (log.isDebugEnabled()) {
            TestUtils.debug(inferred, log);
        }
        // These are the set of expected axioms
        Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(expectedID)).getLogicalAxioms();
        Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
        for (OWLAxiom expected : expectedAxioms) {
            if (!inferred.contains(expected)) {
                log.error("missing expected axiom: {}", expected);
                missing.add(expected);
            }
        }
        log.info("Are all expected axioms in the result (true)? {}", missing.isEmpty());
        assertTrue(missing.isEmpty());
        // We want to remove the ontology from the manager
        manager.removeOntology(testOntology);
    } catch (OWLOntologyCreationException e) {
        log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
        assertTrue(false);
    } catch (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    } catch (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException e) {
        log.error("An {} have been thrown while executing the reasoning", e.getClass());
        assertTrue(false);
    }
}
Also used : OWLLogicalAxiom(org.semanticweb.owlapi.model.OWLLogicalAxiom) InferredAxiomGenerator(org.semanticweb.owlapi.util.InferredAxiomGenerator) ArrayList(java.util.ArrayList) AddImport(org.semanticweb.owlapi.model.AddImport) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) InferredClassAssertionAxiomGenerator(org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) HashSet(java.util.HashSet)

Example 5 with OWLOntologyCreationException

use of org.semanticweb.owlapi.model.OWLOntologyCreationException in project stanbol by apache.

the class OntologyManagerInputProvider method getFromOntoMgr.

private OWLOntology getFromOntoMgr() throws IOException {
    try {
        Scope scope = null;
        synchronized (onManager) {
            scope = onManager.getScope(this.scopeId);
        }
        if (scope == null) {
            log.error("Scope {} cannot be retrieved", this.scopeId);
            throw new IOException("Scope " + this.scopeId + " cannot be retrieved");
        }
        Session session = null;
        if (sessionManager != null)
            synchronized (sessionManager) {
                session = sessionManager.getSession(sessionId);
            }
        if (session == null)
            log.warn("Session {} cannot be retrieved. Ignoring.", this.sessionId);
        final Set<OWLOntology> set = new HashSet<OWLOntology>();
        set.add(scope.export(OWLOntology.class, true));
        if (session != null)
            set.add(session.export(OWLOntology.class, true));
        if (set.size() == 1)
            return set.iterator().next();
        OWLOntologyMerger merger = new OWLOntologyMerger(new OWLOntologySetProvider() {

            @Override
            public Set<OWLOntology> getOntologies() {
                return set;
            }
        });
        return merger.createMergedOntology(createOWLOntologyManager(), IRI.create("reasoners:input-" + System.currentTimeMillis()));
    } catch (OWLOntologyCreationException e) {
        String message = "The network for scope/session cannot be retrieved";
        log.error(message + ":", e);
        throw new IllegalArgumentException(message);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OWLOntologyMerger(org.semanticweb.owlapi.util.OWLOntologyMerger) IOException(java.io.IOException) OWLOntologySetProvider(org.semanticweb.owlapi.model.OWLOntologySetProvider) Scope(org.apache.stanbol.ontologymanager.servicesapi.scope.Scope) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Session(org.apache.stanbol.ontologymanager.servicesapi.session.Session) HashSet(java.util.HashSet)

Aggregations

OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)54 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)45 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)33 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)18 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)15 HashSet (java.util.HashSet)13 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)13 AddImport (org.semanticweb.owlapi.model.AddImport)12 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)11 ArrayList (java.util.ArrayList)10 OntModel (com.hp.hpl.jena.ontology.OntModel)9 WebApplicationException (javax.ws.rs.WebApplicationException)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)9 IRI (org.semanticweb.owlapi.model.IRI)9 OWLClass (org.semanticweb.owlapi.model.OWLClass)9 IOException (java.io.IOException)8 Consumes (javax.ws.rs.Consumes)8 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 POST (javax.ws.rs.POST)7