Remove unsed functions
Browse files- lightrag/utils.py +0 -65
lightrag/utils.py
CHANGED
@@ -752,71 +752,6 @@ def truncate_list_by_token_size(
|
|
752 |
return list_data
|
753 |
|
754 |
|
755 |
-
def save_data_to_file(data, file_name):
|
756 |
-
with open(file_name, "w", encoding="utf-8") as f:
|
757 |
-
json.dump(data, f, ensure_ascii=False, indent=4)
|
758 |
-
|
759 |
-
|
760 |
-
def xml_to_json(xml_file):
|
761 |
-
try:
|
762 |
-
tree = ET.parse(xml_file)
|
763 |
-
root = tree.getroot()
|
764 |
-
|
765 |
-
# Print the root element's tag and attributes to confirm the file has been correctly loaded
|
766 |
-
print(f"Root element: {root.tag}")
|
767 |
-
print(f"Root attributes: {root.attrib}")
|
768 |
-
|
769 |
-
data = {"nodes": [], "edges": []}
|
770 |
-
|
771 |
-
# Use namespace
|
772 |
-
namespace = {"": "http://graphml.graphdrawing.org/xmlns"}
|
773 |
-
|
774 |
-
for node in root.findall(".//node", namespace):
|
775 |
-
node_data = {
|
776 |
-
"id": node.get("id").strip('"'),
|
777 |
-
"entity_type": node.find("./data[@key='d0']", namespace).text.strip('"')
|
778 |
-
if node.find("./data[@key='d0']", namespace) is not None
|
779 |
-
else "",
|
780 |
-
"description": node.find("./data[@key='d1']", namespace).text
|
781 |
-
if node.find("./data[@key='d1']", namespace) is not None
|
782 |
-
else "",
|
783 |
-
"source_id": node.find("./data[@key='d2']", namespace).text
|
784 |
-
if node.find("./data[@key='d2']", namespace) is not None
|
785 |
-
else "",
|
786 |
-
}
|
787 |
-
data["nodes"].append(node_data)
|
788 |
-
|
789 |
-
for edge in root.findall(".//edge", namespace):
|
790 |
-
edge_data = {
|
791 |
-
"source": edge.get("source").strip('"'),
|
792 |
-
"target": edge.get("target").strip('"'),
|
793 |
-
"weight": float(edge.find("./data[@key='d3']", namespace).text)
|
794 |
-
if edge.find("./data[@key='d3']", namespace) is not None
|
795 |
-
else 0.0,
|
796 |
-
"description": edge.find("./data[@key='d4']", namespace).text
|
797 |
-
if edge.find("./data[@key='d4']", namespace) is not None
|
798 |
-
else "",
|
799 |
-
"keywords": edge.find("./data[@key='d5']", namespace).text
|
800 |
-
if edge.find("./data[@key='d5']", namespace) is not None
|
801 |
-
else "",
|
802 |
-
"source_id": edge.find("./data[@key='d6']", namespace).text
|
803 |
-
if edge.find("./data[@key='d6']", namespace) is not None
|
804 |
-
else "",
|
805 |
-
}
|
806 |
-
data["edges"].append(edge_data)
|
807 |
-
|
808 |
-
# Print the number of nodes and edges found
|
809 |
-
print(f"Found {len(data['nodes'])} nodes and {len(data['edges'])} edges")
|
810 |
-
|
811 |
-
return data
|
812 |
-
except ET.ParseError as e:
|
813 |
-
print(f"Error parsing XML file: {e}")
|
814 |
-
return None
|
815 |
-
except Exception as e:
|
816 |
-
print(f"An error occurred: {e}")
|
817 |
-
return None
|
818 |
-
|
819 |
-
|
820 |
def process_combine_contexts(*context_lists):
|
821 |
"""
|
822 |
Combine multiple context lists and remove duplicate content
|
|
|
752 |
return list_data
|
753 |
|
754 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
755 |
def process_combine_contexts(*context_lists):
|
756 |
"""
|
757 |
Combine multiple context lists and remove duplicate content
|