Inserts information into the knowledge base at the specified path. Args: path (str): The placement path string, connected by " -> " linking the name of nodes. information (Information): The information to insert. missing_node_handling (str): How
(
self,
path: str,
information: Information,
missing_node_handling="abort",
root: Optional[KnowledgeNode] = None,
)
| 678 | return current_node |
| 679 | |
| 680 | def insert_information( |
| 681 | self, |
| 682 | path: str, |
| 683 | information: Information, |
| 684 | missing_node_handling="abort", |
| 685 | root: Optional[KnowledgeNode] = None, |
| 686 | ): |
| 687 | """ |
| 688 | Inserts information into the knowledge base at the specified path. |
| 689 | |
| 690 | Args: |
| 691 | path (str): The placement path string, connected by " -> " linking the name of nodes. |
| 692 | information (Information): The information to insert. |
| 693 | missing_node_handling (str): How to handle missing nodes. Options are "abort", "create", and "raise error". |
| 694 | Return: |
| 695 | uuid of insertion information |
| 696 | """ |
| 697 | with self._lock: |
| 698 | target_node: KnowledgeNode = self.find_node_by_path( |
| 699 | path=path, missing_node_handling=missing_node_handling, root=root |
| 700 | ) |
| 701 | information_hash = hash(information) |
| 702 | if information.citation_uuid == -1: |
| 703 | info_citation_uuid = self.info_hash_to_uuid_dict.get( |
| 704 | information_hash, len(self.info_hash_to_uuid_dict) + 1 |
| 705 | ) |
| 706 | information.citation_uuid = info_citation_uuid |
| 707 | self.info_hash_to_uuid_dict[information_hash] = info_citation_uuid |
| 708 | self.info_uuid_to_info_dict[info_citation_uuid] = information |
| 709 | if target_node is not None: |
| 710 | self.info_uuid_to_info_dict[information.citation_uuid].meta[ |
| 711 | "placement" |
| 712 | ] = " -> ".join(target_node.get_path_from_root()) |
| 713 | target_node.insert_information(information.citation_uuid) |
| 714 | |
| 715 | def trim_empty_leaf_nodes(self): |
| 716 | """ |
no test coverage detected