使用py2neo4.x、neo4j3.5.3、python3.7.x
我有:图中的一个节点a
graph = Graph(
host="alpha.graph.domain.co",
auth=('neo4j', 'theActualPassword')
)
# grab the graph
a = Node("Type", url="https://en.wikipedia.org/wiki/Vivendi")
# create a local node with attributes I should be able to MERGE on
graph.merge(a,"Type","url")
# do said merge
graph.pull(a)
# pull any attributes (in my case Labels) that exist on the node in neo4j...
# ...but not on my local node
# better ways to do this also would be nice in the comments
relMatch = RelationshipMatcher(graph)
我想要的:有多少"CREATED"
关系连接到a
(在本例中为7)
我所做的:
x = relMatch.get(20943820943)
使用关系的一个id来查看什么是什么。它返回None
,即docs的意思
If no such Relationship is found, py:const:None is returned instead. Contrast with matcher[1234] which raises a KeyError if no entity is found.
这让我觉得我错了。在
另外:relMatch.match(a,"CREATED")
这会引起
raise ValueError("Nodes must be supplied as a Sequence or a Set")
告诉我我肯定读不好这些文件。在
不一定要使用这个类,这可能不是我所认为的,我如何计算有多少["CREATED"]
指向{
使用
RelationshipMatcher
,您只需使用len
进行计数。因此,如果我正确地阅读了您的代码,您将需要类似于:甚至更简单:
^{pr2}$(因为
graph.match
是RelationshipMatcher(graph)
的快捷方式)(None, a)
元组指定一对有序的节点(仅单向关系),其中起始节点是任意节点,结束节点是a
。使用len
只需计算匹配并返回一个计数。在下面的方法可以工作,并且比前面的实现更容易编写,但我认为这不是正确的方法。在
相关问题 更多 >
编程相关推荐