Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
38 changes: 38 additions & 0 deletions robot-core/src/test/java/org/obolibrary/robot/IOHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions robot-core/src/test/resources/catalog-v001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
<uri id="User Entered Import Resolution" name="https://github.com/ontodev/robot/robot-core/src/test/resources/without_redundant_subclasses.owl" uri="./without_redundant_subclasses.owl"/>
<uri id="User Entered Import Resolution" name="https://github.com/ontodev/robot/robot-core/src/test/resources/non-reasoned.owl" uri="./non-reasoned.owl"/>
<uri id="User Entered Import Resolution" name="https://github.com/ontodev/robot/robot-core/src/test/resources/import_test.owl" uri="./import_test.owl"/>

<!-- Used to test catalog_test.owl -->
<uri id="User Entered Import Resolution" name="http://example.com/does_not_exist.owl" uri="./simple.owl"/>
</catalog>
13 changes: 13 additions & 0 deletions robot-core/src/test/resources/catalog_test.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<rdf:RDF
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<owl:Ontology rdf:about="https://github.com/ontodev/robot/robot-core/src/test/resources/catalog_test.owl">
<owl:imports rdf:resource="http://example.com/does_not_exist.owl"/>
</owl:Ontology>
</rdf:RDF>