On 30 Jul 2010, at 15:35, [email protected] wrote:
> graphdb = neo4j.GraphDatabase("db")
> with graphdb.transaction:
> person = graphdb.node(name="Person")
> peter = graphdb.node(name="Peter")
> peter.IS_A(person)
> print peter['name']
> graphdb.shutdown()
Yes that works great... I think I'm having problems iterating the data once it
is in. I'm trying to save data in from a simple web crawler... A and B below
work OK. But C and D are hopeless. I'm assuming I don't HAVE to create a
Traversal class to simply iterate through records... or is that not so?
thanks, Tom
######## A. DO SOME SETUP STUFF ############
db = neo4j.GraphDatabase("example_db")
pages = db.index("pages", create=True) # create an index called 'pages'
url = 'http://pypi.python.org/'
def create_page(url, code='' ):
page_node = pages[url] # does this page exist yet?
if not page_node:
page_node = db.node(url=url, code=code) # create a page
pages[url] = page_node # Add to index
print "Created:" , url
else:
print "Exists already:" , url
return page_node
######## B. ADD SOME PAGES #################
with db.transaction:
create_page( 'http://pypi.python.org/' )
create_page( 'http://diveintopython.org/' )
create_page( 'http://pypi.python.org/' )
create_python( 'http://stackoverflow.com/questions/tagged/python')
######## C. NOW GET SOME OUT ###############
def get_one(url):
with db.transaction:
node = pages [url ]
if node == None:
print "Node is none!"
return node
print get_one( url ) # fails
######### D. TRY TO ITERATE ################
def list_all_pages( ):
'Just iterate through the pages to make sure the data in in there...
with db.transaction:
for node in db.node:
er...
def delete_one( url ):
''
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user