@Override protected OpenlletCmdApp create() { return new OpenlletClassify(); } }, "--persist", fileIRI("test/data/misc/family.owl"));
/** * Stores the _current state of the incremental classifier to a file (the file name is determined automatically based on ontology's IRI). * * @param incrementalClassifier the incremental classifier to be stored * @param ontology the ontology */ private void persistIncrementalClassifier(final IncrementalClassifier incrementalClassifier, final OWLOntology ontology) { final File saveFile = determineSaveFile(ontology); try { verbose("Saving the state of the classifier to " + saveFile); final FileOutputStream outputStream = new FileOutputStream(saveFile); IncrementalClassifierPersistence.save(incrementalClassifier, outputStream); } catch (final IOException e) { _logger.log(Level.WARNING, "Unable to persist the current classifier state.", e); } }
/** * Performs classification using the incremental classifier (and persisted _data) */ private void runIncrementalClassify() { final String loaderName = _options.getOption("loader").getValueAsString(); if (!"OWLAPI".equals(loaderName)) _logger.log(Level.WARNING, "Ignoring -l " + loaderName + " option. When using --persist the only allowed loader is OWLAPI"); final OWLAPILoader loader = (OWLAPILoader) getLoader("OWLAPI"); loader.parse(getInputFiles()); final OWLOntology ontology = loader.getOntology(); final IncrementalClassifier incrementalClassifier = createIncrementalClassifier(ontology); if (!incrementalClassifier.isClassified()) { startTask("consistency check"); final boolean isConsistent = incrementalClassifier.isConsistent(); finishTask("consistency check"); if (!isConsistent) throw new OpenlletCmdException("Ontology is inconsistent, run \"openllet explain\" to get the reason"); startTask("classification"); incrementalClassifier.classify(); finishTask("classification"); } final TaxonomyPrinter<OWLClass> printer = new OWLClassTreePrinter(); printer.print(incrementalClassifier.getTaxonomy()); if (!_currentStateSaved) persistIncrementalClassifier(incrementalClassifier, ontology); }
@Override public OpenlletCmdOptions getOptions() { final OpenlletCmdOptions options = getGlobalOptions(); final OpenlletCmdOption option = new OpenlletCmdOption("persist"); option.setShortOption("p"); option.setDescription("Enable persistence of classification results. The classifier will save its internal state in a file, and will reuse it the next time this ontology is loaded, therefore saving classification time. This option can only be used with OWLAPI _loader."); option.setIsMandatory(false); option.setArg(NONE); options.add(option); options.add(getLoaderOption()); options.add(getIgnoreImportsOption()); options.add(getInputFormatOption()); return options; }
/** * Performs classification using the non-incremental (classic) classifier */ private void runClassicClassify() { final KnowledgeBase kb = getKB(); startTask("consistency check"); final boolean isConsistent = kb.isConsistent(); finishTask("consistency check"); if (!isConsistent) throw new OpenlletCmdException("Ontology is inconsistent, run \"openllet explain\" to get the reason"); startTask("classification"); kb.classify(); finishTask("classification"); final TaxonomyPrinter<ATermAppl> printer = new ClassTreePrinter(); printer.print(kb.getTaxonomy()); }
/** * Creates incremental classifier by either creating it from scratch or by reading its state from file (if there exists such a state) * * @param ontology the ontology (the _current state of it) * @return the incremental classifier */ private IncrementalClassifier createIncrementalClassifier(final OWLOntology ontology) { final File saveFile = determineSaveFile(ontology); IncrementalClassifier result = null; // first try to restore the classifier from the file (if one exists) if (saveFile.exists()) result = loadIncrementalClassifier(ontology, saveFile); // if it was not possible to restore the classifier, create one from scratch if (result == null) result = new IncrementalClassifier(ontology); result.getReasoner().getKB().setTaxonomyBuilderProgressMonitor(OpenlletOptions.USE_CLASSIFICATION_MONITOR.create()); return result; }
@Override protected OpenlletCmdApp create() { return new OpenlletClassify(); } }, fileIRI("test/data/misc/family.owl"));
@Override protected OpenlletCmdApp create() { return new OpenlletClassify(); } }, "--persist", fileIRI("test/data/misc/family.owl"));