-
Notifications
You must be signed in to change notification settings - Fork 79
Add --input-format option
#1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0f14029
30d0717
dad21e9
2265558
1abf5b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,12 +317,27 @@ public OWLOntology loadOntology(String ontologyPath) throws IOException { | |
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(String ontologyPath, boolean useCatalog) throws IOException { | ||
| return loadOntology(ontologyPath, useCatalog, null); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from a String path, optionally using a catalog file if available and with an | ||
| * explicit input format. | ||
| * | ||
| * @param ontologyPath the path to the ontology file | ||
| * @param useCatalog if true, a catalog file will be used if one is found | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(String ontologyPath, boolean useCatalog, String inputFormat) | ||
| throws IOException { | ||
| File ontologyFile = new File(ontologyPath); | ||
| File catalogFile = null; | ||
| if (useCatalog) { | ||
| catalogFile = guessCatalogFile(ontologyFile); | ||
| } | ||
| return loadOntology(ontologyFile, catalogFile); | ||
| return loadOntology(ontologyFile, catalogFile, inputFormat); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -339,6 +354,22 @@ public OWLOntology loadOntology(String ontologyPath, String catalogPath) throws | |
| return loadOntology(ontologyFile, catalogFile); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from a String path, with optional catalog file and explicit document format. | ||
| * | ||
| * @param ontologyPath the path to the ontology file | ||
| * @param catalogPath the path to the catalog file or null | ||
| * @param inputFormat the expected input format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(String ontologyPath, String catalogPath, String inputFormat) | ||
| throws IOException { | ||
| File ontologyFile = new File(ontologyPath); | ||
| File catalogFile = catalogPath != null ? new File(catalogPath) : null; | ||
| return loadOntology(ontologyFile, catalogFile, inputFormat); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from a File, using a catalog file if available. | ||
| * | ||
|
|
@@ -364,11 +395,26 @@ public OWLOntology loadOntology(File ontologyFile) throws IOException { | |
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(File ontologyFile, boolean useCatalog) throws IOException { | ||
| return loadOntology(ontologyFile, useCatalog, null); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from a File, with option to use a catalog file and to expect an explicit | ||
| * format. | ||
| * | ||
| * @param ontologyFile the ontology file to load | ||
| * @param useCatalog when true, a catalog file will be used if one is found | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(File ontologyFile, boolean useCatalog, String inputFormat) | ||
| throws IOException { | ||
| File catalogFile = null; | ||
| if (useCatalog) { | ||
| catalogFile = guessCatalogFile(ontologyFile); | ||
| } | ||
| return loadOntology(ontologyFile, catalogFile); | ||
| return loadOntology(ontologyFile, catalogFile, inputFormat); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -380,6 +426,20 @@ public OWLOntology loadOntology(File ontologyFile, boolean useCatalog) throws IO | |
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(File ontologyFile, File catalogFile) throws IOException { | ||
| return loadOntology(ontologyFile, catalogFile, null); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from a File, with optional catalog File and input format. | ||
| * | ||
| * @param ontologyFile the ontology file to load | ||
| * @param catalogFile the catalog file to use | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(File ontologyFile, File catalogFile, String inputFormat) | ||
| throws IOException { | ||
| logger.debug("Loading ontology {} with catalog file {}", ontologyFile, catalogFile); | ||
| Object jsonObject = null; | ||
| OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
|
|
@@ -417,14 +477,15 @@ public OWLOntology loadOntology(File ontologyFile, File catalogFile) throws IOEx | |
| // Maybe unzip | ||
| if (ontologyFile.getPath().endsWith(".gz")) { | ||
| if (catalogFile == null) { | ||
| return loadCompressedOntology(ontologyFile, null); | ||
| return loadCompressedOntology(ontologyFile, null, inputFormat); | ||
| } else { | ||
| return loadCompressedOntology(ontologyFile, catalogFile.getAbsolutePath()); | ||
| return loadCompressedOntology(ontologyFile, catalogFile.getAbsolutePath(), inputFormat); | ||
| } | ||
| } | ||
|
|
||
| // Otherwise load from file using default method | ||
| return loadOntology(manager, new FileDocumentSource(ontologyFile)); | ||
| OWLDocumentFormat fmt = inputFormat != null ? getFormat(inputFormat) : null; | ||
| return loadOntology(manager, new FileDocumentSource(ontologyFile, fmt)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to next reviewer: I expect that FileDocumentSource(,) handles the case where fmt is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Calling the |
||
| } catch (JsonLdError | OWLOntologyCreationException e) { | ||
| throw new IOException(String.format(invalidOntologyFileError, ontologyFile.getName()), e); | ||
| } | ||
|
|
@@ -442,7 +503,7 @@ public OWLOntology loadOntology(InputStream ontologyStream) throws IOException { | |
| } | ||
|
|
||
| /** | ||
| * Load an ontology from an InputStream with a catalog file. | ||
| * Load an ontology from an InputStream with an optional catalog file. | ||
| * | ||
| * @param ontologyStream the ontology stream to load | ||
| * @param catalogPath the catalog file to use or null | ||
|
|
@@ -451,6 +512,20 @@ public OWLOntology loadOntology(InputStream ontologyStream) throws IOException { | |
| */ | ||
| public OWLOntology loadOntology(InputStream ontologyStream, String catalogPath) | ||
| throws IOException { | ||
| return loadOntology(ontologyStream, catalogPath, null); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from an InputStream with an optional catalog file and input format. | ||
| * | ||
| * @param ontologyStream the ontology stream to load | ||
| * @param catalogPath the catalog file to use or null | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology( | ||
| InputStream ontologyStream, String catalogPath, String inputFormat) throws IOException { | ||
| OWLOntology ontology; | ||
| // Maybe load a catalog file | ||
| File catalogFile = null; | ||
|
|
@@ -465,7 +540,18 @@ public OWLOntology loadOntology(InputStream ontologyStream, String catalogPath) | |
| if (catalogFile != null) { | ||
| manager.setIRIMappers(Sets.newHashSet(new CatalogXmlIRIMapper(catalogFile))); | ||
| } | ||
| ontology = loadOntology(manager, new StreamDocumentSource(ontologyStream)); | ||
| OWLOntologyDocumentSource source = null; | ||
| if (inputFormat != null) { | ||
| source = | ||
| new StreamDocumentSource( | ||
| ontologyStream, | ||
| StreamDocumentSource.getNextDocumentIRI("inputstream:ontology"), | ||
jamesaoverton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getFormat(inputFormat), | ||
| null); | ||
| } else { | ||
| source = new StreamDocumentSource(ontologyStream); | ||
| } | ||
| ontology = loadOntology(manager, source); | ||
| } catch (OWLOntologyCreationException e) { | ||
| throw new IOException(invalidOntologyStreamError, e); | ||
| } | ||
|
|
@@ -492,6 +578,20 @@ public OWLOntology loadOntology(IRI ontologyIRI) throws IOException { | |
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(IRI ontologyIRI, String catalogPath) throws IOException { | ||
| return loadOntology(ontologyIRI, catalogPath, null); | ||
| } | ||
|
|
||
| /** | ||
| * Load an ontology from an IRI with an optional catalog file and input format. | ||
| * | ||
| * @param ontologyIRI the ontology IRI to load | ||
| * @param catalogPath the catalog file to use or null | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object, with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| public OWLOntology loadOntology(IRI ontologyIRI, String catalogPath, String inputFormat) | ||
| throws IOException { | ||
| OWLOntology ontology; | ||
| // Maybe load a catalog file | ||
| File catalogFile = null; | ||
|
|
@@ -509,11 +609,18 @@ public OWLOntology loadOntology(IRI ontologyIRI, String catalogPath) throws IOEx | |
| } | ||
| // Maybe load a zipped ontology | ||
| if (ontologyIRI.toString().endsWith(".gz")) { | ||
| ontology = loadCompressedOntology(new URL(ontologyIRI.toString()), catalogPath); | ||
| ontology = | ||
| loadCompressedOntology(new URL(ontologyIRI.toString()), catalogPath, inputFormat); | ||
| } else { | ||
| // Otherwise load ontology as normal | ||
| IRI documentIRI = getDocumentIRIFromMappers(manager, ontologyIRI); | ||
| ontology = loadOntology(manager, new IRIDocumentSource(documentIRI)); | ||
| OWLOntologyDocumentSource source = null; | ||
| if (inputFormat != null) { | ||
| source = new IRIDocumentSource(documentIRI, getFormat(inputFormat), null); | ||
| } else { | ||
| source = new IRIDocumentSource(documentIRI); | ||
| } | ||
| ontology = loadOntology(manager, source); | ||
jamesaoverton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } catch (OWLOntologyCreationException e) { | ||
| throw new IOException(e); | ||
|
|
@@ -1724,13 +1831,15 @@ private static Set<IRI> getUndeclaredPredicates( | |
| * | ||
| * @param gzipFile compressed File to load ontology from | ||
| * @param catalogPath the path to the catalog file or null | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| private OWLOntology loadCompressedOntology(File gzipFile, String catalogPath) throws IOException { | ||
| private OWLOntology loadCompressedOntology(File gzipFile, String catalogPath, String inputFormat) | ||
| throws IOException { | ||
| FileInputStream fis = new FileInputStream(gzipFile); | ||
| GZIPInputStream gis = new GZIPInputStream(fis); | ||
| return loadOntology(gis, catalogPath); | ||
| return loadOntology(gis, catalogPath, inputFormat); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1739,10 +1848,12 @@ private OWLOntology loadCompressedOntology(File gzipFile, String catalogPath) th | |
| * | ||
| * @param url URL to load from | ||
| * @param catalogPath the path to the catalog file or null | ||
| * @param inputFormat the expected format of the ontology or null | ||
| * @return a new ontology object with a new OWLManager | ||
| * @throws IOException on any problem | ||
| */ | ||
| private OWLOntology loadCompressedOntology(URL url, String catalogPath) throws IOException { | ||
| private OWLOntology loadCompressedOntology(URL url, String catalogPath, String inputFormat) | ||
| throws IOException { | ||
| // Check for redirects | ||
| url = followRedirects(url); | ||
|
|
||
|
|
@@ -1754,7 +1865,7 @@ private OWLOntology loadCompressedOntology(URL url, String catalogPath) throws I | |
| throw new IOException(String.format(invalidOntologyIRIError, url)); | ||
| } | ||
| GZIPInputStream gis = new GZIPInputStream(is); | ||
| return loadOntology(gis, catalogPath); | ||
| return loadOntology(gis, catalogPath, inputFormat); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.