0

neomodel で次の Cypher クエリを実行しようとしています。

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

サーバーコンソールを介してneo4jでうまく機能します。2 つの関係が接続された 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
4

2 に答える 2

2

わかりました、私はそれを理解しました。@ 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 にインフレートすることを期待しています。そこに着いたら、そのコードを投稿します。

于 2014-10-03T03:56:15.290 に答える