/** * When you have finish use this Helper, you must call {dispose() and eventually getGroup().close()} * * @param ontology an already build ontology. * @return an helper * @since 2.6.3 */ @SuppressWarnings("resource") public static OWLHelper createLightHelper(final OWLOntology ontology) { return new OWLGenericTools(new OWLManagerGroup(ontology), ontology, true) { @Override public void dispose() { super.dispose(); try { getGroup().close(); } catch (final Exception exception) { throw new OpenError(exception); } } }; }
/** * @return The storage manager if you have call setOntologiesDirectory() before; else it throw a RuntimeException. * @since 2.5.1 */ @Override public synchronized OWLOntologyManager getPersistentManager() { if (null == _persistentManager) { _persistentManager = OWLManager.createConcurrentOWLOntologyManager(); if (!getOntologiesDirectory().isPresent()) { final String msg = "You should define a directory for stored ontologies before using stored ontologies."; final OWLException ex = new OWLException(msg); Log.error(getLogger(), msg, ex); throw ex; } try { _storageListener = new OWLIncrementalFlatFileStorageManagerListener(getOntologiesDirectory().get(), new File(getOntologiesDirectory().get().getPath() + File.separator + OWLHelper._delta), this); getPersistentManager().addOntologyChangeListener(_storageListener); } catch (final Exception e) { throw new OWLException(e); } } return _persistentManager; }
public OWLManagerGroup(final File ontologiesDirectory) { setOntologiesDirectory(ontologiesDirectory); }
@Override public void loadDirectory(final File directory) { loadDirectory(directory, getPersistentManager(), (m, f) -> { try { return Optional.of(m.loadOntologyFromOntologyDocument(f)); } catch (final Exception e) { _logger.log(Level.SEVERE, "Can't load ontology of file " + f, e); return Optional.empty(); } }); }
try (final OWLManagerGroup group = new OWLManagerGroup()) group.setOntologiesDirectory(new File("target")); group.getPersistentManager(); group.flushIncrementalStorage(); expected.add(OWL.propertyAssertion(Ind1, propB, OWL.constant(hardString))); try (final OWLManagerGroup group = new OWLManagerGroup()) group.setOntologiesDirectory(new File("target")); group.getPersistentManager(); expected.add(OWL.declaration(propB)); try (final OWLManagerGroup group = new OWLManagerGroup()) // Force the manager to read the file. group.setOntologiesDirectory(new File("target")); group.getPersistentManager();
@Test public void testRestrictionConjonction3() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntology ontology = group.getVolatileManager().loadOntologyFromOntologyDocument(new File("src/test/resources/test_data/restriction_conjonction.owl")); final OWLHelper owl = new OWLGenericTools(group, ontology, true); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isConsistent()); ontology.individualsInSignature().forEach(r::getTypes); ontology.classesInSignature().forEach(r::getInstances); } }
final OWLOntologyManager manager = _owlManagerGroup.getPersistentManager();
@Override public String ontology2filename(final OWLOntology ontology) { return ontology2filename(ontology.getOntologyID()); }
public OWLIncrementalFlatFileStorageManagerListener(final File directory, final File log, final OWLManagerGroup owlManagerGroup) throws OWLOntologyCreationException { _delta = log; _directory = directory; _owlManagerGroup = owlManagerGroup; _owlManagerGroup.loadDirectory(_directory); rebuild(); // Rebuild the ontology that still doesn't exists. sync(); // TODO : add a filter so after having sync/flush the ontologies, we can unload the ontologies we don't want to use ( just to free memory ). flush(); // We flush the log file into ontologies file on fix schedule to avoid to much problem with the log file. _logger.info("Starting incremental storage."); _future = _timer.scheduleAtFixedRate(_task, 0, _flushTimeInMinute, TimeUnit.MINUTES); }
try (final OWLManagerGroup group = new OWLManagerGroup()) group.setOntologiesDirectory(new File("target")); group.getPersistentManager(); group.flushIncrementalStorage(); expected.add(OWL.propertyAssertion(Ind1, propB, OWL.constant(hardString))); try (final OWLManagerGroup group = new OWLManagerGroup()) group.setOntologiesDirectory(new File("target")); group.getPersistentManager(); expected.add(OWL.declaration(propB)); try (final OWLManagerGroup group = new OWLManagerGroup()) // Force the manager to read the file. group.setOntologiesDirectory(new File("target")); group.getPersistentManager();
@Override public void loadDirectory(final File directory) { loadDirectory(directory, getPersistentManager(), (m, f) -> { try { return Optional.of(m.loadOntologyFromOntologyDocument(f)); } catch (final Exception e) { _logger.log(Level.SEVERE, "Can't load ontology of file " + f, e); return Optional.empty(); } }); }
@Test public void testRestrictionConjonction3() throws OWLOntologyCreationException { try (final OWLManagerGroup group = new OWLManagerGroup()) { final OWLOntology ontology = group.getVolatileManager().loadOntologyFromOntologyDocument(new File("src/test/resources/test_data/restriction_conjonction.owl")); final OWLHelper owl = new OWLGenericTools(group, ontology, true); final OWLReasoner r = owl.getReasoner(); assertTrue(r.isConsistent()); ontology.individualsInSignature().forEach(r::getTypes); ontology.classesInSignature().forEach(r::getInstances); } }
final OWLOntologyManager manager = _owlManagerGroup.getPersistentManager();
@Override public String ontology2filename(final OWLOntology ontology) { return ontology2filename(ontology.getOntologyID()); }
public OWLIncrementalFlatFileStorageManagerListener(final File directory, final File log, final OWLManagerGroup owlManagerGroup) throws OWLOntologyCreationException { _delta = log; _directory = directory; _owlManagerGroup = owlManagerGroup; _owlManagerGroup.loadDirectory(_directory); rebuild(); // Rebuild the ontology that still doesn't exists. sync(); // TODO : add a filter so after having sync/flush the ontologies, we can unload the ontologies we don't want to use ( just to free memory ). flush(); // We flush the log file into ontologies file on fix schedule to avoid to much problem with the log file. _logger.info("Starting incremental storage."); _future = _timer.scheduleAtFixedRate(_task, 0, _flushTimeInMinute, TimeUnit.MINUTES); }
/** * When you have finish use this Helper, you must call {dispose() and eventually getGroup().close()} * * @param ontology an already build ontology. * @return an helper * @since 2.6.3 */ @SuppressWarnings("resource") public static OWLHelper createLightHelper(final OWLOntology ontology) { return new OWLGenericTools(new OWLManagerGroup(ontology), ontology, true) { @Override public void dispose() { super.dispose(); try { getGroup().close(); } catch (final Exception exception) { throw new OpenError(exception); } } }; }
/** * @return The storage manager if you have call setOntologiesDirectory() before; else it throw a RuntimeException. * @since 2.5.1 */ @Override public synchronized OWLOntologyManager getPersistentManager() { if (null == _persistentManager) { _persistentManager = OWLManager.createConcurrentOWLOntologyManager(); if (!getOntologiesDirectory().isPresent()) { final String msg = "You should define a directory for stored ontologies before using stored ontologies."; final OWLException ex = new OWLException(msg); Log.error(getLogger(), msg, ex); throw ex; } try { _storageListener = new OWLIncrementalFlatFileStorageManagerListener(getOntologiesDirectory().get(), new File(getOntologiesDirectory().get().getPath() + File.separator + OWLHelper._delta), this); getPersistentManager().addOntologyChangeListener(_storageListener); } catch (final Exception e) { throw new OWLException(e); } } return _persistentManager; }
@Override public void loadDirectory(final File directory) { loadDirectory(directory, getPersistentManager(), (m, f) -> { try { return Optional.of(m.loadOntologyFromOntologyDocument(f)); } catch (final Exception e) { _logger.log(Level.SEVERE, "Can't load ontology of file " + f, e); return Optional.empty(); } }); }
public OWLManagerGroup(final File ontologiesDirectory) { setOntologiesDirectory(ontologiesDirectory); }
final OWLOntologyManager manager = _owlManagerGroup.getPersistentManager();