diff --git a/CHANGELOG.md b/CHANGELOG.md index c472789b3..37cfc19ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java b/robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java index 0326e89d2..bdb0a4083 100644 --- a/robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java +++ b/robot-core/src/main/java/org/obolibrary/robot/ExtractOperation.java @@ -189,20 +189,7 @@ public static OWLOntology extract( } // Maybe annotate entities with rdfs:isDefinedBy if (OptionsHelper.optionIsTrue(options, "annotate-with-source")) { - Set sourceAxioms = new HashSet<>(); - for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) { - // Check if rdfs:isDefinedBy already exists - Set 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 @@ -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 sourceMap, OWLOntology outputOntology, OWLOntologyManager manager) { + Set sourceAxioms = new HashSet<>(); + for (OWLEntity entity : OntologyHelper.getEntities(outputOntology)) { + // Check if rdfs:isDefinedBy already exists + Set 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. @@ -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; }