8000 Fix warning when term is in imports (extract command) by beckyjackson · Pull Request #625 · ontodev/robot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix warning when term is in imports (extract command) #625

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

Merged
merged 1 commit into from
Feb 19, 2020
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
4 changes: 4 additions & 0 deletions docs/extract.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ MIREOT requires either `--lower-term` or `--branch-from-term` to proceed. `--upp

If an `--upper-term` is specified for MIREOT, `--lower-term` (or terms) must also be specified.

### Invalid Imports Error

The input for `--imports` must be either `exclude` or `include`.

### Invalid Method Error

The `--method` option only accepts: MIREOT, STAR, TOP, and BOT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -37,6 +38,10 @@ public class ExtractCommand implements Command {
+ "MISSING LOWER TERMS ERROR "
+ "lower term(s) must be specified with upper term(s) for MIREOT";

/** Error message when user provides invalid imports option. */
private static final String invalidImportsError =
NS + "INVALID IMPORTS ERROR --imports must be 'include' or 'exclude'";

/** Error message when user provides invalid extraction method. */
private static final String invalidMethodError =
NS + "INVALID METHOD ERROR method must be: MIREOT, STAR, TOP, BOT";
Expand Down Expand Up @@ -221,6 +226,7 @@ private static OWLOntology mireotExtract(
CommandLine line,
Map<String, String> extractOptions)
throws Exception {
Imports imports = getImportsOption(extractOptions);
List<OWLOntology> outputOntologies = new ArrayList<>();
// Get terms from input (ensuring that they are in the input ontology)
// It's okay for any of these to return empty (allowEmpty = true)
Expand All @@ -229,23 +235,26 @@ private static OWLOntology mireotExtract(
OntologyHelper.filterExistingTerms(
inputOntology,
CommandLineHelper.getTerms(ioHelper, line, "upper-term", "upper-terms"),
true);
true,
imports);
if (upperIRIs.size() == 0) {
upperIRIs = null;
}
Set<IRI> lowerIRIs =
OntologyHelper.filterExistingTerms(
inputOntology,
CommandLineHelper.getTerms(ioHelper, line, "lower-term", "lower-terms"),
true);
true,
imports);
if (lowerIRIs.size() == 0) {
lowerIRIs = null;
}
Set<IRI> branchIRIs =
OntologyHelper.filterExistingTerms(
inputOntology,
CommandLineHelper.getTerms(ioHelper, line, "branch-from-term", "branch-from-terms"),
true);
true,
imports);
if (branchIRIs.size() == 0) {
branchIRIs = null;
}
Expand Down Expand Up @@ -303,6 +312,7 @@ private static OWLOntology slmeExtract(
CommandLine line,
Map<String, String> extractOptions)
throws Exception {
Imports imports = getImportsOption(extractOptions);
// upper-term, lower-term, and branch-from term should not be used
List<String> mireotTerms =
Arrays.asList(
Expand All @@ -322,7 +332,8 @@ private static OWLOntology slmeExtract(
OntologyHelper.filterExistingTerms(
inputOntology,
CommandLineHelper.getTerms(ioHelper, line),
OptionsHelper.optionIsTrue(extractOptions, "force"));
OptionsHelper.optionIsTrue(extractOptions, "force"),
imports);

// Determine what to do with sources
Map<IRI, IRI> sourceMap =
Expand All @@ -337,6 +348,24 @@ private static OWLOntology slmeExtract(
inputOntology, terms, outputIRI, moduleType, extractOptions, sourceMap);
}

/**
* Given a map of options, return the imports option as Imports.
*
* @param extractOptions map of options
* @return Imports INCLUDED or EXCLUDED
* @throws Exception if option is not 'include' or 'exclude'
*/
private static Imports getImportsOption(Map<String, String> extractOptions) throws Exception {
String importsOption = OptionsHelper.getOption(extractOptions, "imports", "include");
if (importsOption.equalsIgnoreCase("include")) {
return Imports.INCLUDED;
} else if (importsOption.equalsIgnoreCase("exclude")) {
return Imports.EXCLUDED;
} else {
throw new Exception(invalidImportsError);
}
}

/**
* Given an IOHelper and the path to a term-to-source map, return a map of term IRI to source IRI.
*
Expand Down
19 changes: 17 additions & 2 deletions robot-core/src/main/java/org/obolibrary/robot/OntologyHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static void copyAnnotations(

/**
* Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in
* the ontology.
* the ontology. Always include terms in imports.
*
* @param ontology the ontology to check for IRIs
* @param IRIs Set of IRIs to filter
Expand All @@ -299,9 +299,24 @@ public static void copyAnnotations(
*/
public static Set<IRI> filterExistingTerms(
OWLOntology ontology, Set<IRI> IRIs, boolean allowEmpty) {
return filterExistingTerms(ontology, IRIs, allowEmpty, Imports.INCLUDED);
}

/**
* Given an ontology and a set of IRIs, filter the set of IRIs to only include those that exist in
* the ontology. Maybe include terms in imports.
*
* @param ontology the ontology to check for IRIs
* @param IRIs Set of IRIs to filter
* @param allowEmpty boolean specifying if an empty set can be returned
* @param imports Imports INCLUDED or EXCLUDED
* @return Set of filtered IRIs
*/
public static Set<IRI> filterExistingTerms(
OWLOntology ontology, Set<IRI> IRIs, boolean allowEmpty, Imports imports) {
Set<IRI> missingIRIs = new HashSet<>();
for (IRI iri : IRIs) {
if (!ontology.containsEntityInSignature(iri)) {
if (!ontology.containsEntityInSignature(iri, imports)) {
logger.warn("Ontology does not contain {}", iri.toQuotedString());
missingIRIs.add(iri);
}
Expand Down
0