@@ -189,20 +189,7 @@ public static OWLOntology extract(
189
189
}
190
190
// Maybe annotate entities with rdfs:isDefinedBy
191
191
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 );
206
193
}
207
194
208
195
// Determine what to do based on intermediates
@@ -219,6 +206,31 @@ public static OWLOntology extract(
219
206
}
220
207
}
221
208
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
+
222
234
/**
223
235
* Extracts a materialized sub-ontology from the given ontology that only contains the given terms
224
236
* and the relations between them. The input ontology is not changed.
@@ -249,6 +261,11 @@ public static OWLOntology extractSubset(
249
261
copyPropertyAnnotations (inputOntology , filteredOnt );
250
262
ReduceOperation .reduce (filteredOnt , new org .semanticweb .elk .owlapi .ElkReasonerFactory ());
251
263
264
+ // Maybe annotate entities with rdfs:isDefinedBy
265
+ if (OptionsHelper .optionIsTrue (options , "annotate-with-source" )) {
266
+ annotateWithSource (sourceMap , filteredOnt , OWLManager .createOWLOntologyManager ());
267
+ }
268
+
252
269
return filteredOnt ;
253
270
}
254
271
0 commit comments