简体   繁体   English

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

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

I'm trying to run the following Cypher query in neomodel: 我正在尝试在neomodel中运行以下Cypher查询:

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

which works great on neo4j via the server console. 通过服务器控制台在neo4j上非常有效。 It returns 3 nodes with two relationships connecting. 它返回具有两个关系连接的3个节点。 However, when I attempt the following in python: 但是,当我在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()

or 要么

# 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)

both give the following error: 都给出以下错误:

     /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

which makes sense considering neomodel is based on py2neo. 考虑到neomodel基于py2neo,这是有道理的。

The main question is how to get a shortestPath query to work via either of these? 主要问题是如何通过这两个方法使shortestPath查询起作用? Is there a better method within python? python中是否有更好的方法? or is cypher the best way to do it? 还是密码是最好的方法?

edit: 编辑:
I also tried the following from here which gave the same error. 我也从这里尝试了以下给出相同错误的方法。

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

Ok, I figured it out. 好的,我知道了。 I used the tutorial [here]( based on @nigel-small 's answer. 我使用了[这里](基于@ 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()

which returned: 返回:

[[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')),))]]

From here, I expect I'll inflate each of the values back to my neomodel objects and into django for easier manipulation. 从这里开始,我希望我将每个值都膨胀回我的neomodel对象和django中,以便于操作。 Will post that code as I get there. 我到那里时将发布该代码。

The error message you provide is specific to neomodel and looks to have been raised as there is not yet any support for inflating py2neo Path objects in neomodel. 您提供的错误消息是特定于neomodel的,并且由于没有任何支持在neomodel中膨胀py2neo Path对象而引起的错误消息。

This should however work fine in raw py2neo as paths are fully supported, so it may be worth trying that again. 但是,由于完全支持路径,因此在原始py2neo中应该可以正常工作,因此值得再次尝试。 Py2neo certainly wouldn't raise an error from within the neomodel code. Py2neo当然不会在新模型代码中引发错误。 I've just tried a shortestPath query myself and it returns a value as expected. 我刚刚尝试了一个shortestPath查询,它返回了预期的值。

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

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