Skip to content

Commit 80ffb70

Browse files
committed
Cache the result of the search for deprecation annotation.
Since checking whether a given entity is deprecated requires iterating over all the annotations on said entity, and we might have to check the same entity many times (the entity can be referenced from many different axioms), we cache the result of that check.
1 parent 3f274bb commit 80ffb70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/org/incenp/obofoundry/odk/CheckCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
package org.incenp.obofoundry.odk;
2020

2121
import java.util.ArrayList;
22+
import java.util.HashMap;
2223
import java.util.HashSet;
2324
import java.util.List;
25+
import java.util.Map;
2426
import java.util.Set;
2527

2628
import org.apache.commons.cli.CommandLine;
@@ -44,6 +46,7 @@ public class CheckCommand extends BasePlugin {
4446
private static final Logger logger = LoggerFactory.getLogger(CheckCommand.class);
4547

4648
private Set<String> basePrefixes = new HashSet<>();
49+
private Map<OWLEntity, Boolean> cache = new HashMap<>();
4750

4851
public CheckCommand() {
4952
super("check", "perform some checks on an ontology", "robot check --checks [CHECK,...]");
@@ -58,6 +61,7 @@ public void performOperation(CommandState state, CommandLine line) throws Except
5861
for ( String prefix : CommandLineHelper.getOptionalValues(line, "base-iri") ) {
5962
basePrefixes.add(getIRI(prefix, "base-iri").toString());
6063
}
64+
cache.clear();
6165

6266
int failed = 0;
6367
for ( String check : line.getOptionValues("checks") ) {
@@ -128,13 +132,20 @@ private boolean checkDeprecatedReferences(OWLOntology ontology) {
128132
}
129133

130134
private boolean isDeprecated(OWLOntology ontology, OWLEntity entity) {
135+
Boolean cached = cache.get(entity);
136+
if ( cached != null ) {
137+
return cached;
138+
}
139+
131140
for ( OWLOntology ont : ontology.getImportsClosure() ) {
132141
for ( OWLAnnotationAssertionAxiom ax : ont.getAnnotationAssertionAxioms(entity.getIRI()) ) {
133142
if ( ax.isDeprecatedIRIAssertion() ) {
143+
cache.put(entity, true);
134144
return true;
135145
}
136146
}
137147
}
148+
cache.put(entity, false);
138149
return false;
139150
}
140151

0 commit comments

Comments
 (0)