diff --git a/robot-command/src/main/java/org/obolibrary/robot/CommandLineHelper.java b/robot-command/src/main/java/org/obolibrary/robot/CommandLineHelper.java
index 1197eea0f..b8f993bcb 100644
--- a/robot-command/src/main/java/org/obolibrary/robot/CommandLineHelper.java
+++ b/robot-command/src/main/java/org/obolibrary/robot/CommandLineHelper.java
@@ -478,7 +478,17 @@ public static OWLOntology getInputOntology(
}
if (!inputOntologyPaths.isEmpty()) {
- return ioHelper.loadOntology(inputOntologyPaths.get(0), catalogPath, inputFormat);
+ String ontologyPath = inputOntologyPaths.get(0);
+ // When the ontology file is local,
+ // but the catalog path is null at this step,
+ // then we want to guess the catalog file.
+ if (catalogPath == null) {
+ File ontologyFile = new File(ontologyPath);
+ File catalogFile = ioHelper.guessCatalogFile(ontologyFile);
+ return ioHelper.loadOntology(ontologyFile, catalogFile, inputFormat);
+ } else {
+ return ioHelper.loadOntology(ontologyPath, catalogPath, inputFormat);
+ }
} else if (!inputOntologyIRIs.isEmpty()) {
return ioHelper.loadOntology(IRI.create(inputOntologyIRIs.get(0)), catalogPath, inputFormat);
} else {
diff --git a/robot-command/src/test/java/org/obolibrary/robot/CommandLineHelperTest.java b/robot-command/src/test/java/org/obolibrary/robot/CommandLineHelperTest.java
index ae65dfcc9..a3f5f3399 100644
--- a/robot-command/src/test/java/org/obolibrary/robot/CommandLineHelperTest.java
+++ b/robot-command/src/test/java/org/obolibrary/robot/CommandLineHelperTest.java
@@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
import org.junit.Test;
/** Tests for CommandLineHelper. */
@@ -49,4 +51,21 @@ public void testParseArgs() throws Exception {
CommandLineHelper.parseArgList("unbalanced 'quotes");
});
}
+
+ /**
+ * Test handling an input ontology that requires a catalog file.
+ *
+ * @throws Exception on parsing problem
+ */
+ @Test
+ public void testGetInputOntology() throws Exception {
+ String[] args = {"--input", "../robot-core/src/test/resources/catalog_test.owl"};
+ Options o = CommandLineHelper.getCommonOptions();
+ o.addOption("i", "input", true, "load ontology from a file");
+ o.addOption("I", "input-iri", true, "load ontology from an IRI");
+ CommandLine line = CommandLineHelper.getCommandLine("usage", o, args);
+ IOHelper ioHelper = CommandLineHelper.getIOHelper(line);
+ CommandLineHelper.getInputOntology(ioHelper, line);
+ assert true;
+ }
}
diff --git a/robot-core/src/main/java/org/obolibrary/robot/IOHelper.java b/robot-core/src/main/java/org/obolibrary/robot/IOHelper.java
index 5a26f6498..4187b5833 100644
--- a/robot-core/src/main/java/org/obolibrary/robot/IOHelper.java
+++ b/robot-core/src/main/java/org/obolibrary/robot/IOHelper.java
@@ -358,7 +358,7 @@ public OWLOntology loadOntology(String ontologyPath, boolean useCatalog, String
*/
public OWLOntology loadOntology(String ontologyPath, String catalogPath) throws IOException {
File ontologyFile = new File(ontologyPath);
- File catalogFile = new File(catalogPath);
+ File catalogFile = catalogPath != null ? new File(catalogPath) : null;
return loadOntology(ontologyFile, catalogFile);
}
diff --git a/robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java b/robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java
index 640163e3a..907d8d983 100644
--- a/robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java
+++ b/robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java
@@ -19,6 +19,7 @@
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.UnloadableImportException;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
/** Tests for IOHelper. */
@@ -414,4 +415,41 @@ public void testExplicitInputFormat() throws IOException {
}
assert error;
}
+
+ /**
+ * Test loading an ontology and without using a catalog.
+ *
+ * @throws IOException on error creating IOHelper
+ */
+ @Test
+ public void testCatalog() throws IOException {
+ IOHelper ioHelper = new IOHelper();
+
+ // This file should fail to load without using a catalog file.
+ boolean error = false;
+ try {
+ ioHelper.loadOntology("src/test/resources/catalog_test.owl", false);
+ } catch (UnloadableImportException e) {
+ error = true;
+ }
+ assert error;
+
+ // The file should load if we specify the catalog file.
+ ioHelper.loadOntology(
+ "src/test/resources/catalog_test.owl", "src/test/resources/catalog-v001.xml");
+ assert true;
+
+ // If no argument is passed, catalog file should be automatically detected.
+ ioHelper.loadOntology("src/test/resources/catalog_test.owl");
+ assert true;
+
+ // If a null argument is passed, the catalog file will not be detected.
+ error = false;
+ try {
+ ioHelper.loadOntology("src/test/resources/catalog_test.owl", null);
+ } catch (UnloadableImportException e) {
+ error = true;
+ }
+ assert error;
+ }
}
diff --git a/robot-core/src/test/resources/catalog-v001.xml b/robot-core/src/test/resources/catalog-v001.xml
index e618bd1b6..61aaba963 100644
--- a/robot-core/src/test/resources/catalog-v001.xml
+++ b/robot-core/src/test/resources/catalog-v001.xml
@@ -19,4 +19,7 @@
+
+
+
diff --git a/robot-core/src/test/resources/catalog_test.owl b/robot-core/src/test/resources/catalog_test.owl
new file mode 100644
index 000000000..891c696f4
--- /dev/null
+++ b/robot-core/src/test/resources/catalog_test.owl
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+