Skip to content

Commit

Permalink
Merge pull request #427 from rctauber/filter_update
Browse files Browse the repository at this point in the history
Add support for domain and range selectors
  • Loading branch information
jamesaoverton authored Feb 4, 2019
2 parents 7b14de4 + 1fe61ad commit edcbf51
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
2 changes: 2 additions & 0 deletions docs/remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Relation type selections provide the ability to select which terms to remove bas
6. `equivalents`
7. `types`
8. `instances`
9. `domains`
10. `ranges`

#### Entity Types

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,7 @@ public static Set<OWLAxiom> getAnnotationAxioms(OWLOntology ontology, Set<OWLObj
public static Set<OWLAxiom> getCompleteAxioms(
OWLOntology ontology, Set<OWLObject> objects, Set<Class<? extends OWLAxiom>> axiomTypes) {
Set<OWLAxiom> axioms = new HashSet<>();

Set<IRI> iris = new HashSet<>();
for (OWLObject object : objects) {
if (OWLNamedObject.class.isInstance(object)) {
OWLNamedObject namedObject = (OWLNamedObject) object;
iris.add(namedObject.getIRI());
}
}

Set<IRI> iris = getIRIs(objects);
for (OWLAxiom axiom : ontology.getAxioms()) {
if (OntologyHelper.extendsAxiomTypes(axiom, axiomTypes)) {
// Check both the full annotated axiom and axiom without annotations (if annotated)
Expand Down Expand Up @@ -146,15 +138,7 @@ public static Set<OWLAxiom> getCompleteAxioms(
public static Set<OWLAxiom> getPartialAxioms(
OWLOntology ontology, Set<OWLObject> objects, Set<Class<? extends OWLAxiom>> axiomTypes) {
Set<OWLAxiom> axioms = new HashSet<>();

Set<IRI> iris = new HashSet<>();
for (OWLObject object : objects) {
if (OWLNamedObject.class.isInstance(object)) {
OWLNamedObject namedObject = (OWLNamedObject) object;
iris.add(namedObject.getIRI());
}
}

Set<IRI> iris = getIRIs(objects);
for (OWLAxiom axiom : ontology.getAxioms()) {
if (OntologyHelper.extendsAxiomTypes(axiom, axiomTypes)) {
if (axiom instanceof OWLAnnotationAssertionAxiom) {
Expand Down Expand Up @@ -284,6 +268,10 @@ public static Set<OWLObject> select(
return objects;
} else if (selector.equals("types")) {
return selectTypes(ontology, objects);
} else if (selector.equals("ranges")) {
return selectRanges(ontology, objects);
} else if (selector.equals("domains")) {
return selectDomains(ontology, objects);
} else if (selector.contains("=")) {
return selectPattern(ontology, ioHelper, objects, selector);
} else {
Expand Down Expand Up @@ -447,6 +435,27 @@ public static Set<OWLObject> selectDescendants(OWLOntology ontology, Set<OWLObje
return relatedObjects;
}

/**
* Given an ontology and a set of objects, return all domains of any properties in the set.
*
* @param ontology OWLOntology to retrieve domains from
* @param objects OWLObjects to retrieve domains of
* @return set of domains of the starting set
*/
public static Set<OWLObject> selectDomains(OWLOntology ontology, Set<OWLObject> objects) {
Set<OWLObject> relatedObjects = new HashSet<>();
for (OWLObject object : objects) {
if (object instanceof OWLAnnotationProperty) {
relatedObjects.addAll(EntitySearcher.getDomains((OWLAnnotationProperty) object, ontology));
} else if (object instanceof OWLDataProperty) {
relatedObjects.addAll(EntitySearcher.getDomains((OWLDataProperty) object, ontology));
} else if (object instanceof OWLObjectProperty) {
relatedObjects.addAll(EntitySearcher.getDomains((OWLObjectProperty) object, ontology));
}
}
return relatedObjects;
}

/**
* Given an ontology and a set of objects, return all equivalent objects of the starting set.
*
Expand Down Expand Up @@ -588,6 +597,27 @@ public static Set<OWLObject> selectProperties(Set<OWLObject> objects) {
return relatedObjects;
}

/**
* Given an ontology and a set of objects, return all ranges of any properties in the set.
*
* @param ontology OWLOntology to retrieve ranges from
* @param objects OWLObjects to retrieve ranges of
* @return set of ranges of the starting set
*/
public static Set<OWLObject> selectRanges(OWLOntology ontology, Set<OWLObject> objects) {
Set<OWLObject> relatedObjects = new HashSet<>();
for (OWLObject object : objects) {
if (object instanceof OWLAnnotationProperty) {
relatedObjects.addAll(EntitySearcher.getRanges((OWLAnnotationProperty) object, ontology));
} else if (object instanceof OWLDataProperty) {
relatedObjects.addAll(EntitySearcher.getRanges((OWLDataProperty) object, ontology));
} else if (object instanceof OWLObjectProperty) {
relatedObjects.addAll(EntitySearcher.getRanges((OWLObjectProperty) object, ontology));
}
}
return relatedObjects;
}

/**
* Given an ontology and a set of objects, return a set of all the types of the individuals in
* that set.
Expand Down Expand Up @@ -718,6 +748,23 @@ protected static Set<OWLAnnotation> getAnnotations(
}
}

/**
* Given a set of OWLObjects, return the set of IRIs for those objects.
*
* @param objects OWLObjects to get IRIs of
* @return IRIs of the given objects
*/
private static Set<IRI> getIRIs(Set<OWLObject> objects) {
Set<IRI> iris = new HashSet<>();
for (OWLObject object : objects) {
if (object instanceof OWLNamedObject) {
OWLNamedObject namedObject = (OWLNamedObject) object;
iris.add(namedObject.getIRI());
}
}
return iris;
}

/**
* Given an OWL ontology, an annotation property, and an annotation value (in regex pattern form),
* return a set of OWLAnnotations that have values matching the regex value.
Expand Down

0 comments on commit edcbf51

Please sign in to comment.