Skip to content
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

Robot Header Updated #1189

Closed
wants to merge 13 commits into from
Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Added option to input template strings from external file [#1152]

### Fixed
- '--annotate-with-source true' does not work with extract --method subset [#1160]
- Fix how Template adds entities to the QuotedEntityChecker [#1104]
Expand Down Expand Up @@ -385,6 +388,7 @@ First official release of ROBOT!
[#1171]: https://github.com/ontodev/robot/pull/1171
[#1168]: https://github.com/ontodev/robot/pull/1168
[#1160]: https://github.com/ontodev/robot/pull/1160
[#1152]: https://github.com/ontodev/robot/issues/1152
[#1148]: https://github.com/ontodev/robot/pull/1148
[#1135]: https://github.com/ontodev/robot/pull/1135
[#1119]: https://github.com/ontodev/robot/pull/1119
Expand Down
55 changes: 55 additions & 0 deletions docs/examples/animals_ext_template.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.w3.org/2002/07/owl"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<Ontology/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/0000001 -->

<Class rdf:about="http://purl.obolibrary.org/obo/0000001">
<rdfs:comment>Any animal in the world.</rdfs:comment>
<rdfs:label>animal</rdfs:label>
</Class>



<!-- http://purl.obolibrary.org/obo/0000002 -->

<Class rdf:about="http://purl.obolibrary.org/obo/0000002">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/0000001"/>
<rdfs:comment>A member of the genus Canis.</rdfs:comment>
<rdfs:label>canine</rdfs:label>
</Class>



<!-- http://purl.obolibrary.org/obo/0000003 -->

<Class rdf:about="http://purl.obolibrary.org/obo/0000003">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/0000001"/>
<rdfs:comment>A member of the genus Felis.</rdfs:comment>
<rdfs:label>feline</rdfs:label>
</Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.25) https://github.com/owlcs/owlapi -->

2 changes: 2 additions & 0 deletions docs/examples/animals_ext_template.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CURIE Label Parent Comment
ID LABEL SC % A rdfs:comment
4 changes: 4 additions & 0 deletions docs/examples/animals_template.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CURIE Label Parent Comment
obo:0000001 animal Any animal in the world.
obo:0000002 canine animal A member of the genus Canis.
obo:0000003 feline animal A member of the genus Felis.
5 changes: 5 additions & 0 deletions docs/examples/animals_template_error.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CURIE Label Parent Comment
ID LABEL SC % A rdfs:comment
obo:0000001 animal Any animal in the world.
0000002 canine animal A member of the genus Canis.
obo:0000003 feline animal A member of the genus Felis.
20 changes: 18 additions & 2 deletions docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ If the `TYPE` is a defined class, `owl:Individual`, or `owl:NamedIndividual`, an

#### Example of Individual Template Strings

| Label | Entity Type | Individual Role | Property Assertions | Different Individuals |
| Label | Entity Type | Individual Role | Property Assertions | Different Individuals |
| ------------ | ----------- | -------------------- | ------------------- | --------------------- |
| LABEL | TYPE | TI 'has role' some % | I part_of | DI % |
| Individual 1 | Class 1 | Role Class 1 | Individual 2 | |
Expand Down Expand Up @@ -223,6 +223,21 @@ robot template --merge-before \
--output results/test_template.owl
```

ROBOT template data read from separate external file

robot template --template animals_template.tsv \
--external-template animals_ext_template.tsv \
--output results/animals_ext_template.owl

Adjusted line numbers for error reporting for template data read from separate external file
<!-- DO NOT TEST -->
```
robot template --template animals_template_error.tsv \
--ext-template animals_ext_template.tsv \
--output results/animals_ext_template.owl
```


\* NOTE: the imports would be merged into the output if `--collapse-import-closure true` is included instead.

Further examples can be found [in the OBI repository](https://github.com/obi-ontology/obi/tree/master/src/ontology/templates)
Expand Down Expand Up @@ -313,7 +328,7 @@ AL rdfs:label@en

The provided value cannot be parsed and may not be in proper Manchester syntax. See [Manchester Syntax](http://www.w3.org/2007/OWL/wiki/ManchesterSyntax) for more details. If you are using labels, make sure the labels are defined in the `--input` ontology or using the `LABEL` column. Also ensure that all properties use a label instead of a CURIE or IRI.

When using a restriction (`some`, `only`, `min`, `max`, `exactly`, or `value`) the term that preceeds the restriction must be a property.
When using a restriction (`some`, `only`, `min`, `max`, `exactly`, or `value`) the term that preceeds the restriction must be a property.

Terms joined using `and` or `or` must be of the same entity type, e.g., you cannot join an object property and a class in an expression.

Expand Down Expand Up @@ -366,3 +381,4 @@ An invalid `CHARACTERISTIC` value was passed. If you are providing multiple char
### Unknown Template Error

Valid template strings are limited to the [described above](#template-strings). If a different template string is provided, this error message will be returned.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public class TemplateCommand implements Command {
private static final String missingTemplateError =
NS + "MISSING TEMPLATE ERROR at least one template is required";

/** Error message when the header file is not provided */
private static final String missingRobotHeaderError =
NS + "MISSING ROBOT HEADER ERROR header is required";

private static final String mismatchedRobotHeaderError =
NS
+ "MISMATCHED ROBOT HEADER mismatched template file header and external template file header";

/** Store the command-line options for the command. */
private Options options;

Expand All @@ -49,6 +57,7 @@ public TemplateCommand() {
"A", "include-annotations", true, "if true, include ontology annotations from merge input");
o.addOption("f", "force", true, "if true, do not exit on error");
o.addOption("e", "errors", true, "write errors to this path (TSV or CSV)");
o.addOption("E", "external-template", true, "external robot template data file");

options = o;
}
Expand Down Expand Up @@ -143,6 +152,31 @@ public CommandState execute(CommandState state, String[] args) throws Exception
tables.put(templatePath, TemplateHelper.readTable(templatePath));
}

for (String templatePath : templatePaths) {
tables.put(templatePath, TemplateHelper.readTable(templatePath));
}

// Handle external template files.
List<String> externalTemplatePath =
CommandLineHelper.getOptionValues(line, "external-template");
if (externalTemplatePath.size() > 0) {
List<List<String>> externalTemplate = new ArrayList<>();
externalTemplate = TemplateHelper.readTable(externalTemplatePath.get(0));
if (externalTemplate.size() == 0) {
throw new IllegalArgumentException(missingRobotHeaderError);
}
// Insert externalTemplate into all the template file data appropriately
for (String templatePath : templatePaths) {
List<List<String>> template = tables.get(templatePath);
// check that the first lines (headers) are the same
if (compareHeaders(template.get(0), externalTemplate.get(0))) {
template.add(1, externalTemplate.get(1));
} else {
throw new IllegalArgumentException(mismatchedRobotHeaderError);
}
}
}

// Process the templates
OWLOntology outputOntology =
TemplateOperation.template(inputOntology, ioHelper, tables, templateOptions);
Expand Down Expand Up @@ -194,4 +228,23 @@ public CommandState execute(CommandState state, String[] args) throws Exception

return state;
}

/**
* Compare the headers for the template file and the external template file. Return true if they
* match, false otherwise.
*
* @param templateHeader header from template file
* @param externalTemplateHeader header from external template file
* @return true for match, false for mismatch
*/
private boolean compareHeaders(List<String> templateHeader, List<String> externalTemplateHeader) {
if (templateHeader.size() == externalTemplateHeader.size()) {
int numElements = templateHeader.size();
for (int index = 0; index < numElements; index++) {
if (!templateHeader.get(index).equals(externalTemplateHeader.get(index))) return false;
}
return true;
}
return false;
}
}
7 changes: 7 additions & 0 deletions robot-core/src/main/java/org/obolibrary/robot/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ public OWLOntology generateOutputOntology(String outputIRI, boolean force, Strin
return outputOntology;
}

public int getRowNum() {
return rowNum;
}

public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
/**
* Given a list of rows for a table, first validate the headers and template strings. Then, get
* the location of important columns (e.g. IDs and labels). Finally, add all template rows to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public static Map<String, String> getDefaultOptions() {
Map<String, String> options = new HashMap<>();
options.put("force", "false");
options.put("errors", null);
options.put("external-template", null);
return options;
}

Expand Down Expand Up @@ -176,6 +177,10 @@ public static OWLOntology template(
List<OWLOntology> outputOntologies = new ArrayList<>();
for (Map.Entry<String, List<List<String>>> t : tables.entrySet()) {
Template template = new Template(t.getKey(), t.getValue(), intermediate, ioHelper, checker);
// sufficient to check if ext-template option has a not null value
if (options.get("ext-template") != null) {
template.setRowNum(1);
}
// Update the checker with new labels
checker = template.getChecker();
boolean force = OptionsHelper.optionIsTrue(options, "force");
Expand Down
Loading