I am currently working in a doctoral program and i am interested about Py2neo, so I am using it in order to perform some experiments using social graphs. However I got into newbie troubles. Excuse me for asking these simple questions.
I got a xml dataset containing data about publications of a jornal, I have converted it into a csv table, there are about 700 records and each record is composed by four fiels: date, title, keywords, author. So my first question is how to create a graph from this table programatically. I considered writing a python script which loops the csv table, reads for each row and columns fields and writes into nodes. +++++++++++++++++++++++++++++++++++++++++++++ Code +++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/env python
#
import csv
from py2neo import neo4j, cypher
from py2neo import node, rel
# calls database service of Neo4j
#
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
#
# Create nodes and relationships from a csv table
# since it's a csv table, a reader must be invoked
ifile = open('testeout5_cp.csv', "rb")
reader = csv.reader(ifile)
# clear database
graph_db.clear()
rownum = 0
for row in reader:
colnum = 0
for col in row:
titulo, autor, rel = graph_db.create(
{"titulo": col[1]}, {"autor": col[3]}, (1, "eh_autor_de", 0)
)
print(titulo, autor)
rownum += 1
ifile.close()
================ I got this output (Fragment): Python 2.7.5 (default, Aug 22 2013, 09:31:58) [GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on aires2, Standard
(Node('http://localhost:7474/db/data/node/10392'), Node('http://localhost:7474/db/data /node/10393')) (Node('http://localhost:7474/db/data/node/10394'), Node('http://localhost:7474/db/data/node/10395')) (Node('http://localhost:7474/db/data/node/10396'), Node('http://localhost:7474/db/data/node/10397')) (Node('http://localhost:7474/db/data/node/10398'), Node('http://localhost:7474/db/data/node/10399')) (Node('http://localhost:7474/db/data/node/10400'), Node('http://localhost:7474/db/data/node/10401')) (Node('http://localhost:7474/db/data/node/10402'), Node('http://localhost:7474/db/data/node/10403')) (Node('http://localhost:7474/db/data/node/10404'), Node('http://localhost:7474/db/data/node/10405'))
========= What is wrong?