SmartDataAnalytics / DL-Learner

A tool for supervised Machine Learning in OWL and Description Logics
http://dl-learner.org
GNU General Public License v3.0
152 stars 34 forks source link

Operator initialized twice when explicitly defined in configuration file #56

Closed patrickwestphal closed 6 years ago

patrickwestphal commented 7 years ago

Having a configuration like

prefixes = [ ("ex","http://ex.com/") ]
ks.type = "OWL File"
ks.fileName = "kb.owl"

reasoner.type = "cwr"
reasoner.sources = {ks}

lp.type = "posNegStandard"
lp.reasoner = reasoner
lp.positiveExamples = {"ex:p1"}
lp.negativeExamples = {"ex:n1"}

op.type = "rho"
op.useHasValueConstructor = true

alg.type = "celoe"
alg.maxExecutionTimeInSeconds = 60
alg.reasoner = reasoner

will result in a RuntimeException:

Caused by: java.lang.NullPointerException
    at org.dllearner.refinementoperators.RhoDRDown.init(RhoDRDown.java:356)
    at org.dllearner.algorithms.celoe.CELOE.init(CELOE.java:313)
    at org.dllearner.configuration.spring.ComponentInitializationBeanPostProcessor.postProcessBeforeInitialization(ComponentInitializationBeanPostProcessor.java:35)

The main problem seems to be that the operator's init() is called twice in CELOE:

if (operator == null) {
    // we use a default operator and inject the class hierarchy for now
    operator = new RhoDRDown();
    ((CustomStartRefinementOperator) operator).setStartClass(startClass);
    ((ReasoningBasedRefinementOperator) operator).setReasoner(reasoner);
}
if (operator instanceof CustomHierarchyRefinementOperator) {
    ((CustomHierarchyRefinementOperator) operator).setClassHierarchy(classHierarchy);
    ((CustomHierarchyRefinementOperator) operator).setObjectPropertyHierarchy(objectPropertyHierarchy);
    ((CustomHierarchyRefinementOperator) operator).setDataPropertyHierarchy(datatypePropertyHierarchy);
}
operator.init();

We would have to check whether operator is already initialized an use the clone constructor to make the hierarchy settings and use/re-initialize the clone afterwards.