get_hierarchy_info.py§
build_hierarchy(relationships)
§
Build a hierarchical tree structure from a list of parent-child relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relationships
|
List[Tuple[str, str]]
|
A list of tuples representing parent-child relationships. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representing the hierarchical tree structure. |
Source code in brickllm/utils/get_hierarchy_info.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
create_hierarchical_dict(elements, properties=False)
§
Create a hierarchical dictionary from a list of elements, optionally including properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements
|
List[str]
|
A list of elements to include in the hierarchy. |
required |
properties
|
bool
|
Whether to include properties in the hierarchy. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representing the hierarchical structure. |
Source code in brickllm/utils/get_hierarchy_info.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
extract_ttl_content(input_string)
§
Extract content between code block markers in a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_string
|
str
|
The input string containing code blocks. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The extracted content between the code block markers. |
Source code in brickllm/utils/get_hierarchy_info.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
filter_elements(elements)
§
Filter elements based on their hierarchical relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements
|
List[str]
|
A list of elements to filter. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of filtered elements. |
Source code in brickllm/utils/get_hierarchy_info.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
find_parents(current_data, target, parents=None)
§
Recursively find the parent nodes of a target node in a hierarchical data structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_data
|
Dict[str, Any]
|
The current level of the hierarchy to search. |
required |
target
|
str
|
The target node to find parents for. |
required |
parents
|
Optional[List[str]]
|
Accumulated list of parent nodes. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Tuple[bool, List[str]]
|
Tuple[bool, List[str]]: A tuple containing a boolean indicating if the target was found and a list of parent nodes. |
Source code in brickllm/utils/get_hierarchy_info.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
find_sensor_paths(tree, path=None)
§
Find paths to sensor nodes in a hierarchical tree structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree
|
Dict[str, Any]
|
The hierarchical tree structure. |
required |
path
|
Optional[List[str]]
|
Accumulated path to the current node. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
List[Dict[str, str]]: A list of dictionaries containing sensor names and their paths. |
Source code in brickllm/utils/get_hierarchy_info.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
flatten_hierarchy(current_data, parent=None, result=None)
§
Flatten a hierarchical data structure into a list of parent-child tuples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_data
|
Dict[str, Any]
|
The current level of the hierarchy to flatten. |
required |
parent
|
Optional[str]
|
The parent node. Defaults to None. |
None
|
result
|
Optional[List[Tuple[str, str]]]
|
Accumulated list of parent-child tuples. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
List[Tuple[str, str]]
|
List[Tuple[str, str]]: A list of tuples representing parent-child relationships. |
Source code in brickllm/utils/get_hierarchy_info.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
get_all_subchildren(current_data, target)
§
Recursively get all children and subchildren of a target node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_data
|
Dict[str, Any]
|
The current level of the hierarchy to search. |
required |
target
|
str
|
The target node to find children for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representing the subtree of the target node. |
Source code in brickllm/utils/get_hierarchy_info.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_children(current_data, target)
§
Get the children of a target node in a hierarchical data structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_data
|
Dict[str, Any]
|
The current level of the hierarchy to search. |
required |
target
|
str
|
The target node to find children for. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of child nodes. |
Source code in brickllm/utils/get_hierarchy_info.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
get_children_hierarchy(key, flatten=False)
§
Get the hierarchy of children for a target node, optionally flattening the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The target node to get children for. |
required |
flatten
|
bool
|
Whether to flatten the hierarchy. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[Dict[str, Any], List[Tuple[str, str]]]
|
Union[Dict[str, Any], List[Tuple[str, str]]]: A dictionary representing the hierarchy or a list of parent-child tuples if flattened. |
Source code in brickllm/utils/get_hierarchy_info.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
get_hierarchical_info(key)
§
Get the hierarchical information of a node, including its parents and children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The target node to get information for. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]]
|
Tuple[List[str], List[str]]: A tuple containing a list of parent nodes and a list of child nodes. |
Source code in brickllm/utils/get_hierarchy_info.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|