Skip to content

Commit 40f9f5e

Browse files
authored
Merge pull request #533 from dice-group/clean_up
Small changes/fixes
2 parents d222f8f + a0346f2 commit 40f9f5e

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

docs/usage/05_evaluate_ce.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ the positive and negative examples for the concept of 'Father'. Our positive exa
2929
```python
3030
from owlapy.owl_individual import OWLNamedIndividual, IRI
3131

32+
NS = "http://example.com/father#"
33+
3234
positive_examples = {OWLNamedIndividual(IRI.create(NS, 'stefan')),
3335
OWLNamedIndividual(IRI.create(NS, 'markus')),
3436
OWLNamedIndividual(IRI.create(NS, 'martin'))}
@@ -94,8 +96,9 @@ You can now evaluate the class expression you just created:
9496
<!--pytest-codeblocks:cont-->
9597
```python
9698
from ontolearn.quality_funcs import evaluate_concept
99+
from ontolearn.metrics import F1
97100

98-
evaluated_concept = evaluate_concept(concept_to_test, F1(), encoded_lp)
101+
evaluated_concept = evaluate_concept(kg, concept_to_test, F1(), encoded_lp)
99102
```
100103
In this example we use F1-score to evaluate the concept, but there are more [metrics](ontolearn.metrics)
101104
which you can use including Accuracy, Precision and Recall.

examples/concept_learning_cv_evaluation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def dl_concept_learning(args):
274274
print(f"NCES Runtime: {rt_nces:.3f}")
275275

276276
if not args.learner_types or 'nces2' in args.learner_types:
277-
continue
278277
start_time = time.time()
279278
# () Fit model on training dataset
280279
pred_nces2 = nces2.fit(train_lp).best_hypotheses(n=1)
@@ -299,7 +298,6 @@ def dl_concept_learning(args):
299298
##
300299

301300
if not args.learner_types or 'roces' in args.learner_types:
302-
continue
303301
start_time = time.time()
304302
# () Fit model on training dataset
305303
pred_roces = roces.fit(train_lp).best_hypotheses(n=1)

ontolearn/knowledge_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ def __init__(self, *,
117117
elif reasoner_factory is not None:
118118
self.reasoner = reasoner_factory(self.ontology)
119119
else:
120-
# default to native Reasoner of owlapy. To use SyncReasoner, pass the reasoner explicitly as an argument.
121-
self.reasoner = StructuralReasoner(ontology=self.ontology)
120+
if isinstance(self.ontology, Ontology):
121+
self.reasoner = StructuralReasoner(ontology=self.ontology)
122+
else:
123+
self.reasoner = SyncReasoner(ontology=self.ontology, reasoner="Pellet")
122124

123125
if load_class_hierarchy:
124126
self.class_hierarchy: ClassHierarchy

ontolearn/learners/drill.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ def compute_quality_of_class_expression(self, state: RL_State) -> None:
448448
named_individual = OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'NamedIndividual'))
449449
if named_individual in tp:
450450
c = named_individual
451+
assert c == named_individual, ("Individuals in your dataset do not explicitly have the type"
452+
"owl:Thing or owl:NamedIndividual and this will eventually "
453+
"throw an error or provide misleading results because these "
454+
"individuals are not recognized as such. SPARQL queries used by "
455+
"TripleStore cannot infer this information.")
451456

452457
sparql_query = owl_expression_to_sparql_with_confusion_matrix(expression=c, positive_examples=self.pos,
453458
negative_examples=self.neg)

ontolearn/scripts/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from ontolearn.verbalizer import LLMVerbalizer
4242
from owlapy import owl_expression_to_dl
4343
import os
44+
import shutil
4445

4546
app = FastAPI()
4647
args = None
@@ -79,9 +80,13 @@ def get_drill(data: dict):
7980
use_nominals=data.get("use_nominals", True),
8081
verbose=1)
8182
# (2) Either load the weights of DRILL or train it.
82-
if data.get("path_to_pretrained_drill", None) and os.path.isdir(data["path_to_pretrained_drill"]):
83+
if (data.get("path_to_pretrained_drill", None) and os.path.isdir(data["path_to_pretrained_drill"]) and
84+
os.path.isfile("path_to_pretrained_drill/drill.pth")):
8385
drill.load(directory=data["path_to_pretrained_drill"])
8486
else:
87+
# remove the pretrained directory if already exist but does not have the drill.pth file and retrain
88+
if data.get("path_to_pretrained_drill", None) and os.path.isdir(data["path_to_pretrained_drill"]):
89+
shutil.rmtree('path_to_pretrained_drill')
8590
# Train & Save
8691
drill.train(num_of_target_concepts=data.get("num_of_target_concepts", 1),
8792
num_learning_problems=data.get("num_of_training_learning_problems", 1))

tests/test_tdl_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_regression_mutagenesis(self):
6060
lp = PosNegLPStandard(pos=typed_pos, neg=typed_neg)
6161
h = model.fit(learning_problem=lp).best_hypotheses()
6262
q = compute_f1_score(individuals=frozenset({i for i in kb.individuals(h)}), pos=lp.pos, neg=lp.neg)
63-
assert q >= 0.85
63+
assert q >= 0.80
6464

6565
def test_regression_carcinogenesis(self):
6666
path = "KGs/Carcinogenesis/carcinogenesis.owl"

0 commit comments

Comments
 (0)