-
Notifications
You must be signed in to change notification settings - Fork 0
/
usingNeo4j.py
40 lines (29 loc) · 1.26 KB
/
usingNeo4j.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding: utf-8 -*-
from getData import *
from py2neo import Graph,node,Relationship
from neo4j import Node
class usingNeo4j:
def __init__(self):
self.url="http://user:password@ip:7474/db/data/"
self.graph = Graph(self.url)
self.graph.cypher.execute("CREATE (SJTU:University {name:'上海交通大学',url:'www.sjtu.edu.cn'})",)
def createNode(self,id,what,name,url):
# cmd="No extension found at path %r on graph <%s>" % (name, url)
cmd="CREATE (%s:`%s` {name:'%s',url:'%s'})" % (id,what,name,url)
print cmd
self.graph.cypher.execute(cmd)
def createRelation(self,node1,relation,node2):
cmd="MATCH (a:`%s`),(b:`%s`) CREATE (b)-[:`%s`]->(a) RETURN a,b" % (node1,node2,relation)
print cmd
self.graph.cypher.execute(cmd)
# cmd2="CREATE (%s)-[r:`%s`]->(%s)" % (node1,relation,node2)
# Relationship(node1,relation,node2)
def cmd(self,cmd):
print cmd
self.graph.cypher.execute(cmd)
def showAll(self):
self.graph.cypher.execute("MATCH (n) RETURN n")
def deleteAll(self):
self.graph.cypher.execute("MATCH (n) DETACH DELETE n")
#def relationShip(self,node1,node2,relation):