Skip to content

Commit

Permalink
removed neural ontology manager
Browse files Browse the repository at this point in the history
  • Loading branch information
LckyLke committed Dec 12, 2024
1 parent 4045219 commit f724de0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
9 changes: 2 additions & 7 deletions examples/neural_reasoner_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
###################################################################
Expand Down
6 changes: 2 additions & 4 deletions owlapy/owl_neural_reasoners/abstract.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions owlapy/owl_neural_reasoners/owl_neural_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@
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):
return True if "/" in text_input else False

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
Expand Down

0 comments on commit f724de0

Please sign in to comment.