bruinend commented on issue #66:
URL: https://github.com/apache/age-viewer/issues/66#issuecomment-1327400977

   Hi
   This is how i build the connection with python:
   
   import age
   import pandas as pd
   from age.gen.AgtypeParser import *
   
   GRAPH_NAME = "metadata_ndh_graph_TEST4"
   DSN = "host=age port=5432 dbname=metadata_ndh user=root password=root"
   
   ag = age.connect(graph=GRAPH_NAME, dsn=DSN)
   ag.setGraph(GRAPH_NAME)
   
   Then i create the objects (i read data from an excel sheet and build the 
code).
   After the objects are created i create the links which are also defined in 
the excel sheet using the node_id attributes.
   
   The id attribute of the nodes are created in the database when creating the 
Node with the python script.
   
   This is python code to create node:
   
   for sheet in worksheets:
       if sheet != "link":        
           Metadata = pd.read_excel('KgMetaDataTemplatesv0.2_Joined.xlsx', 
sheet_name=sheet)        
           string = "CREATE (n:" + sheet + " {name: %s , node_id:%s , 
description: %s, status:%s}) RETURN n"
           for i, j in Metadata.iterrows():
               if j[0] in existing_node_ids: continue
               elif j[1] in existing_node_names:
                   print('Existing name found: ' + str(j[1]))
                   continue
               else:
                   cursor = ag.execCypher(string, params=(j[1],j[0],j[2],j[3]))
                   if showcreation == 1:
                       for row in cursor:
                           print("CREATED: ", row[0])
                   else: continue
           ag.commit()
   
   This is python code to create link (Edge):
   
   for i, j in Metadata_links.iterrows():
       if j[7] != "na":
           label = j[6] + ' , ' + j[7]
       else:
           label = j[6]
       if str(j[2]) == "IS_CONNECTED_TO":
           weight = 10
       elif str(j[2]) == "IS_EXECUTED_ON":
           weight = 5
       elif str(j[2]) == "IS_USING":
           weight = 3
       else: weight = 1
       if j[8] != "na":
           sequence = str(j[8])
           string = "MATCH (a: " + str(j[1]) +  "{node_id: '" + str(j[0]) + 
"'}), (b: " + str(j[4]) + " {node_id: '" + str(j[3]) + "'}) CREATE (a)-[r:" + 
str(j[2]) + " {weight: " + str(weight) + ", tag: '" + str(label) + "', 
sequence: '" + sequence + "'}]->(b)"        
       else:
           string = "MATCH (a: " + str(j[1]) +  "{node_id: '" + str(j[0]) + 
"'}), (b: " + str(j[4]) + " {node_id: '" + str(j[3]) + "'}) CREATE (a)-[r:" + 
str(j[2]) + " {weight: " + str(weight) + ", tag: '" + str(label) + "'}]->(b)"
       #print(string)
       cursor = ag.execCypher(string)
       #print (cursor)
       for row in cursor:
           print("CREATED: ", row[0])
       
   
   ag.commit()
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to