如何打印图形中包含的关系类型

时间:2018-10-01 08:50:21

标签: python neo4j py2neo

这是py2neo(v4)的某些基本功能的另一个基本问题,这些功能无法直观地工作。

  

如何获取/打印现有关系类型的列表?

documentation's graph section of the database page中,有一种方法relationship_types应该返回“当前在图形中定义的一组关系类型。”,我希望它能像这样工作:

print(graph.relationship_types)

但是出现错误'Graph' object has no attribute 'relationship_types'

但是如果是这样的话,那具有什么属性呢?在该页面(或我能找到的其他任何地方)上没有使用此方法的示例,出于类似原因,我在使用py2neo的许多基本功能时遇到了麻烦。

2 个答案:

答案 0 :(得分:0)

您提到的属性不仅在V4中,而且在V3中也是如此。 可能是您没有正确使用该属性。

这是一个非常简单的示例,对我有用(v3.1.2)。同样的代码也可以在V4.1.0上运行。

from py2neo import Graph

graph = Graph("http://localhost:7474", username="USERNAME", password="PASSWORD")

print(graph.relationship_types)

答案 1 :(得分:0)

for rel in grap.ralationships:
    print('from:',rel.start_node)
    print('to:',rel.end_node)
    print('drum role.... ding ding ding Rel TYPE:',type(r).__name__) 

相关类型列表:

set([type(r).__name__ for r in in graph.ralationships])

希望这对某些人有帮助