liveontologies / elk-reasoner

A Java-based OWL 2 EL reasoner
Apache License 2.0
94 stars 26 forks source link

ELK 0.4.3 does not seem to cache calls to getSubclasses() #50

Closed matentzn closed 6 years ago

matentzn commented 6 years ago

I do not know whether this is a bug, but I had a bottleneck in an application and I was surprised to find it here. After calling r.precomputeInferences(CLASS_HIERARCHY) I would expect calls to getSubclasses and getSuperclasses to be mere look-ups. However, these calls tend to be very slow; In order to proof that it was not the lookup itself causing the trouble, I tried the following:

OWLReasoner r = new ElkReasonerFactory().createReasoner(o); List<OWLClass> classes = createClassListWithDuplicates();

V1 for(OWLClass c:classes) { System.out.println(r.getSubClasses(c,false)); }

V2: Map<OWLClass,Set<OWLClass>> makeshiftcache = new HashMap<>(); for(OWLClass c:classes) { if(!makeshiftcache.containsKey(c)) { makeshiftcache.put(c,r.getSubClasses(c,false).getFlattened()); } System.out.println(makeshiftcache.get(c)); } Over time, V2 gets faster and faster, while V1 remains always the same in terms of performance. Is this intentional, or not a supported behaviour?

ykazakov commented 6 years ago

In ELK only direct subclasses / superclasses are stored in the taxonomy model. Indirect (all) subclasses / superclasses are computed on the fly from the direct ones. We do not decide for the user which calls of the OWL API methods to cache. If you need to retrieve (non-direct) subclasses / superclasses frequently for the same object, V2 seems to be the right choice.

matentzn commented 6 years ago

Okay thanks.