org.semanticweb.owlapi.model.MissingImportHandlingStrategy Java Examples

The following examples show how to use org.semanticweb.owlapi.model.MissingImportHandlingStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private OWLOntology loadOwlOntology() throws OWLOntologyCreationException {
  FileDocumentSource fileDocumentSource = new FileDocumentSource(ontologyFile);
  // use silent import handling strategy to enable ontology loading without internet access
  // see: https://github.com/molgenis/molgenis/issues/5301
  OWLOntologyLoaderConfiguration owlOntologyLoaderConfiguration =
      new OWLOntologyLoaderConfiguration()
          .setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
  return manager.loadOntologyFromOntologyDocument(
      fileDocumentSource, owlOntologyLoaderConfiguration);
}
 
Example #2
Source File: IRIConverter.java    From OWL2VOWL with MIT License 4 votes vote down vote up
@Override
protected void loadOntology() throws OWLOntologyCreationException {
	logger.info("Converting IRIs...");
	
	logger.info("Loading ontologies ... [" + mainOntology + ",  " + depdencyOntologies + "]");
	this.setOntologyHasMissingImports(false);
	manager = OWLManager.createOWLOntologyManager();

	if (!depdencyOntologies.isEmpty()) {
		for (IRI externalIRI : depdencyOntologies) {
			manager.loadOntology(externalIRI);
		}
		logger.info("External ontologies loaded!");
	}
	

	try {
		this.addLoadingInfo("* Parsing ontology with OWL API ");
		this.setCurrentlyLoadingFlag("* Parsing ontology with OWL API ",true);
		missingListener=new OWLAPI_MissingImportsListener(this);
		manager.addMissingImportListener(missingListener);
		manager.getOntologyConfigurator().setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
		manager.getOntologyConfigurator().setFollowRedirects(true);
		manager.getOntologyConfigurator().setConnectionTimeout(100000);

		manager.getOntologyConfigurator().setAcceptingHTTPCompression(true);
		manager.getOntologyConfigurator().withRepairIllegalPunnings(false);
		
		ontology = manager.loadOntology(mainOntology);
		
		
		this.addLoadingInfoToParentLine("... done " );
		this.setCurrentlyLoadingFlag(false);
		if (this.ontologyHasMissingImports()==true) {
			this.addLoadingInfoToLine("* Parsing ontology with OWL API ","<span style='color:yellow;'>(with warnings)</span>" );
		}
	
	} catch (Exception e ) {
		this.addLoadingInfoToLine("* Parsing ontology with OWL API ","... <span style='color:red;'>failed</span>" );
		this.setCurrentlyLoadingFlag(false);
		this.addLoadingInfo("\n <span style='color:red;'>Loading process failed:</span> \n"+msgForWebVOWL(e.getMessage()));
		logger.info(this.getLoadingInfoString());
	}
	
	loadedOntologyPath = mainOntology.toString();

	String logOntoName;
	if (!ontology.isAnonymous()) {
		logOntoName = ontology.getOntologyID().getOntologyIRI().get().toString();
	} else {
		logOntoName = mainOntology.toString();
		logger.info("Ontology IRI is anonymous. Use loaded URI/IRI instead.");
	}
	logger.info("Ontologies loaded! Main Ontology: " + logOntoName);
}
 
Example #3
Source File: InputStreamConverter.java    From OWL2VOWL with MIT License 4 votes vote down vote up
@Override
protected void loadOntology() throws OWLOntologyCreationException {
	logger.info("Converting input streams...");
	this.setOntologyHasMissingImports(false);
	manager = OWLManager.createOWLOntologyManager();

	for (InputStream depdencyOntology : depdencyOntologies) {
		manager.loadOntologyFromOntologyDocument(depdencyOntology);
	}
	String CharEncoding="UTF-8";
	String copiedOntologyContent="";
	try {
		copiedOntologyContent = IOUtils.toString(mainOntology, CharEncoding);
	} catch (IOException e1) {
		e1.printStackTrace();
		
	}
	// need a workaround with copied string since the input stream is flushed on reading ... 
	try {
		this.addLoadingInfo("* Parsing ontology with OWL API ");
		this.setCurrentlyLoadingFlag("* Parsing ontology with OWL API ",true);
		InputStream copyOfInputBuffer = new ByteArrayInputStream(copiedOntologyContent.getBytes(CharEncoding));
		missingListener=new OWLAPI_MissingImportsListener(this);
		manager.addMissingImportListener(missingListener);
		manager.getOntologyConfigurator().setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT);
		ontology = manager.loadOntologyFromOntologyDocument(copyOfInputBuffer);
		this.addLoadingInfoToParentLine("... done " );
		this.setCurrentlyLoadingFlag(false);
		
		if (this.ontologyHasMissingImports()==true) {
			this.addLoadingInfoToLine("* Parsing ontology with OWL API ","<span style='color:yellow;'>(with warnings)</span>" );
		}
		copyOfInputBuffer=null;
	} catch (Exception e ) {
		this.setCurrentlyLoadingFlag(false);
		this.addLoadingInfoToLine("* Parsing ontology with OWL API ","... <span style='color:red;'>failed</span>" );
		this.addLoadingInfo("\n <span style='color:red;'>Loading process failed:</span> \n"+msgForWebVOWL(e.getMessage()));
	}
	
	loadedOntologyPath = "file upload";
	copiedOntologyContent="";
	String logOntoName;
	if (!ontology.isAnonymous()) {
		logOntoName = ontology.getOntologyID().getOntologyIRI().get().toString();
	} else {
		logOntoName = "Anonymous";
		logger.info("Ontology IRI is anonymous. Use loaded URI/IRI instead.");
	}
	logger.info("Ontologies loaded! Main Ontology: " + logOntoName);
}