Skip to content

Commit 4630074

Browse files
Merge pull request #1160 from hkir-dev/issue_1157
Extract subset "annotate-with-source" support
2 parents 08b89af + 1a185d8 commit 4630074

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

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

14-
1514
## [1.9.5] - 2023-09-20
1615

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

383+
[#1160]: https://github.com/ontodev/robot/pull/1160
384384
[#1148]: https://github.com/ontodev/robot/pull/1148
385385
[#1135]: https://github.com/ontodev/robot/pull/1135
386386
[#1119]: https://github.com/ontodev/robot/pull/1119

robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,7 @@ public static OWLOntology extract(
189189
}
190190
// Maybe annotate entities with rdfs:isDefinedBy
191191
if (OptionsHelper.optionIsTrue(options, "annotate-with-source")) {
192-
Set<OWLAnnotationAxiom> sourceAxioms = new HashSet<>();
193-
for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) {
194-
// Check if rdfs:isDefinedBy already exists
195-
Set<OWLAnnotationValue> existingValues =
196-
OntologyHelper.getAnnotationValues(outputOntology, isDefinedBy, entity.getIRI());
197-
if (existingValues == null || existingValues.size() == 0) {
198-
// If not, add it
199-
OWLAnnotationAxiom def = getIsDefinedBy(entity, sourceMap);
200-
if (def != null) {
201-
sourceAxioms.add(def);
202-
}
203-
}
204-
}
205-
manager.addAxioms(outputOntology, sourceAxioms);
192+
annotateWithSource(sourceMap, outputOntology, manager);
206193
}
207194

208195
// Determine what to do based on intermediates
@@ -219,6 +206,31 @@ public static OWLOntology extract(
219206
}
220207
}
221208

209+
/**
210+
* Annotates entities of the outputOntology with rdfs:isDefinedBy.
211+
*
212+
* @param sourceMap map of term IRI to source IRI, or null.
213+
* @param outputOntology output ontology.
214+
* @param manager OWL ontology manager.
215+
*/
216+
private static void annotateWithSource(
217+
Map<IRI, IRI> sourceMap, OWLOntology outputOntology, OWLOntologyManager manager) {
218+
Set<OWLAnnotationAxiom> sourceAxioms = new HashSet<>();
219+
for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) {
220+
// Check if rdfs:isDefinedBy already exists
221+
Set<OWLAnnotationValue> existingValues =
222+
OntologyHelper.getAnnotationValues(outputOntology, isDefinedBy, entity.getIRI());
223+
if (existingValues == null || existingValues.size() == 0) {
224+
// If not, add it
225+
OWLAnnotationAxiom def = getIsDefinedBy(entity, sourceMap);
226+
if (def != null) {
227+
sourceAxioms.add(def);
228+
}
229+
}
230+
}
231+
manager.addAxioms(outputOntology, sourceAxioms);
232+
}
233+
222234
/**
223235
* Extracts a materialized sub-ontology from the given ontology that only contains the given terms
224236
* and the relations between them. The input ontology is not changed.
@@ -249,6 +261,11 @@ public static OWLOntology extractSubset(
249261
copyPropertyAnnotations(inputOntology, filteredOnt);
250262
ReduceOperation.reduce(filteredOnt, new org.semanticweb.elk.owlapi.ElkReasonerFactory());
251263

264+
// Maybe annotate entities with rdfs:isDefinedBy
265+
if (OptionsHelper.optionIsTrue(options, "annotate-with-source")) {
266+
annotateWithSource(sourceMap, filteredOnt, OWLManager.createOWLOntologyManager());
267+
}
268+
252269
return filteredOnt;
253270
}
254271

0 commit comments

Comments
 (0)