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

Fix filtering axioms with multiple axiom selectors #644

Merged
merged 4 commits into from
Mar 4, 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 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]

### Fixed
- Fix filtering axioms with multiple axiom selectors [#644]

## [1.6.0] - 2020-03-04

### Added
Expand Down Expand Up @@ -168,6 +171,7 @@ First official release of ROBOT!
[`report`]: http://robot.obolibrary.org/report
[`template`]: http://robot.obolibrary.org/template

[#644]: https://github.com/ontodev/robot/issues/644
[#630]: https://github.com/ontodev/robot/issues/630
[#625]: https://github.com/ontodev/robot/issues/625
[#619]: https://github.com/ontodev/robot/issues/619
Expand Down
161 changes: 161 additions & 0 deletions docs/examples/no-class-logic.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?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"/>



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

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



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




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

<owl:DatatypeProperty rdf:about="http://example.com/propery-1">
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://example.com/B6C3F1"/>
<rdf:Description rdf:about="http://example.com/F344N"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#decimal"/>
<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>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://example.com/propery-1"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight of a mouse or rat in kilograms (kg).</owl:annotatedTarget>
<obo:IAO_0000119 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Rebecca C Jackson</obo:IAO_0000119>
</owl:Axiom>



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




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

<owl:Class rdf:about="http://example.com/B6C3F1">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/NCBITaxon_10090"/>
<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>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://example.com/B6C3F1"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of mouse used in many scientific investigations.</owl:annotatedTarget>
<obo:IAO_0000119 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000119>
</owl:Axiom>



<!-- 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>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://example.com/F344N"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">An inbred strain of rat used in many scientific investigations.</owl:annotatedTarget>
<obo:IAO_0000119 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">James A. Overton</obo:IAO_0000119>
</owl:Axiom>



<!-- 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">
<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 -->

6 changes: 6 additions & 0 deletions docs/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ Remove structural tautologies (e.g., `owl:Nothing`):
--axioms structural-tautologies \
--output results/no-tautologies.owl

Remove disjoint classes and class assertions:

robot remove --input template.owl \
--axioms "DisjointClasses ClassAssertion" \
--output results/no-class-logic.owl

Create a "base" subset by removing external axioms (alternatively, use `filter --axioms internal`):

robot remove --input template.owl \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Set<OWLAxiom> getAnnotationAxioms(OWLOntology ontology, Set<OWLObj
/**
* Filter a set of OWLAxioms based on the provided arguments.
*
* @param axioms Set of OWLAxioms to filter
* @param inputAxioms Set of OWLAxioms to filter
* @param objects Set of OWLObjects to get axioms for
* @param axiomSelectors List of string selectors for types of axioms
* @param baseNamespaces List of string base namespaces used for internal/external selections
Expand All @@ -99,7 +99,7 @@ public static Set<OWLAxiom> getAnnotationAxioms(OWLOntology ontology, Set<OWLObj
* @throws OWLOntologyCreationException on issue creating empty ontology for tautology checker
*/
public static Set<OWLAxiom> filterAxioms(
Set<OWLAxiom> axioms,
Set<OWLAxiom> inputAxioms,
Set<OWLObject> objects,
List<String> axiomSelectors,
List<String> baseNamespaces,
Expand All @@ -110,34 +110,37 @@ public static Set<OWLAxiom> filterAxioms(
// Go through the axiom selectors in order and process selections
boolean internal = false;
boolean external = false;
Set<OWLAxiom> filteredAxioms = new HashSet<>();
for (String axiomSelector : axiomSelectors) {
if (axiomSelector.equalsIgnoreCase("internal")) {
if (external) {
logger.error(
"ignoring 'internal' axiom selector - 'internal' and 'external' together will remove all axioms");
}
axioms = RelatedObjectsHelper.filterInternalAxioms(axioms, baseNamespaces);
filteredAxioms.addAll(
RelatedObjectsHelper.filterInternalAxioms(inputAxioms, baseNamespaces));
internal = true;
} else if (axiomSelector.equalsIgnoreCase("external")) {
if (internal) {
logger.error(
"ignoring 'external' axiom selector - 'internal' and 'external' together will remove all axioms");
}
axioms = RelatedObjectsHelper.filterExternalAxioms(axioms, baseNamespaces);
filteredAxioms.addAll(
RelatedObjectsHelper.filterExternalAxioms(inputAxioms, baseNamespaces));
external = true;
} else if (axiomSelector.equalsIgnoreCase("tautologies")) {
axioms = RelatedObjectsHelper.filterTautologicalAxioms(axioms, false);
filteredAxioms.addAll(RelatedObjectsHelper.filterTautologicalAxioms(inputAxioms, false));
} else if (axiomSelector.equalsIgnoreCase("structural-tautologies")) {
axioms = RelatedObjectsHelper.filterTautologicalAxioms(axioms, true);
filteredAxioms.addAll(RelatedObjectsHelper.filterTautologicalAxioms(inputAxioms, true));
} else {
// Assume this is a normal OWLAxiom type
Set<Class<? extends OWLAxiom>> axiomTypes =
RelatedObjectsHelper.getAxiomValues(axiomSelector);
axioms = filterAxiomsByAxiomType(axioms, objects, axiomTypes, partial, namedOnly);
filteredAxioms.addAll(
filterAxiomsByAxiomType(inputAxioms, objects, axiomTypes, partial, namedOnly));
}
}

return axioms;
return filteredAxioms;
}

/**
Expand Down