create apache age graph from networkx graph

Question:

I’ve started using apache age and was wondering if there is a cool way to directly put networkx graph into the apache age database?

I’m using a workaround to get the edged and nodes associated with their attributes to insert them in the apache age using for loop, is there a better and quicker way?

Asked By: Amgad Abdallah

||

Answers:

This feature is currently under development. But for sure, in the future, you will be seeing more such robust and effective features.

For now, you can follow the following raw-code structure to put networkx graph into the apache-age database and then visualize it on age-viewer.

#import apache-age python driver and networkx 
from apache-age import GraphDatabase
import networkx as nx

#connect to the database
driver = GraphDatabase.driver(**xyz**->argument to connect to age database**) 

query = "
SELECT * FROM cypher('graph_name', $$
    MATCH p = (actor {name: 'Willam Defoe'})-[:ACTED_IN*2]-(co_actor)
    RETURN relationships(p)
$$) as (r agtype);"

# run the query
    result = driver.run(query)

# iterate through the result
# find the nodes and edges from result
# and add them to the nx.graph
# This bit doesn't work

G = nx.Graph(result)

Note: Code is not the executable, I have provided just the raw-structure.

Answered By: Kamlesh Kumar

The feature is currently not available. At the moment other developments have higher priority.

With that being said, you can request the feature in the Github repository:

https://github.com/apache/age

If you are lucky it may get accepted.

EDI:T
Thanks to Kamlesh in the comments for this update.

So you can see it is currently open for research and development

Answered By: RU-D

To be able to a NetworkX graph into Apache AGE, the graph data needs to be converted to a format that that is compatible with the graph tables used by apache AGE one of the possible approaches could be to loop over the networkx graph that includes nodes and edges and input them into the database.

That being said, if the graph is large, iterating over the whole graph can be time consuming, in this case, there are a few approaches that can improve the performance:

  1. Parallel Processing
  2. Data Conversion
  3. Batch Insertion

These methods will help improve the performance and efficiency of the transfer. Hope this helps!

Answered By: Haseeb Ashraf