本文整理汇总了Python中py2neo.Graph.data方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.data方法的具体用法?Python Graph.data怎么用?Python Graph.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py2neo.Graph
的用法示例。
在下文中一共展示了Graph.data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Neo4j
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import data [as 别名]
class Neo4j():
graph = None
def __init__(self):
print("create neo4j class ...")
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="8313178")
def matchItembyTitle(self,value):
answer = self.graph.find_one(label="Item",property_key="title",property_value=value)
return answer
# 根据title值返回互动百科item
def matchHudongItembyTitle(self,value):
answer = self.graph.find_one(label="HudongItem",property_key="title",property_value=value)
return answer
# 根据entity的名称返回关系
def getEntityRelationbyEntity(self,value):
answer = self.graph.data("MATCH (entity1) - [rel] -> (entity2) WHERE entity1.title = \"" +value +"\" RETURN rel,entity2")
return answer
示例2: py2neo
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import data [as 别名]
def py2neo():
from py2neo import Graph, Path
# graph = Graph()
graph = Graph("http://localhost:7474/db/data/")
print graph.data("MATCH (o:Organisation) RETURN o LIMIT 4")
示例3: Graph
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import data [as 别名]
"""
# 方式1:
g = Graph(host="localhost", password='password',bolt=True, bolt_port=7689)
print g.data('match (n) return count(*)')
sys.exit(1)
"""
# 方式2: *****访问被代理或docker 容器中的 neo4j server的话,只能用这种方式 *********
# set up authentication parameters
http_port = "7476"
authenticate("localhost:"+http_port, "username", "password")
# connect to authenticated graph database
g = Graph("http://localhost:"+http_port+"/db/data/", bolt_port=7689)
g.data('match (n) return count(*)')
g.run('match (n) return count(*)').dump()
# import data in one transaction
tx = g.begin()
a = Node("Person", name="Alice")
b = Node("Person", name="Bob")
tx.create(a)
ab = Relationship(a, "KNOWS", b)
tx.create(ab)
#tx.commit()
print g.exists(ab)
# get nodes in one autocommit transaction
g.run("MATCH (a:Person) RETURN a.name, a.born LIMIT 4").data()
示例4: Neo4j
# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import data [as 别名]
class Neo4j():
graph = None
def __init__(self):
print("create neo4j class ...")
def connectDB(self):
self.graph = Graph("http://localhost:7474", username="neo4j", password="123456")
def matchItembyTitle(self,value):
answer = self.graph.find_one(label="Item",property_key="title",property_value=value)
return answer
# 根据title值返回互动百科item
def matchHudongItembyTitle(self,value):
answer = self.graph.find_one(label="HudongItem",property_key="title",property_value=value)
return answer
# 根据entity的名称返回关系
def getEntityRelationbyEntity(self,value):
answer = self.graph.data("MATCH (entity1) - [rel] -> (entity2) WHERE entity1.title = \"" +value +"\" RETURN rel,entity2")
return answer
#查找entity1及其对应的关系(与getEntityRelationbyEntity的差别就是返回值不一样)
def findRelationByEntity(self,entity1):
answer = self.graph.data("MATCH (n1:HudongItem {title:\""+entity1+"\"})- [rel] -> (n2) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\""+entity1+"\"})- [rel] -> (n2) RETURN n1,rel,n2" )
return answer
#查找entity2及其对应的关系
def findRelationByEntity2(self,entity1):
answer = self.graph.data("MATCH (n1)- [rel] -> (n2:HudongItem {title:\""+entity1+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1)- [rel] -> (n2:NewNode {title:\""+entity1+"\"}) RETURN n1,rel,n2" )
return answer
#根据entity1和关系查找enitty2
def findOtherEntities(self,entity,relation):
answer = self.graph.data("MATCH (n1:HudongItem {title:\"" + entity + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\"" + entity + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2) RETURN n1,rel,n2" )
return answer
#根据entity2和关系查找enitty1
def findOtherEntities2(self,entity,relation):
answer = self.graph.data("MATCH (n1)- [rel:RELATION {type:\""+relation+"\"}] -> (n2:HudongItem {title:\"" + entity + "\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1)- [rel:RELATION {type:\""+relation+"\"}] -> (n2:NewNode {title:\"" + entity + "\"}) RETURN n1,rel,n2" )
return answer
#根据两个实体查询它们之间的关系
def findRelationByEntities(self,entity1,entity2):
answer = self.graph.data("MATCH (n1:HudongItem {title:\"" + entity1 + "\"})- [rel] -> (n2:HudongItem{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:HudongItem {title:\"" + entity1 + "\"})- [rel] -> (n2:NewNode{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\"" + entity1 + "\"})- [rel] -> (n2:HudongItem{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\"" + entity1 + "\"})- [rel] -> (n2:NewNode{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
return answer
#查询数据库中是否有对应的实体-关系匹配
def findEntityRelation(self,entity1,relation,entity2):
answer = self.graph.data("MATCH (n1:HudongItem {title:\"" + entity1 + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2:HudongItem{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:HudongItem {title:\"" + entity1 + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2:NewNode{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\"" + entity1 + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2:HudongItem{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
if(len(answer) == 0):
answer = self.graph.data("MATCH (n1:NewNode {title:\"" + entity1 + "\"})- [rel:RELATION {type:\""+relation+"\"}] -> (n2:NewNode{title:\""+entity2+"\"}) RETURN n1,rel,n2" )
return answer