我尝试在neomodel中运行以下Cypher查询:
MATCH (b1:Bal { text:'flame' }), (b2:Bal { text:'candle' }),
p = shortestPath((b1)-[*..15]-(b2))
RETURN p
它通过服务器控制台在neo4j上运行得很好。它返回3个节点,其中两个关系连接在一起。但是,当我在python中尝试以下操作时:
^{pr2}$或者
# neomodel version of cypher query in python
from neomodel import db
shortest_path_text = "MATCH (b1:Bal { text:'flame' }), (b2:Bal { text:'candle' }), p = shortestPath((b1)-[*..15]-(b2)) RETURN p"
results, meta = db.cypher_query(shortest_path_text)
两者都给出了以下错误:
/Library/Python/2.7/site-packages/neomodel-1.0.1-py2.7.egg/neomodel/util.py in _hydrated(data)
73 elif obj_type == 'relationship':
74 return Rel(data)
---> 75 raise NotImplemented("Don't know how to inflate: " + repr(data))
76 elif neo4j.is_collection(data):
77 return type(data)([_hydrated(datum) for datum in data])
TypeError: 'NotImplementedType' object is not callable
考虑到neomodel是基于py2neo的,这是有意义的。在
主要的问题是如何让最短路径查询通过这两种方法之一工作?python中有更好的方法吗?或者说cypher是最好的方法吗?在
编辑:
我还尝试了来自here的以下操作,它给出了相同的错误。在
graph_db = neo4j.GraphDatabaseService()
query_string = "START beginning=node(1), end=node(4) \
MATCH p = shortestPath(beginning-[*..500]-end) \
RETURN p"
result = neo4j.CypherQuery(graph_db, query_string).execute()
for r in result:
print type(r) # r is a py2neo.util.Record object
print type(r.p) # p is a py2neo.neo4j.Path object
好吧,我想好了。我使用了这个教程(基于@nigelsmall的答案)。在
它返回:
^{pr2}$从这里开始,我希望我将把每个值放大回我的neomodel对象,并转换成django,以便于操作。我一到那里就把密码发出去。在
您提供的错误消息是特定于neomodel的,并且看起来已经被引发了,因为还没有任何支持在neomodel中膨胀py2neo路径对象。在
不过,这在原始py2neo中应该可以很好地工作,因为路径是完全支持的,所以可能值得再试一次。Py2neo当然不会在neomodel代码中引发错误。我刚刚尝试了一个
shortestPath
查询,它按预期返回一个值。在相关问题 更多 >
编程相关推荐