-
Hello, I tried to export a graph from ArangoDB to graphml thanks to NetworkX and networkx-adapter I did from dotenv import load_dotenv
from arango import ArangoClient
from adbnx_adapter import ADBNX_Adapter
load_dotenv()
client = ArangoClient(hosts="http://localhost:8529")
db = client.db("My-DB", username="root", password=os.getenv("ARANGO_ROOT_PASSWORD"))
adbnx_adapter = ADBNX_Adapter(db)
nx_g = adbnx_adapter.arangodb_graph_to_networkx("My-Graph")
nx.write_graphml_lxml(nx_g, "my.graphml") but it raised
I think my nodes have attributes named So I tried def convert_data_types(data):
"""Converts unsupported data types to strings."""
if isinstance(data, type):
return str(data)
else:
return data
#print("nodes")
for node, attr_dict in nx_g.nodes(data=True):
nx_g.nodes[node]["attributes"] = {key: convert_data_types(value) for key, value in attr_dict.items()}
#print("edges")
for edge in nx_g.edges(data=True):
source, target, attr_dict = edge
d = {key: convert_data_types(value) for key, value in attr_dict.items()}
nx_g.edges[source][target] = d
nx.write_graphml_lxml(nx_g, "gh.graphml") but it raises
What is the most efficient way to fix that? Kind regards PS : also posting at arangoml/networkx-adapter#96 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I think your nx_g.nodes[node]["attributes"] = {key: convert_data_types(value) for key, value in attr_dict.items()} will create a node attribute named Thank you :) |
Beta Was this translation helpful? Give feedback.
-
To keep track of what is going on, keep in miind the picture of the data structure as dict-of-dicts-of.......
In Graph/DiGraph:
In MultiGraph/MultiDiGraph:
Most of the bugs I see when looking at your code come from mistaking which level of the dict-of-dict-of-dict structure you are accessing. In addition, when you use Finally, graphml is fairly strict about what kinds of attribute values it can represent. You might try a different graph format if you want to use dicts or lists as the attribute values. (Though -- you should be able to use the name "type" for an attribute without trouble. The name of the attribute is not the problem -- it is the object type of the value that graphml is complaining about. |
Beta Was this translation helpful? Give feedback.
To keep track of what is going on, keep in miind the picture of the data structure as dict-of-dicts-of.......
For node attributes:
In Graph/DiGraph:
In MultiGraph/MultiDiGraph: