This commit is contained in:
hajdul88 2025-09-17 12:24:39 +02:00
parent 6e47de4979
commit 00c3ba3a0c
3 changed files with 28 additions and 22 deletions

View file

@ -35,6 +35,8 @@ class BaseOntologyResolver(ABC):
@abstractmethod @abstractmethod
def get_subgraph( def get_subgraph(
self, node_name: str, node_type: str = "individuals", directed: bool = True self, node_name: str, node_type: str = "individuals", directed: bool = True
) -> Tuple[List[AttachedOntologyNode], List[Tuple[str, str, str]], Optional[AttachedOntologyNode]]: ) -> Tuple[
List[AttachedOntologyNode], List[Tuple[str, str, str]], Optional[AttachedOntologyNode]
]:
"""Get a subgraph for the given node.""" """Get a subgraph for the given node."""
pass pass

View file

@ -49,7 +49,5 @@ class FuzzyMatchingStrategy(MatchingStrategy):
return name return name
# Find fuzzy match # Find fuzzy match
best_match = difflib.get_close_matches( best_match = difflib.get_close_matches(name, candidates, n=1, cutoff=self.cutoff)
name, candidates, n=1, cutoff=self.cutoff
)
return best_match[0] if best_match else None return best_match[0] if best_match else None

View file

@ -24,7 +24,11 @@ class RDFLibOntologyResolver(BaseOntologyResolver):
It provides fuzzy matching and subgraph extraction capabilities for ontology entities. It provides fuzzy matching and subgraph extraction capabilities for ontology entities.
""" """
def __init__(self, ontology_file: Optional[str] = None, matching_strategy: Optional[MatchingStrategy] = None): def __init__(
self,
ontology_file: Optional[str] = None,
matching_strategy: Optional[MatchingStrategy] = None,
):
super().__init__(matching_strategy) super().__init__(matching_strategy)
self.ontology_file = ontology_file self.ontology_file = ontology_file
try: try:
@ -111,7 +115,9 @@ class RDFLibOntologyResolver(BaseOntologyResolver):
def get_subgraph( def get_subgraph(
self, node_name: str, node_type: str = "individuals", directed: bool = True self, node_name: str, node_type: str = "individuals", directed: bool = True
) -> Tuple[List[AttachedOntologyNode], List[Tuple[str, str, str]], Optional[AttachedOntologyNode]]: ) -> Tuple[
List[AttachedOntologyNode], List[Tuple[str, str, str]], Optional[AttachedOntologyNode]
]:
nodes_set = set() nodes_set = set()
edges: List[Tuple[str, str, str]] = [] edges: List[Tuple[str, str, str]] = []
visited = set() visited = set()