Skip to content

Commit

Permalink
Merge pull request #1160 from hkir-dev/issue_1157
Browse files Browse the repository at this point in the history
Extract subset "annotate-with-source" support
  • Loading branch information
jamesaoverton committed Nov 29, 2023
2 parents 08b89af + 1a185d8 commit 4630074
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed

- '--annotate-with-source true' does not work with extract --method subset [#1160]
- Fix how Template adds entities to the QuotedEntityChecker [#1104]


## [1.9.5] - 2023-09-20

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

[#1160]: https://github.com/ontodev/robot/pull/1160
[#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
45 changes: 31 additions & 14 deletions robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,7 @@ public static OWLOntology extract(
}
// Maybe annotate entities with rdfs:isDefinedBy
if (OptionsHelper.optionIsTrue(options, "annotate-with-source")) {
Set<OWLAnnotationAxiom> sourceAxioms = new HashSet<>();
for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) {
// Check if rdfs:isDefinedBy already exists
Set<OWLAnnotationValue> existingValues =
OntologyHelper.getAnnotationValues(outputOntology, isDefinedBy, entity.getIRI());
if (existingValues == null || existingValues.size() == 0) {
// If not, add it
OWLAnnotationAxiom def = getIsDefinedBy(entity, sourceMap);
if (def != null) {
sourceAxioms.add(def);
}
}
}
manager.addAxioms(outputOntology, sourceAxioms);
annotateWithSource(sourceMap, outputOntology, manager);
}

// Determine what to do based on intermediates
Expand All @@ -219,6 +206,31 @@ public static OWLOntology extract(
}
}

/**
* Annotates entities of the outputOntology with rdfs:isDefinedBy.
*
* @param sourceMap map of term IRI to source IRI, or null.
* @param outputOntology output ontology.
* @param manager OWL ontology manager.
*/
private static void annotateWithSource(
Map<IRI, IRI> sourceMap, OWLOntology outputOntology, OWLOntologyManager manager) {
Set<OWLAnnotationAxiom> sourceAxioms = new HashSet<>();
for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) {
// Check if rdfs:isDefinedBy already exists
Set<OWLAnnotationValue> existingValues =
OntologyHelper.getAnnotationValues(outputOntology, isDefinedBy, entity.getIRI());
if (existingValues == null || existingValues.size() == 0) {
// If not, add it
OWLAnnotationAxiom def = getIsDefinedBy(entity, sourceMap);
if (def != null) {
sourceAxioms.add(def);
}
}
}
manager.addAxioms(outputOntology, sourceAxioms);
}

/**
* Extracts a materialized sub-ontology from the given ontology that only contains the given terms
* and the relations between them. The input ontology is not changed.
Expand Down Expand Up @@ -249,6 +261,11 @@ public static OWLOntology extractSubset(
copyPropertyAnnotations(inputOntology, filteredOnt);
ReduceOperation.reduce(filteredOnt, new org.semanticweb.elk.owlapi.ElkReasonerFactory());

// Maybe annotate entities with rdfs:isDefinedBy
if (OptionsHelper.optionIsTrue(options, "annotate-with-source")) {
annotateWithSource(sourceMap, filteredOnt, OWLManager.createOWLOntologyManager());
}

return filteredOnt;
}

Expand Down

0 comments on commit 4630074

Please sign in to comment.