22
33import math
44import warnings
5- from typing import (
6- TYPE_CHECKING ,
7- Any ,
8- Dict ,
9- Generic ,
10- Hashable ,
11- Iterator ,
12- List ,
13- Optional ,
14- Set ,
15- TypeVar ,
16- )
5+ from typing import TYPE_CHECKING , Any , Generic , Hashable , Iterator , TypeVar
176
187import networkx as nx
198
@@ -37,7 +26,7 @@ class Node_Info(Freezable, Generic[Node]):
3726 without requiring an external corpus to ascertain term frequency.
3827 """
3928
40- ic_metrics : List [str ] = [
29+ ic_metrics : list [str ] = [
4130 "intrinsic_ic" ,
4231 "intrinsic_ic_sanchez" ,
4332 ]
@@ -53,7 +42,7 @@ def __init__(self, nxo: NXOntology[Node], node: Node):
5342 self .node = node
5443
5544 @property
56- def name (self ) -> Optional [ str ] :
45+ def name (self ) -> str | None :
5746 """Human readable name / label."""
5847 value = self ._get_node_attribute (
5948 custom_field = "node_name_attribute" , default = "name"
@@ -66,7 +55,7 @@ def name(self) -> Optional[str]:
6655 return None if value is None else str (value )
6756
6857 @property
69- def label (self ) -> Optional [ str ] :
58+ def label (self ) -> str | None :
7059 """Human readable node name / label."""
7160 warnings .warn (
7261 "Node_Info.label is deprecated and will be removed. Use Node_Info.name instead." ,
@@ -76,14 +65,14 @@ def label(self) -> Optional[str]:
7665 return self .name
7766
7867 @property
79- def identifier (self ) -> Optional [ Any ] :
68+ def identifier (self ) -> Any | None :
8069 """Database / machine identifier."""
8170 return self ._get_node_attribute (
8271 custom_field = "node_identifier_attribute" , default = "identifier"
8372 )
8473
8574 @property
86- def url (self ) -> Optional [ str ] :
75+ def url (self ) -> str | None :
8776 """Uniform Resource Locator (URL)"""
8877 value = self ._get_node_attribute (
8978 custom_field = "node_url_attribute" , default = "url"
@@ -102,19 +91,19 @@ def frozen(self) -> bool:
10291 return self .nxo .frozen
10392
10493 @property
105- def data (self ) -> Dict [Any , Any ]:
94+ def data (self ) -> dict [Any , Any ]:
10695 """Dictionary of node data (properties) for `self.node` in the networkx graph."""
10796 data = self .nxo .graph .nodes [self .node ]
10897 assert isinstance (data , dict )
10998 return data
11099
111100 @property
112- def parents (self ) -> Set [Node ]:
101+ def parents (self ) -> set [Node ]:
113102 """Direct parent nodes of this node."""
114103 return set (self .nxo .graph .predecessors (self .node ))
115104
116105 @property
117- def parent (self ) -> Optional [ Node ] :
106+ def parent (self ) -> Node | None :
118107 """
119108 Sole parent of this node, or None if this node is a root.
120109 If this node has multiple parents, raise ValueError.
@@ -129,13 +118,13 @@ def parent(self) -> Optional[Node]:
129118 raise ValueError (f"Node { self !r} has multiple parents." )
130119
131120 @property
132- def children (self ) -> Set [Node ]:
121+ def children (self ) -> set [Node ]:
133122 """Direct child nodes of this node."""
134123 return set (self .nxo .graph .successors (self .node ))
135124
136125 @property # type: ignore [misc]
137126 @cache_on_frozen
138- def ancestors (self ) -> Set [Node ]:
127+ def ancestors (self ) -> set [Node ]:
139128 """
140129 Get ancestors of node in graph, including the node itself.
141130 Ancestors refers to more general concepts in an ontology,
@@ -148,7 +137,7 @@ def ancestors(self) -> Set[Node]:
148137
149138 @property # type: ignore [misc]
150139 @cache_on_frozen
151- def descendants (self ) -> Set [Node ]:
140+ def descendants (self ) -> set [Node ]:
152141 """
153142 Get descendants of node in graph, including the node itself.
154143 Descendants refers to more specific concepts in an ontology,
@@ -171,12 +160,12 @@ def n_descendants(self) -> int:
171160
172161 @property # type: ignore [misc]
173162 @cache_on_frozen
174- def roots (self ) -> Set [Node ]:
163+ def roots (self ) -> set [Node ]:
175164 """Ancestors of this node that are roots (top-level)."""
176165 return self .ancestors & self .nxo .roots
177166
178167 @property
179- def leaves (self ) -> Set [Node ]:
168+ def leaves (self ) -> set [Node ]:
180169 """Descendents of this node that are leaves."""
181170 return self .descendants & self .nxo .leaves
182171
0 commit comments