dice-group / Ontolearn

Ontolearn is an open-source software library for explainable structured machine learning in Python. It learns OWL class expressions from positive and negative examples.
https://ontolearn-docs-dice-group.netlify.app/index.html
MIT License
43 stars 9 forks source link

EvoLearner Example Broken #475

Closed heindorf closed 2 weeks ago

heindorf commented 2 weeks ago

I tried to run python concept_learning_with_evolearner.py in the latest ontolearn version (0.80). However, I get the error

Traceback (most recent call last):
  File "/home/heindorf/git/Ontolearn/examples/concept_learning_with_evolearner.py", line 61, in <module>
    model.save_best_hypothesis(n=3, path='Predictions_{0}'.format(str_target_concept))
  File "/home/heindorf/git/Ontolearn/ontolearn/base_concept_learner.py", line 383, in save_best_hypothesis
    ontology.save(IRI.create(path + '.owl'))
  File "/home/heindorf/.conda/envs/ontolearn/lib/python3.10/site-packages/owlapy/iri.py", line 89, in create
    return IRI(string[0:index], string[index:])
  File "/home/heindorf/.conda/envs/ontolearn/lib/python3.10/site-packages/owlapy/iri.py", line 20, in __call__
    _temp = super().__call__(*args, **kwargs)
  File "/home/heindorf/.conda/envs/ontolearn/lib/python3.10/site-packages/owlapy/iri.py", line 46, in __init__
    assert namespace[-1] in ("/", ":", "#"), "It should be a valid IRI based on /, :, and #"
IndexError: string index out of range

The problem seems to be in the line model.save_best_hypothesis(n=3, path='Predictions_{0}'.format(str_target_concept))

alkidbaci commented 2 weeks ago

This is related with a change in owlapy where the standard to save an ontology is by using an IRI and what the error is indicating is that Predictions_{str_targetconcept} is not a valid IRI because it does not contain one of ("/", ":", "#"). Now its true that the argument name path is a bit misleading but the path should be a valid iri in string format which basically refers to the saving filename. In this case we add a "./" before the name so it will be considered a valid IRI and filepath at the same time, i.e. (./Predictions{str_target_concept}. These changes are recent and the example is apparently not updated. Maybe we can alter the standard a bit to be less restrictive

heindorf commented 2 weeks ago

By the way, the same issue occurs for CELOE: https://github.com/dice-group/Ontolearn/blob/35d5e597707f67ebc6dc124c0c9e4cce88c0572a/examples/concept_learning_with_celoe_heuristic.py#L76

Demirrr commented 2 weeks ago

Fixed with #477 We created a text for each example so that the examples will not be broken, see https://github.com/dice-group/Ontolearn/blob/develop/tests/test_example_celoe.py https://github.com/dice-group/Ontolearn/blob/develop/tests/test_evolearner.py