DL-Learner icon indicating copy to clipboard operation
DL-Learner copied to clipboard

ClassCastException with CELOE and ClassExpressionLearningProblem

Open posixcompliance opened this issue 3 years ago • 4 comments

Given the following code and the current release DL-Learner 1.5, there is a ClassCastException thrown during alg.start();.

        OWLOntologyManager manager = OWLManager.createConcurrentOWLOntologyManager();
        OWLOntology ontology = manager.loadOntologyFromOntologyDocument(getClass().getResourceAsStream("/Test.owl"));
        Configuration reasonerConfiguration = new Configuration();
        // using HermiT
        OWLReasoner reasoner = new ReasonerFactory().createReasoner(ontology, reasonerConfiguration);

        AbstractKnowledgeSource ks = new OWLAPIOntology(ontology);
        ks.init();

        OWLAPIReasoner rc = new OWLAPIReasoner(reasoner);
        rc.init();

        ClassExpressionLearningProblem lp = new ClassExpressionLearningProblem(rc);
        lp.setClassToDescribe(IRI.create("#Positive"));
        lp.init();

        CELOE alg = new CELOE(lp, rc);
        alg.setMaxExecutionTimeInSeconds(10);
        alg.init();

        alg.start();
java.lang.ClassCastException: class org.dllearner.utilities.ReasoningUtils cannot be cast to class org.dllearner.utilities.ReasoningUtilsCLP (org.dllearner.utilities.ReasoningUtils and org.dllearner.utilities.ReasoningUtilsCLP are in unnamed module of loader 'app')

	at org.dllearner.learningproblems.ClassExpressionLearningProblem.computeScore(ClassExpressionLearningProblem.java:184)
	at org.dllearner.learningproblems.ClassExpressionLearningProblem.evaluate(ClassExpressionLearningProblem.java:266)
	at org.dllearner.learningproblems.ClassExpressionLearningProblem.evaluate(ClassExpressionLearningProblem.java:53)
	at org.dllearner.core.AbstractLearningProblem.evaluate(AbstractLearningProblem.java:103)
	at org.dllearner.utilities.owl.EvaluatedDescriptionSet.add(EvaluatedDescriptionSet.java:71)
	at org.dllearner.algorithms.celoe.CELOE.addNode(CELOE.java:609)
	at org.dllearner.algorithms.celoe.CELOE.start(CELOE.java:331)

Perhaps this could be an issue with me using a single class #Positive as the class to describe?

posixcompliance avatar May 02 '22 15:05 posixcompliance

seems to be a bug; if you want to test something with a single named class you can see if the ClassLearningProblem (no Expression) does any good

SimonBin avatar May 20 '22 14:05 SimonBin

I have tested again and can confirm that the code works with just ClassLearningProblem. However, the same exception as above is still being thrown when I use a real class expression.

I tested with code like the following:

        ClassExpressionLearningProblem lp = new ClassExpressionLearningProblem(rc);
        lp.setClassExpressionToDescribe(
            df.getOWLObjectHasValue(
                    df.getOWLObjectProperty(IRI.create("testProperty")),
                    df.getOWLNamedIndividual(IRI.create("testIndividual"))
            )
        );
        lp.init();

posixcompliance avatar May 24 '22 14:05 posixcompliance

Upon further investigation I think the issue in ClassExpressionLearningProblem may be with the cast to the following class cast: https://github.com/SmartDataAnalytics/DL-Learner/blob/6359c3e4ff7595d4758e6ba3c5e18698a8ad5324/components-core/src/main/java/org/dllearner/learningproblems/ClassExpressionLearningProblem.java#L184

But the instance was created to be a ReasoningUtils Object by: https://github.com/SmartDataAnalytics/DL-Learner/blob/6359c3e4ff7595d4758e6ba3c5e18698a8ad5324/components-core/src/main/java/org/dllearner/learningproblems/ClassExpressionLearningProblem.java#L108

posixcompliance avatar May 24 '22 21:05 posixcompliance

right, but there are more subtle issues to consider in e.g. the CELOE algorithm when trying to use such a Learning Problem, which currently does too many assumptions about supported learning problems; so I fear than that needs to be done

SimonBin avatar May 25 '22 12:05 SimonBin