Search in sources :

Example 1 with InferredOntologyGenerator

use of org.semanticweb.owlapi.util.InferredOntologyGenerator in project goci by EBISPOT.

the class DefaultGWASOWLPublisher method saveGWASDataInferredView.

public void saveGWASDataInferredView(OWLReasoner reasoner, File outputFile) throws OWLConversionException {
    try {
        // create new ontology to hold inferred axioms
        OWLOntology inferredOntology = getConverter().createConversionOntology();
        getLog().info("Saving inferred view...");
        List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
        // we require all inferred stuff except for disjoints...
        gens.add(new InferredClassAssertionAxiomGenerator());
        gens.add(new InferredDataPropertyCharacteristicAxiomGenerator());
        gens.add(new InferredEquivalentClassAxiomGenerator());
        gens.add(new InferredEquivalentDataPropertiesAxiomGenerator());
        gens.add(new InferredEquivalentObjectPropertyAxiomGenerator());
        gens.add(new InferredInverseObjectPropertiesAxiomGenerator());
        gens.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
        gens.add(new InferredPropertyAssertionGenerator());
        gens.add(new InferredSubClassAxiomGenerator());
        gens.add(new InferredSubDataPropertyAxiomGenerator());
        gens.add(new InferredSubObjectPropertyAxiomGenerator());
        // now create the target ontology and save
        OWLOntologyManager inferredManager = inferredOntology.getOWLOntologyManager();
        InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
        iog.fillOntology(inferredManager, inferredOntology);
        inferredManager.saveOntology(inferredOntology, IRI.create(outputFile));
        getLog().info("Inferred view saved ok");
    } catch (OWLOntologyStorageException e) {
        throw new OWLConversionException("Failed to save GWAS data (inferred view)", e);
    }
}
Also used : InferredSubClassAxiomGenerator(org.semanticweb.owlapi.util.InferredSubClassAxiomGenerator) InferredDataPropertyCharacteristicAxiomGenerator(org.semanticweb.owlapi.util.InferredDataPropertyCharacteristicAxiomGenerator) InferredEquivalentDataPropertiesAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentDataPropertiesAxiomGenerator) InferredPropertyAssertionGenerator(org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator) InferredObjectPropertyCharacteristicAxiomGenerator(org.semanticweb.owlapi.util.InferredObjectPropertyCharacteristicAxiomGenerator) InferredInverseObjectPropertiesAxiomGenerator(org.semanticweb.owlapi.util.InferredInverseObjectPropertiesAxiomGenerator) InferredAxiomGenerator(org.semanticweb.owlapi.util.InferredAxiomGenerator) ArrayList(java.util.ArrayList) InferredSubDataPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredSubDataPropertyAxiomGenerator) InferredEquivalentClassAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator) OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) InferredClassAssertionAxiomGenerator(org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) InferredSubObjectPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredSubObjectPropertyAxiomGenerator) InferredEquivalentObjectPropertyAxiomGenerator(org.semanticweb.owlapi.util.InferredEquivalentObjectPropertyAxiomGenerator) InferredOntologyGenerator(org.semanticweb.owlapi.util.InferredOntologyGenerator) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 2 with InferredOntologyGenerator

use of org.semanticweb.owlapi.util.InferredOntologyGenerator 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

OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)2 InferredOntologyGenerator (org.semanticweb.owlapi.util.InferredOntologyGenerator)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)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 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)1 InconsistentOntologyException (org.semanticweb.owlapi.reasoner.InconsistentOntologyException)1 OWLReasoner (org.semanticweb.owlapi.reasoner.OWLReasoner)1 InferredAxiomGenerator (org.semanticweb.owlapi.util.InferredAxiomGenerator)1 InferredClassAssertionAxiomGenerator (org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator)1 InferredDataPropertyCharacteristicAxiomGenerator (org.semanticweb.owlapi.util.InferredDataPropertyCharacteristicAxiomGenerator)1 InferredEquivalentClassAxiomGenerator (org.semanticweb.owlapi.util.InferredEquivalentClassAxiomGenerator)1 InferredEquivalentDataPropertiesAxiomGenerator (org.semanticweb.owlapi.util.InferredEquivalentDataPropertiesAxiomGenerator)1 InferredEquivalentObjectPropertyAxiomGenerator (org.semanticweb.owlapi.util.InferredEquivalentObjectPropertyAxiomGenerator)1 InferredInverseObjectPropertiesAxiomGenerator (org.semanticweb.owlapi.util.InferredInverseObjectPropertiesAxiomGenerator)1