如何从py2neo图形查询返回节点?

时间:2016-07-20 14:27:36

标签: python-2.7 neo4j py2neo

我如何使用结果并将其转换为graph.run的节点或关系,例如。

result = graph.run('match (x:Person) return x')

如何将结果转换为Py2neo v3节点/关系?

3 个答案:

答案 0 :(得分:2)

从查询中获取节点的最简单方法是使用//... editText.setText(getSpannedText(editText.getText(), `u`, `r`)); //... private static SpannableString getSpannedText(String text, char... triggers) { SpannableString spanString = new SpannableString(text); for (int i = 0; i < spanString.length(); i++) { for (char trigger : triggers) { if (spanString.charAt(i) == trigger) { spanString.setSpan(new ForegroundColorSpan(Color.CYAN), i, i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return spanString; } 代替import Foundation import MBProgressHUD public class ShowLoading{ let view = UIView() func show(){ let loadingNotification = MBProgressHUD.showHUDAddedTo(view, animated: true) loadingNotification.color = UIColor.blueColor() loadingNotification.mode = MBProgressHUDMode.Indeterminate loadingNotification.labelText = MyConstants.LOADING_TEXT } func hide(){ MBProgressHUD.hideAllHUDsForView(view, animated: true) } }

evaluate

此方法返回返回的第一个记录的第一个值。在这种情况下,您的节点。

http://py2neo.org/v3/database.html#py2neo.database.Graph.evaluate

答案 1 :(得分:0)

对于Py2neo 1.6.7,您可以使用GraphDatabaseService方法find来迭代一组带标签的节点,可选择按属性键和值进行过滤,例如:

from py2neo import neo4j
# pass the base URI of your neo4j database as arg
graph_db = neo4j.GraphDatabaseService('http://localhost:7474/db/data/') 
resultset = graph_db.find('Person')

对于Py2neo 3.0,您可以使用Graph方法find生成具有给定标签的所有节点,可选择按属性键进行过滤,值。所以,举个例子:

from py2neo import Graph
graph_db = Graph("http://localhost:7474/db/data/")
resultset = graph_db.find('Person')

最后,来自官方文档的重要警告

  

另请注意,Py2neo仅在Linux下开发和测试   使用标准的CPython发行版。虽然其他操作系统和Python发行版可能有效,但是不支持这些发行版。

答案 2 :(得分:0)

另一种方法是根据cypher.execute返回的生成器生成一个列表。

result = graph.cypher.execute('match (x:Person) return x')
nodes = [n for n in result]

请注意,像这样查询的节点是记录。要访问真实节点,请选择每个对象的属性r。 :

l_nodes = map(lambda node : node.r, nodes)