private Optional<OWLOntology> loadOntologyFromFile() throws OWLOntologyCreationException { /** * File */ OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); if (options.mappingOntologyOptions.ontologyFile.isPresent()) { owlOntology = Optional.of(manager.loadOntologyFromOntologyDocument(options.mappingOntologyOptions.ontologyFile.get())); } /** * URL */ try { Optional<URL> optionalURL = options.mappingOntologyOptions.ontologyURL; if (optionalURL.isPresent()) { owlOntology = Optional.of( manager.loadOntologyFromOntologyDocument( optionalURL.get().openStream())); } } catch (MalformedURLException e ) { throw new OWLOntologyCreationException("Invalid URI: " + e.getMessage()); } catch (IOException e) { throw new OWLOntologyCreationException(e.getMessage()); } return owlOntology; }
private List<OWLOntologyChange> reloadOntologyAndGetPatch() throws OWLOntologyCreationException { ListenableFuture<List<OWLOntologyChange>> future = executorService .submit(() -> { try { return performReloadAndGetPatch(); } finally { dlg.setVisible(false); } }); dlg.setVisible(true); try { return future.get(); } catch (InterruptedException e) { throw new OWLOntologyCreationException(e); } catch (ExecutionException e) { if(e.getCause() instanceof OWLOntologyCreationException) { throw (OWLOntologyCreationException) e.getCause(); } else { logger.error("An error occurred whilst reloading the ontology: {}", e.getMessage(), e); throw new OWLOntologyCreationException(e); } } }
private List<OWLOntologyChange> reloadOntologyAndGetPatch() throws OWLOntologyCreationException { ListenableFuture<List<OWLOntologyChange>> future = executorService .submit(() -> { try { return performReloadAndGetPatch(); } finally { dlg.setVisible(false); } }); dlg.setVisible(true); try { return future.get(); } catch (InterruptedException e) { throw new OWLOntologyCreationException(e); } catch (ExecutionException e) { if(e.getCause() instanceof OWLOntologyCreationException) { throw (OWLOntologyCreationException) e.getCause(); } else { logger.error("An error occurred whilst reloading the ontology: {}", e.getMessage(), e); throw new OWLOntologyCreationException(e); } } }
/** * Creates an OBOFormatParser object to parse a file and then converts it * using the convert method. * * @param oboFile the obo file * @return ontology * @throws OWLOntologyCreationException the oWL ontology creation exception */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try { OBOFormatParser p = new OBOFormatParser(); return convert(p.parse(oboFile)); } catch (IOException ex) { throw new OWLOntologyCreationException( "Error Occured while parsing OBO '" + oboFile + '\'', ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException( "Syntax error occured while parsing OBO '" + oboFile + '\'', ex); } }
/** * Creates an OBOFormatParser object to parse a file and then converts it * using the convert method. * * @param oboFile the obo file * @return ontology * @throws OWLOntologyCreationException the oWL ontology creation exception */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try { OBOFormatParser p = new OBOFormatParser(); return convert(p.parse(oboFile)); } catch (IOException ex) { throw new OWLOntologyCreationException( "Error Occured while parsing OBO '" + oboFile + '\'', ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException( "Syntax error occured while parsing OBO '" + oboFile + '\'', ex); } }
/** * Creates an OBOFormatParser object to parse a file and then converts it using * the convert method * * @param oboFile * @return ontology * @throws OWLOntologyCreationException */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(oboFile); return convert(obodoc); }catch(IOException ex){ throw new OWLOntologyCreationException("Error Occured while parsing OBO '" + oboFile + "'", ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException("Syntax error occured while parsing OBO '" + oboFile + "'", ex); } }
/** * Creates an OBOFormatParser object to parse a file and then converts it * using the convert method. * * @param oboFile the obo file * @return ontology * @throws OWLOntologyCreationException the oWL ontology creation exception */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try { OBOFormatParser p = new OBOFormatParser(); return convert(p.parse(oboFile)); } catch (IOException ex) { throw new OWLOntologyCreationException( "Error Occured while parsing OBO '" + oboFile + '\'', ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException( "Syntax error occured while parsing OBO '" + oboFile + '\'', ex); } }
/** * Creates an OBOFormatParser object to parse a file and then converts it * using the convert method. * * @param oboFile the obo file * @return ontology * @throws OWLOntologyCreationException the oWL ontology creation exception */ public OWLOntology convert(String oboFile) throws OWLOntologyCreationException { try { OBOFormatParser p = new OBOFormatParser(); return convert(p.parse(oboFile)); } catch (IOException ex) { throw new OWLOntologyCreationException( "Error Occured while parsing OBO '" + oboFile + '\'', ex); } catch (OBOFormatParserException ex) { throw new OWLOntologyCreationException( "Syntax error occured while parsing OBO '" + oboFile + '\'', ex); } }
/*** * @param manager The ontology manager to use * @param ontology A string representing the ontology to load. This can be an URI or a file path * @return The loaded ontology * @throws OWLOntologyCreationException */ public static OWLOntology loadOntology(OWLOntologyManager manager, String ontology) throws OWLOntologyCreationException { logger.info(String.format("Loading ontology with owlapi: %s", ontology)); String origThreadName = Thread.currentThread().getName(); Thread.currentThread().setName("read - " + ontology); OWLOntology ont; if (validator.isValid(ontology)) { ont = manager.loadOntology(IRI.create(ontology)); } else if (new File(ontology).exists()){ ont = manager.loadOntologyFromOntologyDocument(new File(ontology)); } else { try { ont = manager.loadOntologyFromOntologyDocument(Resources.getResource(ontology).openStream()); } catch (Exception e) { throw new OWLOntologyCreationException("Failed to find ontology: " + ontology); } } logger.info(String.format("Finished loading ontology with owlapi: %s", ontology)); Thread.currentThread().setName(origThreadName); return ont; }
public List<OWLAxiom> executeGraph(String query) throws OWLException { if (SPARQLQueryUtility.isConstructQuery(query) || SPARQLQueryUtility.isDescribeQuery(query)) { try { GraphResultSet resultSet = (GraphResultSet) st.execute(query); return createOWLIndividualAxioms(resultSet); } catch (Exception e) { throw new OWLOntologyCreationException(e); }} else { throw new RuntimeException("Query is not graph query (CONSTRUCT / DESCRIBE)."); } }
public List<OWLAxiom> executeGraph(String query) throws OWLException { if (SPARQLQueryUtility.isConstructQuery(query) || SPARQLQueryUtility.isDescribeQuery(query)) { try { GraphResultSet resultSet = (GraphResultSet) st.execute(query); return createOWLIndividualAxioms(resultSet); } catch (Exception e) { throw new OWLOntologyCreationException(e); }} else { throw new RuntimeException("Query is not graph query (CONSTRUCT / DESCRIBE)."); } }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
/** * Clone into another ontology with the same axioms and same manager. NB : In a future version this function may return an ontology that share axiom with * previous for memory saving. * * @param version that will have the new ontology. * @return a new ontology with the axioms of the given one. * @throws OWLOntologyCreationException if we can't create the ontology. * @since 2.5.1 */ default public OWLHelper derivate(final double version) throws OWLOntologyCreationException { final Optional<OWLHelper> result = look(this.getOntology().getOntologyID().getOntologyIRI().get(), version); if (!result.isPresent()) throw new OWLOntologyCreationException("Can't derivate to version " + version); if (result.get().getOntology().getAxiomCount() != 0) getLogger().warning(() -> "The ontology you try to derivate from " + getVersion() + " to version " + version + " already exist."); result.get().addAxioms(getOntology().axioms()); return result.get(); }
public OWLGenericTools(final OWLGroup group, final OWLOntologyID ontologyID, final boolean isVolatile) throws OWLOntologyCreationException throw new OWLOntologyCreationException("Illegal character ' ' in name on [" + ontologyID.getOntologyIRI() + "]"); else if (ontologyID.getVersionIRI() != null && ontologyID.getVersionIRI().toString().indexOf(' ') != -1) throw new OWLOntologyCreationException("Illegal character ' ' in version on [" + ontologyID.getVersionIRI() + "]");
/** * Reloads the specified ontology. Either the ontology is successfully reloaded or it is left intact. * @throws OWLOntologyCreationException */ public void reload() throws OWLOntologyCreationException { logger.info(LogBanner.start("Reloading ontology")); logger.info("Reloading ontology: {}", ontologyToReload.getOntologyID()); try { // Load the ontology as a fresh ontology List<OWLOntologyChange> changes = reloadOntologyAndGetPatch(); logger.info("Applying {} change(s) to patch ontology to reloaded ontology", changes.size()); if (!changes.isEmpty()) { ontologyToReload.getOWLOntologyManager().applyChanges(changes); if(modelManager instanceof IOListenerManager) { ((IOListenerManager) modelManager).fireAfterLoadEvent(ontologyToReload.getOntologyID(), ontologyToReload.getOWLOntologyManager().getOntologyDocumentIRI(ontologyToReload).toURI()); } } } catch (Throwable t) { if (t instanceof OWLOntologyCreationException) { throw (OWLOntologyCreationException) t; } else { throw new OWLOntologyCreationException(t); } } }
/** * Reloads the specified ontology. Either the ontology is successfully reloaded or it is left intact. * @throws OWLOntologyCreationException */ public void reload() throws OWLOntologyCreationException { logger.info(LogBanner.start("Reloading ontology")); logger.info("Reloading ontology: {}", ontologyToReload.getOntologyID()); try { // Load the ontology as a fresh ontology List<OWLOntologyChange> changes = reloadOntologyAndGetPatch(); logger.info("Applying {} change(s) to patch ontology to reloaded ontology", changes.size()); if (!changes.isEmpty()) { ontologyToReload.getOWLOntologyManager().applyChanges(changes); if(modelManager instanceof IOListenerManager) { ((IOListenerManager) modelManager).fireAfterLoadEvent(ontologyToReload.getOntologyID(), ontologyToReload.getOWLOntologyManager().getOntologyDocumentIRI(ontologyToReload).toURI()); } } } catch (Throwable t) { if (t instanceof OWLOntologyCreationException) { throw (OWLOntologyCreationException) t; } else { throw new OWLOntologyCreationException(t); } } }
public OWLOntology reload(OWLOntology ont) throws OWLOntologyCreationException { IRI ontologyDocumentIRI = IRI.create(getOntologyPhysicalURI(ont)); manager.removeOntology(ont); boolean wasTheActiveOntology = false; if (ont.equals(activeOntology)) { wasTheActiveOntology = true; activeOntology = null; } dirtyOntologies.remove(ont); try { ont = manager.loadOntologyFromOntologyDocument(ontologyDocumentIRI); } catch (Throwable t) { ((OWLOntologyManagerImpl) manager).ontologyCreated(ont); // put it back - a hack but it works manager.setOntologyDocumentIRI(ont, ontologyDocumentIRI); throw (t instanceof OWLOntologyCreationException) ? (OWLOntologyCreationException) t : new OWLOntologyCreationException(t); } if (wasTheActiveOntology) { activeOntology = ont; } rebuildActiveOntologiesCache(); refreshRenderer(); fireEvent(EventType.ONTOLOGY_RELOADED); return ont; }
public OWLOntology reload(OWLOntology ont) throws OWLOntologyCreationException { IRI ontologyDocumentIRI = IRI.create(getOntologyPhysicalURI(ont)); manager.removeOntology(ont); boolean wasTheActiveOntology = false; if (ont.equals(activeOntology)) { wasTheActiveOntology = true; activeOntology = null; } dirtyOntologies.remove(ont.getOntologyID()); try { ont = manager.loadOntologyFromOntologyDocument(ontologyDocumentIRI); } catch (Throwable t) { ((OWLOntologyManagerImpl) manager).ontologyCreated(ont); // put it back - a hack but it works manager.setOntologyDocumentIRI(ont, ontologyDocumentIRI); throw (t instanceof OWLOntologyCreationException) ? (OWLOntologyCreationException) t : new OWLOntologyCreationException(t); } if (wasTheActiveOntology) { activeOntology = ont; } rebuildActiveOntologiesCache(); refreshRenderer(); fireEvent(EventType.ONTOLOGY_RELOADED); return ont; }
public static void loadImports(final OWLOntologyManager manager, final OwlApiCase t, final SerializationFormat format) throws OWLOntologyCreationException { for (final IRI iri : t.getImportedOntologies()) { if (!manager.contains(iri)) { final String str = t.getImportedOntology(iri, format); if (str == null) { final String msg = format("Imported ontology (%s) not provided in " + format + " syntax for testcase (%s)", iri, t.getIdentifier()); _logger.warning(msg); throw new OWLOntologyCreationException(msg); } else { final StringDocumentSource source = new StringDocumentSource(str, iri); try { manager.loadOntologyFromOntologyDocument(source); } catch (final OWLOntologyCreationException e) { _logger.warning(format("Failed to parse imported ontology for testcase (%s)", t.getIdentifier())); throw e; } } } } }