繁体   English   中英

Neo4j,py2neo,Neomodel-Cypher最短路径给出错误-TypeError:'NotImplementedType'对象不可调用

[英]Neo4j, py2neo, Neomodel - Cypher Shortest Path giving error - TypeError: 'NotImplementedType' object is not callable

我正在尝试在neomodel中运行以下Cypher查询:

MATCH (b1:Bal { text:'flame' }), (b2:Bal { text:'candle' }), 
p = shortestPath((b1)-[*..15]-(b2)) 
RETURN p

通过服务器控制台在neo4j上非常有效。 它返回具有两个关系连接的3个节点。 但是,当我在python中尝试以下操作时:

# Py2Neo version of cypher query in python
from py2neo import neo4j
graph_db = neo4j.GraphDatabaseService()
shortest_path_text = "MATCH (b1:Bal { text:'flame' }), (b2:Bal { text:'candle' }), p = shortestPath((b1)-[*..15]-(b2)) RETURN p"
results = neo4j.CypherQuery(graph_db, shortest_path_text).execute()

要么

# 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,这是有道理的。

主要问题是如何通过这两个方法使shortestPath查询起作用? python中是否有更好的方法? 还是密码是最好的方法?

编辑:
我也从这里尝试了以下给出相同错误的方法。

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

好的,我知道了。 我使用了[这里](基于@ nigel-small的答案的教程。

from py2neo import cypher

session = cypher.Session("http://localhost:7474")
tx = session.create_transaction()

tx.append("START beginning=node(3), end=node(16) MATCH p = shortestPath(beginning-[*..500]-end) RETURN p")
tx.execute()

返回:

[[Record(columns=(u'p',), values=(Path(Node('http://localhost:7474/db/data/node/3'), ('threads', {}), Node('http://localhost:7474/db/data/node/1'), ('threads', {}), Node('http://localhost:7474/db/data/node/2'), ('threads', {}), Node('http://localhost:7474/db/data/node/16')),))]]

从这里开始,我希望我将每个值都膨胀回我的neomodel对象和django中,以便于操作。 我到那里时将发布该代码。

您提供的错误消息是特定于neomodel的,并且由于没有任何支持在neomodel中膨胀py2neo Path对象而引起的错误消息。

但是,由于完全支持路径,因此在原始py2neo中应该可以正常工作,因此值得再次尝试。 Py2neo当然不会在新模型代码中引发错误。 我刚刚尝试了一个shortestPath查询,它返回了预期的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM