Search in sources :

Example 6 with OWLReasoner

use of org.semanticweb.owlapi.reasoner.OWLReasoner in project goci by EBISPOT.

the class GOCIDataPublisherDriver method publishAndSave.

public void publishAndSave(File assertedOntologyFile, File inferredOntologyFile) throws RuntimeException {
    try {
        // publishAndSave the data
        System.out.println("Attempting to convert and publish GWAS data as OWL...");
        OWLOntology ontology = getGwasOwlPublisher().publishGWASData();
        // and save the result
        System.out.print("Ontology converted, saving asserted results...");
        getGwasOwlPublisher().saveGWASData(ontology, assertedOntologyFile);
        System.out.println("..done!");
        if (inferredOntologyFile != null) {
            // now get the inferred view
            System.out.println("Evaluating inferred view...");
            OWLReasoner reasoner = getGwasOwlPublisher().publishGWASDataInferredView(ontology);
            // now save inferred view
            System.out.print("Ontology fully classified, saving inferred results...");
            getGwasOwlPublisher().saveGWASDataInferredView(reasoner, inferredOntologyFile);
            System.out.println("..done!");
        }
    } catch (OWLConversionException e) {
        System.err.println("Failed to publish data to OWL: " + e.getMessage());
        getLog().error("Failed to publish data to OWL: ", e);
        throw new RuntimeException(e);
    } catch (Exception e) {
        System.err.println("Failed to publish data to OWL (an unexpected exception occurred): " + e.getMessage());
        getLog().error("Failed to publish data to OWL (an unexpected exception occurred): ", e);
        throw new RuntimeException(e);
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) ParseException(org.apache.commons.cli.ParseException)

Example 7 with OWLReasoner

use of org.semanticweb.owlapi.reasoner.OWLReasoner in project stanbol by apache.

the class AbstractOWLApiReasoningService method run.

/**
     * Generic method for running the reasoner
     * 
     * @param input
     * @param generators
     * @return
     */
@Override
public Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException, InconsistentInputException {
    log.debug("run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators)");
    try {
        // Get the manager
        OWLOntologyManager manager = createOWLOntologyManager();
        // Get the reasoner
        OWLReasoner reasoner = getReasoner(input);
        log.info("Running {} reasoner on {} ", reasoner.getClass(), input.getOntologyID());
        // To generate inferred axioms
        InferredOntologyGenerator inferred = new InferredOntologyGenerator(reasoner, generators);
        // We fill an anonymous ontology with the result, the return the
        // axiom set
        Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
        try {
            OWLOntology output = manager.createOntology();
            log.debug("Created output ontology: {}", output);
            try {
                inferred.fillOntology(manager, output);
            } catch (InconsistentOntologyException i) {
                throw i;
            } catch (Throwable t) {
                log.error("Some problem occurred:\n {}", t.getStackTrace());
                throw new ReasoningServiceException();
            }
            log.debug("Filled ontology: {}", output);
            log.debug("Temporary ID is {}", output.getOntologyID());
            axioms = manager.getOntology(output.getOntologyID()).getAxioms();
            // IMPORTANT We remove the ontology from the manager
            manager.removeOntology(output);
        } catch (OWLOntologyCreationException e) {
            log.error("An exception have been thrown when instantiating the ontology");
            throw new ReasoningServiceException();
        }
        return axioms;
    } catch (InconsistentOntologyException inconsistent) {
        /**
             * TODO Add report. Why it is inconsistent?
             */
        throw new InconsistentInputException();
    } catch (Exception exception) {
        log.error("An exception have been thrown while executing method run()", exception);
        throw new ReasoningServiceException();
    }
}
Also used : OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) InconsistentInputException(org.apache.stanbol.reasoners.servicesapi.InconsistentInputException) InconsistentOntologyException(org.semanticweb.owlapi.reasoner.InconsistentOntologyException) UnsupportedTaskException(org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException) ReasoningServiceException(org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) InconsistentOntologyException(org.semanticweb.owlapi.reasoner.InconsistentOntologyException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) InferredOntologyGenerator(org.semanticweb.owlapi.util.InferredOntologyGenerator) HashSet(java.util.HashSet)

Aggregations

OWLReasoner (org.semanticweb.owlapi.reasoner.OWLReasoner)7 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)5 HashSet (java.util.HashSet)2 OWLClass (org.semanticweb.owlapi.model.OWLClass)2 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)2 ConsoleProgressMonitor (org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor)2 OWLReasonerConfiguration (org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration)2 OWLReasonerFactory (org.semanticweb.owlapi.reasoner.OWLReasonerFactory)2 SimpleConfiguration (org.semanticweb.owlapi.reasoner.SimpleConfiguration)2 OWLConversionException (uk.ac.ebi.spot.goci.exception.OWLConversionException)2 URI (java.net.URI)1 ParseException (org.apache.commons.cli.ParseException)1 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)1 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)1 UnsupportedTaskException (org.apache.stanbol.reasoners.servicesapi.UnsupportedTaskException)1 Test (org.junit.Test)1 Configuration (org.semanticweb.HermiT.Configuration)1 ReasonerFactory (org.semanticweb.HermiT.Reasoner.ReasonerFactory)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1