From f724de06a03fd242b71208a387f77cb7d1e1276d Mon Sep 17 00:00:00 2001 From: Luke Friedrichs Date: Thu, 12 Dec 2024 09:07:54 +0100 Subject: [PATCH] removed neural ontology manager --- examples/neural_reasoner_retrieval.py | 9 ++------- owlapy/owl_neural_reasoners/abstract.py | 6 ++---- owlapy/owl_neural_reasoners/owl_neural_reasoner.py | 5 +---- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/examples/neural_reasoner_retrieval.py b/examples/neural_reasoner_retrieval.py index 02e86e9..4a4e065 100644 --- a/examples/neural_reasoner_retrieval.py +++ b/examples/neural_reasoner_retrieval.py @@ -41,7 +41,6 @@ """ from owlapy.owl_neural_reasoners.owl_neural_reasoner import OWLNeuralReasoner -from owlapy.owl_neural_reasoners.neural_ontology_manager import NeuralOntologyManager from owlapy.owl_reasoner import StructuralReasoner from owlapy.owl_ontology_manager import OntologyManager from owlapy.utils import concept_reducer, concept_reducer_properties, jaccard_similarity, f1_set_similarity @@ -78,13 +77,9 @@ def execute(args): symbolic_kb = StructuralReasoner(ontology=OntologyManager().load_ontology(path=args.path_kg)) # (2) Initialize Neural OWL Reasoner. if args.path_kge_model: - neural_manager = NeuralOntologyManager() - neural_manager.load_neural_embedding(path=args.path_kge_model) - neural_owl_reasoner = OWLNeuralReasoner(ontology=neural_manager, gamma=args.gamma) + neural_owl_reasoner = OWLNeuralReasoner(path_neural_embedding=args.path_kge_model, gamma=args.gamma) else: - neural_manager = NeuralOntologyManager() - neural_manager.load_ontology(path=args.path_kg) - neural_owl_reasoner = OWLNeuralReasoner(ontology=neural_manager, gamma=args.gamma) + neural_owl_reasoner = OWLNeuralReasoner(path_of_kb=args.path_kg, gamma=args.gamma) # Fix the random seed. random.seed(args.seed) ################################################################### diff --git a/owlapy/owl_neural_reasoners/abstract.py b/owlapy/owl_neural_reasoners/abstract.py index 33aac1d..14a1892 100644 --- a/owlapy/owl_neural_reasoners/abstract.py +++ b/owlapy/owl_neural_reasoners/abstract.py @@ -1,13 +1,11 @@ from abc import ABC, abstractmethod -from typing import List, Tuple, Generator, Union +from typing import List, Tuple, Generator from owlapy.class_expression import OWLClassExpression -from owlapy.owl_neural_reasoners.neural_ontology_manager import NeuralOntologyManager -from owlapy.owl_ontology import AbstractOWLOntology class AbstractNeuralReasoner(ABC): """Abstract class for Neural Reasoners that operate on OWL Class Expressions using embeddings.""" @abstractmethod - def __init__(self, ontology: Union[NeuralOntologyManager, AbstractOWLOntology], **kwargs): + def __init__(self, **kwargs): pass @abstractmethod diff --git a/owlapy/owl_neural_reasoners/owl_neural_reasoner.py b/owlapy/owl_neural_reasoners/owl_neural_reasoner.py index 97fef3d..c1dddde 100644 --- a/owlapy/owl_neural_reasoners/owl_neural_reasoner.py +++ b/owlapy/owl_neural_reasoners/owl_neural_reasoner.py @@ -14,7 +14,6 @@ from collections import Counter, OrderedDict from functools import lru_cache from owlapy.owl_neural_reasoners.abstract import AbstractNeuralReasoner -from owlapy.owl_neural_reasoners.neural_ontology_manager import NeuralOntologyManager # TODO: def is_valid_entity(text_input: str): @@ -22,10 +21,8 @@ def is_valid_entity(text_input: str): class OWLNeuralReasoner(AbstractNeuralReasoner): """ OWL Neural Reasoner uses a neural link predictor to retrieve instances of an OWL Class Expression""" - def __init__(self, ontology: NeuralOntologyManager, gamma: float = 0.25, max_cache_size: int = 2**20): + def __init__(self, path_of_kb: str = None, path_neural_embedding: str = None, gamma: float = 0.25, max_cache_size: int = 2**20): assert gamma is None or 0 <= gamma <= 1, "Confidence threshold (gamma) must be in the range [0, 1]." - path_of_kb = ontology.get_path() - path_neural_embedding = ontology.get_path_neural_embedding( ) self.gamma = gamma self._prediction_cache = OrderedDict() self._max_cache_size = max_cache_size