Search in sources :

Example 1 with OWLReasoner

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

the class DefaultGWASOWLPublisher method publishGWASDataInferredView.

public OWLReasoner publishGWASDataInferredView(OWLOntology ontology) throws OWLConversionException {
    getLog().debug("Loading any missing imports...");
    StringBuilder loadedOntologies = new StringBuilder();
    int n = 1;
    for (OWLOntology o : ontology.getOWLOntologyManager().getOntologies()) {
        loadedOntologies.append("\t").append(n++).append(") ").append(o.getOntologyID().getOntologyIRI()).append("\n");
    }
    getLog().debug("Imports collected: the following ontologies have been loaded in this session:\n" + loadedOntologies.toString());
    getLog().info("Classifying ontology from " + ontology.getOntologyID().getOntologyIRI());
    getLog().debug("Creating reasoner... ");
    OWLReasonerFactory factory = new Reasoner.ReasonerFactory();
    ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
    OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
    OWLReasoner reasoner = factory.createReasoner(ontology, config);
    getLog().debug("Precomputing inferences...");
    reasoner.precomputeInferences();
    getLog().debug("Checking ontology consistency...");
    reasoner.isConsistent();
    getLog().debug("Checking for unsatisfiable classes...");
    if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
        throw new OWLConversionException("Once classified, unsatisfiable classes were detected");
    } else {
        getLog().info("Reasoning complete! ");
        return reasoner;
    }
}
Also used : OWLConversionException(uk.ac.ebi.spot.goci.exception.OWLConversionException) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory) OWLReasonerConfiguration(org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SimpleConfiguration(org.semanticweb.owlapi.reasoner.SimpleConfiguration) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) ConsoleProgressMonitor(org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory)

Example 2 with OWLReasoner

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

the class HermitReasoningService method getReasoner.

@Override
protected OWLReasoner getReasoner(OWLOntology ontology) {
    log.debug("Creating HermiT reasoner: {}", ontology);
    Configuration config = new Configuration();
    // This must be true!
    config.ignoreUnsupportedDatatypes = true;
    // This must be true!
    config.throwInconsistentOntologyException = true;
    //config.monitor = new Debugger(null, false);
    log.debug("Configuration: {}, debugger {}", config, config.monitor);
    ReasonerFactory risfactory = new ReasonerFactory();
    log.debug("factory: {}", risfactory);
    OWLReasoner reasoner = null;
    reasoner = risfactory.createReasoner(ontology, config);
    log.debug("Reasoner : {}", reasoner);
    if (reasoner == null) {
        log.error("Cannot create the reasner!!");
        throw new IllegalArgumentException("Cannot create the reasoner");
    }
    return reasoner;
}
Also used : Configuration(org.semanticweb.HermiT.Configuration) ReasonerFactory(org.semanticweb.HermiT.Reasoner.ReasonerFactory) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner)

Example 3 with OWLReasoner

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

the class HermitReasoningServiceTest method testInstantiation.

@Test
public void testInstantiation() {
    log.info("Testing the innstantiation of an HermitReasoningService");
    OWLOntology foaf = TestData.manager.getOntology(IRI.create(TestData.FOAF_NS));
    // Here we want to be sure that the getReasoner() method creates an
    // instance correctly
    HermitReasoningService akindofhermit = new HermitReasoningService() {

        protected OWLReasoner getReasoner(OWLOntology ontology) {
            try {
                OWLReasoner reasoner = super.getReasoner(ontology);
                assertTrue(reasoner != null);
                return reasoner;
            } catch (Throwable t) {
                log.error("Some prolem occurred while instantiating the HermitReasoningService. Message was: {}", t.getLocalizedMessage());
                // We force tests to stop here
                assertTrue(false);
                return null;
            }
        }
    };
    long startHere = System.currentTimeMillis();
    // This is possible only because the subclass is in this scope...
    akindofhermit.getReasoner(foaf);
    long endHere = System.currentTimeMillis();
    log.info("Instantiating an Hermit reasoner lasts {} milliseconds", (endHere - startHere));
}
Also used : OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) Test(org.junit.Test)

Example 4 with OWLReasoner

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

the class IRITreeBuilder method buildIRITree.

//    OntologyLoader ontologyLoader;
//
//    @Autowired
//    public IRITreeBuilder(OntologyLoader ontologyLoader){
//        this.ontologyLoader = ontologyLoader;
//    }
public IRITree buildIRITree(URL efoLocation) throws URISyntaxException, OWLOntologyCreationException {
    // load efo
    getLog().info("Loading efo...");
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology efo = manager.loadOntology(IRI.create(efoLocation));
    owlNothingIRI = manager.getOWLDataFactory().getOWLNothing().getIRI().toString();
    // create a reasoner over efo
    getLog().info("Reasoning over efo...");
    OWLReasonerFactory factory = new Reasoner.ReasonerFactory();
    ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
    OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
    OWLReasoner reasoner = factory.createReasoner(efo, config);
    getLog().info("Precomputing inferences...");
    reasoner.precomputeInferences();
    getLog().info("Checking ontology consistency...");
    reasoner.isConsistent();
    // get 'top' class
    OWLClass topClass = reasoner.getTopClassNode().getRepresentativeElement();
    getLog().info("Reasoner 'top class' element is " + topClass.getIRI());
    IRITree tree = new IRITree();
    // do one level deep manually - should only be experimental factor
    IRINode rootNode = null;
    OWLClass efClass = null;
    NodeSet<OWLClass> subclasses = reasoner.getSubClasses(topClass, true);
    for (Node<OWLClass> node : subclasses) {
        OWLClass cls = node.getRepresentativeElement();
        getLog().debug("Next child of " + topClass + " is " + cls);
        if (cls.getIRI().toString().equals(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI)) {
            efClass = cls;
            rootNode = new IRINode(cls.getIRI(), getClassLabel(efo, cls));
        }
    }
    if (rootNode != null) {
        getLog().info("Building tree... walking ontology from " + rootNode.getLabel() + " down...");
        tree.setRootNode(rootNode);
        recurse(reasoner, efo, efClass, rootNode);
        getLog().info("...Tree build complete!");
    } else {
        throw new RuntimeException("Could not find Experimental Factor as a child of OWL:Thing");
    }
    return tree;
}
Also used : OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) ConsoleProgressMonitor(org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor) OWLReasonerConfiguration(org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SimpleConfiguration(org.semanticweb.owlapi.reasoner.SimpleConfiguration) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLReasonerFactory(org.semanticweb.owlapi.reasoner.OWLReasonerFactory)

Example 5 with OWLReasoner

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

the class SparqlPussycatSession method getRelatedTraits.

@Override
public Set<URI> getRelatedTraits(String traitName) {
    // get OWLClasses by name
    Collection<OWLClass> traitClasses = getOntologyService().getOWLClassesByLabel(traitName);
    Set<URI> results = new HashSet<URI>();
    // check reasoner
    OWLReasoner reasoner = getOntologyService().getOntologyLoader().getOWLReasoner();
    for (OWLClass traitClass : traitClasses) {
        results.add(traitClass.getIRI().toURI());
        Set<OWLClass> subclasses = reasoner.getSubClasses(traitClass, false).getFlattened();
        for (OWLClass subclass : subclasses) {
            results.add(subclass.getIRI().toURI());
        }
    }
    return results;
}
Also used : OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLReasoner(org.semanticweb.owlapi.reasoner.OWLReasoner) URI(java.net.URI) 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