From 7880d0efbcfa0f8bf9ca46687a6cfc43e7d00371 Mon Sep 17 00:00:00 2001 From: Louis-Mozart Date: Wed, 22 Jan 2025 15:17:43 +0100 Subject: [PATCH] Refactoring --- ontolearn/semantic_caching.py | 78 ----------------------------------- 1 file changed, 78 deletions(-) diff --git a/ontolearn/semantic_caching.py b/ontolearn/semantic_caching.py index 5cb8e6f..a9c2a5e 100644 --- a/ontolearn/semantic_caching.py +++ b/ontolearn/semantic_caching.py @@ -698,81 +698,3 @@ def run_non_semantic_cache(path_kg:str, path_kge:str, cache_size:int, name_reaso 'avg_jaccard_reas': f"{sum(Avg_jaccard_reas) / len(Avg_jaccard_reas):.3f}" }, D - - - - -# def subsumption_based_caching(func, cache_size): -# cache = {} # Dictionary to store cached results - -# def store(concept, instances): -# # Check if cache limit will be exceeded -# if len(instances) + len(cache) > cache_size: -# purge(len(instances)) # Adjusted to ensure cache size limit -# # Add concept and instances to cache -# cache[concept] = instances - -# def purge(needed_space): -# # Remove oldest items until there's enough space -# while len(cache) > needed_space: -# cache.pop(next(iter(cache))) - -# def wrapper(*args): -# path_onto = args[1] -# onto = get_ontology(path_onto).load() - -# # Synchronize the reasoner (e.g., using Pellet) -# # with onto: -# # sync_reasoner(infer_property_values=True) - -# all_individuals = {a for a in onto.individuals()} -# str_expression = owl_expression_to_dl(args[0]) -# owl_expression = args[0] - -# # Check cache for existing results -# if str_expression in cache: -# return cache[str_expression] - -# super_concepts = set() -# namespace, class_name = owl_expression.str.split('#') -# class_expression = f"{namespace.split('/')[-1]}.{class_name}" - -# all_classes = [i for i in list(onto.classes())] - -# for j in all_classes: -# if str(j) == class_expression: -# class_expression = j - -# for D in list(cache.keys()): -# # print(owl_expression) -# # exit(0) -# if D in class_expression.ancestors(): # Check if C ⊑ D -# super_concepts.add(D) - -# print(super_concepts) -# exit(0) -# # Compute instances based on subsumption -# if len(super_concepts) == 0: -# instances = all_individuals -# else: -# instances = set.intersection( -# *[wrapper(D, path_onto) for D in super_concepts] -# ) - -# # Filter instances by checking if each is an instance of the concept -# instance_set = set() - -# for individual in instances: -# for type_entry in individual.is_a: -# type_iri = str(type_entry.iri) -# if owl_expression.str == type_iri: -# instance_set.add(individual) -# break - -# # Store in cache -# store(str_expression, instance_set) -# return instance_set - -# return wrapper - -