|
2 | 2 | import logging |
3 | 3 | from collections import deque |
4 | 4 |
|
5 | | -from ontograph.queries.navigator import NavigatorPronto |
6 | | -from ontograph.queries.relations import RelationsPronto |
| 5 | +from ontograph.models import LookUpTables |
| 6 | +from ontograph.queries.navigator import NavigatorOntology |
| 7 | +from ontograph.queries.relations import RelationsPronto, RelationsOntology |
7 | 8 |
|
8 | 9 | __all__ = [ |
9 | | - 'OntologyIntrospection', |
| 10 | + 'IntrospectionOntology', |
10 | 11 | ] |
11 | 12 |
|
12 | 13 | logger = logging.getLogger(__name__) |
|
16 | 17 | # ------------------------------------------------------------ |
17 | 18 | # ---- OntologyIntrospection Port (abstract class) ---- |
18 | 19 | # ------------------------------------------------------------ |
19 | | -class OntologyIntrospection(ABC): |
| 20 | +class IntrospectionOntology(ABC): |
20 | 21 | """Abstract class for ontology introspection utilities.""" |
21 | 22 |
|
22 | | - def __init__(self, navigator, relations) -> None: |
| 23 | + def __init__( |
| 24 | + self, navigator: NavigatorOntology, relations: RelationsOntology |
| 25 | + ) -> None: |
23 | 26 | self._navigator = navigator |
24 | 27 | self._relations = relations |
25 | 28 |
|
@@ -60,14 +63,14 @@ def print_term_trajectories_tree(trajectories: list[dict]) -> None: |
60 | 63 | # ------------------------------------------------------------- |
61 | 64 | # ---- IntrospectionPronto adapter (concrete class) ---- |
62 | 65 | # ------------------------------------------------------------- |
63 | | -class IntrospectionPronto(OntologyIntrospection): |
| 66 | +class IntrospectionPronto(IntrospectionOntology): |
64 | 67 | """Provides introspection utilities for ontology graphs. |
65 | 68 |
|
66 | 69 | Includes methods for calculating distances, paths, and ancestor trajectories. |
67 | 70 | """ |
68 | 71 |
|
69 | 72 | def __init__( |
70 | | - self, navigator: NavigatorPronto, relations: RelationsPronto |
| 73 | + self, navigator: NavigatorOntology, relations: RelationsPronto |
71 | 74 | ) -> None: |
72 | 75 | """Initialize the introspection utility. |
73 | 76 |
|
@@ -242,8 +245,8 @@ def print_term_trajectories_tree(trajectories: list[dict]) -> None: |
242 | 245 | print(f'{node["id"]}: {node["name"]}') |
243 | 246 | return |
244 | 247 | # Otherwise, use tree printing |
245 | | - root = OntologyIntrospection._build_tree_from_trajectories(trajectories) |
246 | | - OntologyIntrospection._print_ascii_tree(root) |
| 248 | + root = IntrospectionOntology._build_tree_from_trajectories(trajectories) |
| 249 | + IntrospectionOntology._print_ascii_tree(root) |
247 | 250 |
|
248 | 251 | @staticmethod |
249 | 252 | def _build_tree_from_trajectories(trajectories: list[dict]) -> object: |
@@ -306,30 +309,31 @@ def print_ascii_tree( |
306 | 309 | print_ascii_tree(child, '', is_last_child) |
307 | 310 |
|
308 | 311 |
|
309 | | -class IntrospectionGraphblas(OntologyIntrospection): |
| 312 | +class IntrospectionGraphblas(IntrospectionOntology): |
310 | 313 | """Provides introspection utilities for ontology graphs using GraphBLAS. |
311 | 314 |
|
312 | 315 | Includes methods for calculating distances, paths, and ancestor trajectories. |
313 | 316 | """ |
314 | 317 |
|
315 | 318 | def __init__( |
316 | 319 | self, |
317 | | - navigator: NavigatorPronto, |
318 | | - relations: RelationsPronto, |
319 | | - lookup_tables, |
| 320 | + navigator: NavigatorOntology, |
| 321 | + relations: RelationsOntology, |
| 322 | + lookup_tables: LookUpTables, |
320 | 323 | ) -> None: |
321 | 324 | """Initialize the introspection utility. |
322 | 325 |
|
323 | 326 | Args: |
324 | | - navigator (OntologyNavigator): The ontology navigator. |
325 | | - relations (OntologyRelations): The ontology relations. |
| 327 | + navigator (NavigatorPronto): The ontology navigator. |
| 328 | + relations (RelationsPronto): The ontology relations. |
| 329 | + lookup_tables (LookUpTables): Lookup tables for term/index/description mapping. |
326 | 330 | """ |
327 | 331 | self.__navigator = navigator |
328 | 332 | self.__relations = relations |
329 | 333 | self.lookup_tables = lookup_tables |
330 | 334 | self.matrices_container = navigator.matrices_container |
331 | 335 |
|
332 | | - def get_distance_from_root(self, term_id): |
| 336 | + def get_distance_from_root(self, term_id: str) -> int: |
333 | 337 | """Calculate the distance from the given term to the root node(s) of the ontology. |
334 | 338 |
|
335 | 339 | Parameters |
@@ -361,7 +365,7 @@ def get_distance_from_root(self, term_id): |
361 | 365 |
|
362 | 366 | return max_distance |
363 | 367 |
|
364 | | - def get_path_between(self, node_a, node_b): |
| 368 | + def get_path_between(self, node_a: str, node_b: str) -> list: |
365 | 369 | """Find the shortest path between two nodes in the ontology. |
366 | 370 |
|
367 | 371 | Parameters |
@@ -403,7 +407,7 @@ def get_path_between(self, node_a, node_b): |
403 | 407 | # BFS to find shortest path |
404 | 408 |
|
405 | 409 | queue = deque([[start_idx]]) |
406 | | - visited = set([start_idx]) |
| 410 | + visited = {start_idx} |
407 | 411 |
|
408 | 412 | while queue: |
409 | 413 | path = queue.popleft() |
|
0 commit comments