private void computeLowerBoundClassificationWithELK() { //Logger.getLogger("org.semanticweb.elk").setLevel(Level.ERROR);//this is to make elk less chatty: only errors Logger.getLogger("org.semanticweb.elk").setLevel(Level.OFF);//removed completely timeForELK = System.currentTimeMillis(); lReasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology); lReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); timeForELK = System.currentTimeMillis() - timeForELK; }
/** * Given a string of a reasoner name from user input, return the reasoner factory. If the user * input is not valid, throw IllegalArgumentExcepiton. * * @param line the command line to use * @param allowEMR boolean specifying if EMR can be returned * @return OWLReasonerFactory if successful */ public static OWLReasonerFactory getReasonerFactory(CommandLine line, boolean allowEMR) { // ELK is the default reasoner String reasonerName = getDefaultValue(line, "reasoner", "ELK").trim().toLowerCase(); logger.info("Reasoner: " + reasonerName); if (reasonerName.equals("structural")) { return new org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory(); } else if (reasonerName.equals("hermit")) { return new org.semanticweb.HermiT.ReasonerFactory(); } else if (reasonerName.equals("jfact")) { return new JFactFactory(); // Reason must change behavior with EMR, so not all commands can use it } else if (reasonerName.equals("emr") && allowEMR) { ElkReasonerFactory innerReasonerFactory = new org.semanticweb.elk.owlapi.ElkReasonerFactory(); return new ExpressionMaterializingReasonerFactory(innerReasonerFactory); } else if (reasonerName.equals("elk")) { return new org.semanticweb.elk.owlapi.ElkReasonerFactory(); } else { throw new IllegalArgumentException(String.format(invalidReasonerError, reasonerName)); } }
ConsoleProgressMonitor mon = new ConsoleProgressMonitor(); OWLReasonerConfiguration reasonerConf = new SimpleConfiguration(mon); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); samplesReasoner = reasonerFactory.createReasoner(samplesKb, reasonerConf); samplesReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
/** * Build and return a {@code OWLReasoner} instance for a particular ontology, * as configured. * @param config the configuration for the ontology. * @param ontology the ontology. * @return the configured {@code OWLReasoner} instance, or the HermiT Reasoner * if the configuration value is not recognised. */ public OWLReasoner buildReasoner(OntologyConfiguration config, OWLOntology ontology) { String cfgReasoner = config.getReasoner(); OWLReasoner reasoner; if (HERMIT_REASONER.equalsIgnoreCase(cfgReasoner)) { reasoner = new Reasoner(ontology); } else if (ELK_REASONER.equalsIgnoreCase(cfgReasoner)) { reasoner = new ElkReasonerFactory().createReasoner(ontology); } else { LOGGER.info("Reasoner {} not recognized - using HermiT", cfgReasoner); reasoner = new Reasoner(ontology); } return reasoner; }
lReasoner = new ElkReasonerFactory().createReasoner(lmodule_onto); tLreasoner = System.currentTimeMillis(); lReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); inferredAxioms.addAll(turnHierarchyIntoAxioms(lReasoner)); lReasoner.dispose(); lReasoner = new ElkReasonerFactory().createReasoner(manager .createOntology(inferredAxioms)); lReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
mergedReasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology); mergedReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); timeForELKMerged = System.currentTimeMillis() - timeForELKMerged;
/** * @param args * @throws OWLOntologyCreationException */ public static void main(String[] args) throws OWLOntologyCreationException { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); // Load your ontology. OWLOntology ont = man .loadOntologyFromOntologyDocument(new File(args[0])); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Precompute instances for each named class in the ontology reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); // List representative instances for each class. for (OWLClass clazz : ont.getClassesInSignature()) { for (Node<OWLNamedIndividual> individual : reasoner.getInstances( clazz, true)) { System.out.println(clazz + "(" + individual.getRepresentativeElement() + ")"); } } // Terminate the worker threads used by the reasoner. reasoner.dispose(); }
/** * @param args * @throws OWLOntologyCreationException */ public static void main(String[] args) throws OWLOntologyCreationException { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); // Load your ontology. OWLOntology ont = man .loadOntologyFromOntologyDocument(new File(args[0])); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Precompute instances for each named class in the ontology reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); // List representative instances for each class. for (OWLClass clazz : ont.getClassesInSignature()) { for (Node<OWLNamedIndividual> individual : reasoner.getInstances( clazz, true)) { System.out.println(clazz + "(" + individual.getRepresentativeElement() + ")"); } } // Terminate the worker threads used by the reasoner. reasoner.dispose(); }
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
public QueryingWithNamedClasses() throws OWLOntologyCreationException { // Traditional setup with the OWL-API manager = OWLManager.createOWLOntologyManager(); IRI ontologyIri = IRI.create(EL_ONTOLOGY); ontology = manager.loadOntologyFromOntologyDocument(ontologyIri); System.out.println("Loaded ontology: " + ontology.getOntologyID()); // But we use the Elk reasoner (add it to the classpath) reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(ontology); // IMPORTANT: Precompute the inferences beforehand, otherwise no results // will be returned reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Ontologies are not easy to query with the full name of concept, so we // keep only the interesting bit ( = shortform) shortFormProvider = new SimpleShortFormProvider(); Set<OWLOntology> importsClosure = ontology.getImportsClosure(); mapper = new BidirectionalShortFormProviderAdapter(manager, importsClosure, shortFormProvider); }
public QueryingWithNamedClasses() throws OWLOntologyCreationException { // Traditional setup with the OWL-API manager = OWLManager.createOWLOntologyManager(); IRI ontologyIri = IRI.create(EL_ONTOLOGY); ontology = manager.loadOntologyFromOntologyDocument(ontologyIri); System.out.println("Loaded ontology: " + ontology.getOntologyID()); // But we use the Elk reasoner (add it to the classpath) reasonerFactory = new ElkReasonerFactory(); reasoner = reasonerFactory.createReasoner(ontology); // IMPORTANT: Precompute the inferences beforehand, otherwise no results // will be returned reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Ontologies are not easy to query with the full name of concept, so we // keep only the interesting bit ( = shortform) shortFormProvider = new SimpleShortFormProvider(); Set<OWLOntology> importsClosure = ontology.getImportsClosure(); mapper = new BidirectionalShortFormProviderAdapter(manager, importsClosure, shortFormProvider); }
break; case ELK: reasonerFactory = new ElkReasonerFactory(); break; case HERMIT:
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); mpKBReasoner = reasonerFactory.createReasoner(mpKB, reasonerConf); mpKBReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
public static void main(String[] args) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Load your ontology OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology")); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Classify the ontology. reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); OWLDataFactory factory = manager.getOWLDataFactory(); OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState")); OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState"))); OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure"))); // Remove an existing axiom, add a new axiom manager.addAxiom(ont, added); manager.removeAxiom(ont, removed); // This is a buffering reasoner, so you need to flush the changes reasoner.flush(); // Re-classify the ontology, the changes should be accommodated // incrementally (i.e. without re-inferring all subclass relationships) // You should be able to see it from the log output reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Terminate the worker threads used by the reasoner. reasoner.dispose(); }
public static void main(String[] args) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Load your ontology OWLOntology ont = manager.loadOntologyFromOntologyDocument(new File("path-to-ontology")); // Create an ELK reasoner. OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont); // Classify the ontology. reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); OWLDataFactory factory = manager.getOWLDataFactory(); OWLClass subClass = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#AbsoluteShapeState")); OWLAxiom removed = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#ShapeState"))); OWLAxiom added = factory.getOWLSubClassOfAxiom(subClass, factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/galen#GeneralisedStructure"))); // Remove an existing axiom, add a new axiom manager.addAxiom(ont, added); manager.removeAxiom(ont, removed); // This is a buffering reasoner, so you need to flush the changes reasoner.flush(); // Re-classify the ontology, the changes should be accommodated // incrementally (i.e. without re-inferring all subclass relationships) // You should be able to see it from the log output reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); // Terminate the worker threads used by the reasoner. reasoner.dispose(); }
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont);