Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #311

Merged
merged 26 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8517438
Setup.py added
Demirrr Oct 30, 2023
1b19f6b
__repr__ included for EvoLearnerNode to show list of respective objects
Demirrr Oct 30, 2023
a2bf10c
Readme updated via examples and DRILL refactored
Demirrr Oct 30, 2023
4e481dc
gradio included
Demirrr Oct 30, 2023
641b7b6
Text reduced
Demirrr Oct 30, 2023
2b9df00
Merge branch 'develop' into DRILL
Demirrr Oct 30, 2023
04aeacd
Merge pull request #307 from dice-group/DRILL
Demirrr Oct 30, 2023
b4e0182
Added more support for triplestore calls
alkidbaci Nov 2, 2023
99e0a3b
Initialize KB with triplestore address only
alkidbaci Nov 2, 2023
fbaa456
Fixed query when owl:Thing used in UNION, Intersect or as filler
alkidbaci Nov 2, 2023
e32494a
Changed example to run CELOE instead
alkidbaci Nov 2, 2023
dc0972b
Updated converter test to recent changes
alkidbaci Nov 2, 2023
245161d
Refactoring
alkidbaci Nov 3, 2023
af61c2c
Updated documentation
alkidbaci Nov 3, 2023
6bdede0
Refactoring KB
alkidbaci Nov 3, 2023
f7f9e60
Merge pull request #308 from dice-group/retrieval_via_triplestore
Demirrr Nov 7, 2023
34de594
Added 'requests' package
alkidbaci Nov 9, 2023
dd79bcc
Removed 'use_triplestore' argument
alkidbaci Nov 9, 2023
934b725
Fixed an issue
alkidbaci Nov 9, 2023
7235127
Added `verbalize` method for CL models. #292
alkidbaci Nov 21, 2023
cfc96f6
Refactoring: owlapy is now a dependency
alkidbaci Nov 22, 2023
e51e435
Documentation update
alkidbaci Nov 22, 2023
17921fb
Removed unused files
alkidbaci Nov 23, 2023
5133ca2
Changed description for CL execution
alkidbaci Nov 23, 2023
e3379ea
Added verbalization example
alkidbaci Nov 23, 2023
21b818d
Merge pull request #310 from dice-group/general_adjustments
Demirrr Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added verbalize method for CL models. #292
alkidbaci committed Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7235127ce4cd02d3595a45ac3fb61a58f266969b
65 changes: 63 additions & 2 deletions ontolearn/base_concept_learner.py
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@
import time
from abc import ABCMeta, abstractmethod
from typing import List, Tuple, Dict, Optional, Iterable, Generic, TypeVar, ClassVar, Final, Union, cast, Callable, Type

import xml.etree.ElementTree as ET
import numpy as np
import pandas as pd

import os
from ontolearn.heuristics import CELOEHeuristic
from ontolearn.knowledge_base import KnowledgeBase
from ontolearn.metrics import F1, Accuracy
@@ -358,6 +358,67 @@ def load_hypotheses(self, path: str) -> Iterable[OWLClassExpression]:
if equivalent_c != c:
yield equivalent_c

@staticmethod
def verbalize(predictions_file_path: str):

tree = ET.parse(predictions_file_path)
root = tree.getroot()
tmp_file = 'tmp_file_' + predictions_file_path
owl = 'http://www.w3.org/2002/07/owl#'
ontology_elem = root.find(f'{{{owl}}}Ontology')
ontology_elem.remove(ontology_elem.find(f'{{{owl}}}imports'))

# The commented lines below are needed if you want to use `verbaliser.verbalise_class_expression`
# They assign labels to classes and properties.

# rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
# rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
# for element in root.iter():
# resource = None
# if f'{{{rdf}}}about' in element.attrib:
# resource = element.attrib[f'{{{rdf}}}about']
# elif f'{{{rdf}}}resource' in element.attrib:
# resource = element.attrib[f'{{{rdf}}}resource']
# if resource is not None:
# label = resource.split('#')
# if len(label) > 1:
# element.set(f'{{{rdfs}}}label', label[1])
# else:
# element.set(f'{{{rdfs}}}label', resource)

tree.write(tmp_file)

try:
from deeponto.onto import Ontology, OntologyVerbaliser
from anytree.dotexport import RenderTreeGraph
from IPython.display import Image
except Exception as e:
print("You need to install deeponto to use this feature (pip install deeponto). If you have already, check "
"whether it's installed properly. \n ----> Error: " + f'{e}')
if os.path.exists(tmp_file):
os.remove(tmp_file)
return

onto = Ontology(tmp_file)
verbalizer = OntologyVerbaliser(onto)
complex_concepts = onto.get_asserted_complex_classes()
try:
for i, ce in enumerate(complex_concepts):
tree = verbalizer.parser.parse(str(ce))
tree.render_image()
os.rename("range_node.png", f"Prediction_{i}.png")
except Exception as e:
print("If you have not installed graphviz, please do so at https://graphviz.org/download/ to make the "
"verbalization possible. Otherwise check the error message: \n" + f'{e}')
if os.path.exists(tmp_file):
os.remove(tmp_file)
if len(complex_concepts) == 0:
print("No complex classes found!")
elif len(complex_concepts) == 1:
print("Image generated successfully!")
else:
print("Images generated successfully!")


class RefinementBasedConceptLearner(BaseConceptLearner[_N]):
"""