Skip to content

Commit

Permalink
Merge pull request #1023 from hkir-dev/886-fix
Browse files Browse the repository at this point in the history
Remove and filter operations new "drop_axiom_annotation" option
  • Loading branch information
jamesaoverton authored Feb 7, 2024
2 parents 6e47651 + 1650528 commit c480381
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Updated ELK from 0.4.3 to 0.5.0. [#999]. This is an important change as ELK 0.5.0 is more complete than 0.4.3, which means that it will potentially uncover inferences, in particular unsatisfiable classes, which were not recognised by ELK 0.4.3.
- Add support for pluggable commands [#1119]
- Add `--drop-axiom-annotations` option to drop axiom annotations in [`remove`] and [`filter`] [#1023]

### Changed
- Migrate to OWL API 4.5.26 to deal with [broken turtle serialiser](https://github.com/ontodev/robot/issues/1129). [#1135]
Expand Down Expand Up @@ -382,7 +383,7 @@ First official release of ROBOT!
[`report`]: http://robot.obolibrary.org/report
[`template`]: http://robot.obolibrary.org/template
[`validate`]: http://robot.obolibrary.org/validate

;
[#1181]: https://github.com/ontodev/robot/pull/1181
[#1171]: https://github.com/ontodev/robot/pull/1171
[#1168]: https://github.com/ontodev/robot/pull/1168
Expand All @@ -402,6 +403,7 @@ First official release of ROBOT!
[#1061]: https://github.com/ontodev/robot/issues/1061
[#1030]: https://github.com/ontodev/robot/issues/1030
[#1026]: https://github.com/ontodev/robot/issues/1026
[#1023]: https://github.com/ontodev/robot/pull/1023
[#1017]: https://github.com/ontodev/robot/issues/1017
[#1016]: https://github.com/ontodev/robot/issues/1016
[#1009]: https://github.com/ontodev/robot/issues/1009
Expand Down
130 changes: 130 additions & 0 deletions docs/examples/template-drop-axiom-filter.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="https://github.com/ontodev/robot/examples/template.owl#"
xml:base="https://github.com/ontodev/robot/examples/template.owl"
xmlns:obo="http://purl.obolibrary.org/obo/"
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#"
xmlns:example="http://example.com/">
<owl:Ontology rdf:about="https://github.com/ontodev/robot/examples/template.owl"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




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

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115"/>



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

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000117"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://example.com/propery-1 -->

<owl:DatatypeProperty rdf:about="http://example.com/propery-1">
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight of a mouse or rat in kilograms (kg).</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Rebecca C Jackson</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">weight in kilograms</rdfs:label>
</owl:DatatypeProperty>



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




<!-- http://example.com/B6C3F1 -->

<owl:Class rdf:about="http://example.com/B6C3F1">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/NCBITaxon_10090"/>
<owl:disjointWith rdf:resource="http://example.com/F344N"/>
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of mouse used in many scientific investigations.</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">B6C3F1</rdfs:label>
<rdfs:seeAlso rdf:resource="http://jaxmice.jax.org/strain/100010.html"/>
</owl:Class>



<!-- http://example.com/F344N -->

<owl:Class rdf:about="http://example.com/F344N">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/NCBITaxon_10116"/>
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of rat used in many scientific investigations.</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">F 344/N</rdfs:label>
<rdfs:seeAlso rdf:resource="http://www.informatics.jax.org/external/festing/rat/docs/F344.shtml"/>
</owl:Class>



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

<owl:Class rdf:about="http://purl.obolibrary.org/obo/NCBITaxon_10090"/>



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

<owl:Class rdf:about="http://purl.obolibrary.org/obo/NCBITaxon_10116"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://example.com/rat-1234 -->

<owl:NamedIndividual rdf:about="http://example.com/rat-1234">
<rdf:type rdf:resource="http://example.com/F344N"/>
<example:propery-1 rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.2</example:propery-1>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">rat 1234</rdfs:label>
</owl:NamedIndividual>
</rdf:RDF>



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

130 changes: 130 additions & 0 deletions docs/examples/template-drop-axiom-remove.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="https://github.com/ontodev/robot/examples/template.owl#"
xml:base="https://github.com/ontodev/robot/examples/template.owl"
xmlns:obo="http://purl.obolibrary.org/obo/"
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#"
xmlns:example="http://example.com/">
<owl:Ontology rdf:about="https://github.com/ontodev/robot/examples/template.owl"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




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

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115"/>



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

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000117"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Data properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://example.com/propery-1 -->

<owl:DatatypeProperty rdf:about="http://example.com/propery-1">
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight of a mouse or rat in kilograms (kg).</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Rebecca C Jackson</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">weight in kilograms</rdfs:label>
</owl:DatatypeProperty>



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




<!-- http://example.com/B6C3F1 -->

<owl:Class rdf:about="http://example.com/B6C3F1">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/NCBITaxon_10090"/>
<owl:disjointWith rdf:resource="http://example.com/F344N"/>
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of mouse used in many scientific investigations.</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">B6C3F1</rdfs:label>
<rdfs:seeAlso rdf:resource="http://jaxmice.jax.org/strain/100010.html"/>
</owl:Class>



<!-- http://example.com/F344N -->

<owl:Class rdf:about="http://example.com/F344N">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/NCBITaxon_10116"/>
<obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of rat used in many scientific investigations.</obo:IAO_0000115>
<obo:IAO_0000117 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000117>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">F 344/N</rdfs:label>
<rdfs:seeAlso rdf:resource="http://www.informatics.jax.org/external/festing/rat/docs/F344.shtml"/>
</owl:Class>



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

<owl:Class rdf:about="http://purl.obolibrary.org/obo/NCBITaxon_10090"/>



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

<owl:Class rdf:about="http://purl.obolibrary.org/obo/NCBITaxon_10116"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://example.com/rat-1234 -->

<owl:NamedIndividual rdf:about="http://example.com/rat-1234">
<rdf:type rdf:resource="http://example.com/F344N"/>
<example:propery-1 rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.2</example:propery-1>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">rat 1234</rdfs:label>
</owl:NamedIndividual>
</rdf:RDF>



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

12 changes: 12 additions & 0 deletions docs/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Then `filter --term A --term R --term C --select "self parents" --axioms all --s
- the objects for `ax2` are `{A, R, C}` (with `R some C` excluded), and all of these are in the target set, so `ax2` is matched and copied
- the objects for `ax3` are `{D, E}`, and none of these are in the target set, so `ax3` is not matched and is not copied

Finally `--drop-axiom-annotations` option lets you to specify an annotation property to drop all axiom annotations using it. `all` parameter can be used to drop all axiom annotations.

The `remove` and `filter` operations maintains structural integrity by default: lineage is maintained, and gaps will be filled where classes have been removed. If you wish to *not* preserve the hierarchy, include `--preserve-structure false`.

## Annotations
Expand Down Expand Up @@ -94,3 +96,13 @@ Create a "base" subset that only includes internal axioms (alternatively, use `r
--include-term IAO:0000119 \
--output results/template-base-filter.owl

Create a "base" subset in which axiom annotations involving IAO:0000117 and IAO:0000119 are removed:

robot filter --input template.owl \
--base-iri http://example.com/ \
--select "annotations" \
--axioms internal \
--drop-axiom-annotations IAO:0000117 \
--drop-axiom-annotations IAO:0000119 \
--output results/template-drop-axiom-filter.owl

13 changes: 13 additions & 0 deletions docs/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Then `remove --term A --term R --term C --select "self parents" --axioms all --s
- the objects for `ax1` are `{A, B}`, and at least one of these is in the target set, so `ax1` is matched and removed
- the objects for `ax2` are `{A, R, C}` (with `R some C` excluded), and at least one of these is in the target set, so `ax2` is matched and removed
- the objects for `ax3` are `{D, E}`, and none of these are in the target set, so `ax3` is not matched and is not removed

Finally `--drop-axiom-annotations` option lets you to specify an annotation property to drop all axiom annotations using it. `all` parameter can be used to drop all axiom annotations.

## Preserving the Structure

Expand Down Expand Up @@ -227,3 +229,14 @@ Create a "base" subset by removing external axioms (alternatively, use `filter -
--select annotation-properties \
--signature true \
--output results/filter_annotations.owl

Create a "base" subset in which axiom annotations involving IAO:0000117 and IAO:0000119 are removed:

robot remove --input template.owl \
--base-iri http://example.com/ \
--axioms external \
--drop-axiom-annotations IAO:0000117 \
--drop-axiom-annotations IAO:0000119 \
--output results/template-drop-axiom-remove.owl

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.semanticweb.owlapi.apibinding.OWLManager;
Expand Down Expand Up @@ -43,6 +44,11 @@ public FilterCommand() {
o.addOption("r", "trim", true, "if true, keep axioms containing only selected objects");
o.addOption(
"S", "signature", true, "if true, keep axioms with any selected entity in their signature");
o.addOption(
"d",
"drop-axiom-annotations",
true,
"drop all axiom annotations involving a particular annotation property");
options = o;
}

Expand Down Expand Up @@ -159,10 +165,22 @@ public CommandState execute(CommandState state, String[] args) throws Exception
}
}

List<String> dropParameters =
CommandLineHelper.getOptionalValues(line, "drop-axiom-annotations");
List<IRI> annotationsToDrop =
dropParameters.stream()
.filter(s -> !s.equalsIgnoreCase("all"))
.map(
curie ->
CommandLineHelper.maybeCreateIRI(ioHelper, curie, "drop-axiom-annotations"))
.collect(Collectors.toList());

// Use the select statements to get a set of objects to filter
Set<OWLObject> relatedObjects =
RemoveCommand.getObjects(line, ioHelper, inputOntology, selectGroups);
if (relatedObjects.isEmpty()) {
// drop specified axiom annotations
RelatedObjectsHelper.dropAxiomAnnotations(outputOntology, annotationsToDrop, dropParameters);
// nothing to filter - save and exit
CommandLineHelper.maybeSaveOutput(line, outputOntology);
state.setOntology(outputOntology);
Expand Down Expand Up @@ -212,6 +230,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
outputOntology, RelatedObjectsHelper.getAnnotationAxioms(inputOntology, relatedObjects));
}

// drop specified axiom annotations
RelatedObjectsHelper.dropAxiomAnnotations(outputOntology, annotationsToDrop, dropParameters);

// Save the changed ontology and return the state
CommandLineHelper.maybeSaveOutput(line, outputOntology);
state.setOntology(outputOntology);
Expand Down
Loading

0 comments on commit c480381

Please sign in to comment.