2014-10-02 154 views
0

我试图运行neomodel以下的Cypher查询:的Neo4j,py2neo,Neomodel - Cypher支架最短路径给错误 - 类型错误: 'NotImplementedType' 对象不是可调用

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中有更好的方法吗?或者是密码的最佳方式呢?

编辑:
我也试过以下从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 

回答

2

好吧,我想通了。我用[这里]教程(基于@奈杰尔小的回答

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更容易操作。将张贴代码,因为我到那里。

0

您所提供的错误信息是特定于neomodel,看起来已经提出,因为还没有对充气py2neo路径在neomodel对象的任何支持。

然而,这应该在原py2neo中正常工作,因为路径完全受支持,所以它可能值得再次尝试。 Py2neo当然不会从neomodel代码中引发错误。我刚刚尝试过shortestPath查询,它会按预期返回一个值。

+0

谢谢你Nigel。你能发布你的代码示例吗?我很好奇如何在python中运行原始py2neo密码查询正如我以为这是我在上面做的.. – raschwab 2014-10-03 02:54:18

相关问题