简体   繁体   English

Neo4J Traversal跳过关系类型

[英]Neo4J Traversal Skipping Relationship Types

I am performing a custom traversal in Neo4J, using my own evaluator. 我正在使用我自己的评估器在Neo4J中执行自定义遍历。 In the traversal are two nodes, connected by two different relationships. 在遍历中有两个节点,由两个不同的关系连接。 What I'm seeing is that only one of the two relationships will be walked during the traversal. 我所看到的是,在遍历过程中只会走两条关系中的一条。

However, my custom evaluation changes its behavior based on whether both relationships are present. 但是,我的自定义评估会根据两个关系是否存在来更改其行为。

It seems like during a traversal, Neo4J maintains a set of visited nodes, and if a candidate path ends at a node that has already been visited, then that path is never sent to my evaluator. 似乎在遍历期间,Neo4J维护一组访问节点,并且如果候选路径在已经访问过的节点处结束,则该路径永远不会发送给我的评估者。 Is there a way around this? 有没有解决的办法? How can I have a custom evaluator examine every possible path to the nodes? 如何让自定义评估程序检查节点的每个可能路径?

Here's a quick example: 这是一个简单的例子:

Say that the graph looks like this: 假设图形如下所示:

             E----D----A====B----C

The traversal begins at A. A has two different relationships tying it to B (of two different types). 遍历从A开始.A有两种不同的关系将它与B(两种不同类型)联系起来。 All of the remaining nodes are connected by only 1 relationship. 所有剩余节点仅通过1个关系连接。 The goal of the evaluator is to return AD, AB, and BC, but not DE. 评估者的目标是返回AD,AB和BC,但不返回DE。 The determination that BC is valid comes from the fact that there are two relationships between A and B. BC有效的确定来自A和B之间存在两种关系的事实。

How can this be solved? 怎么解决这个问题?

You may need to think your use case through a bit more carefully. 您可能需要更仔细地考虑您的用例。

One suggestion is that when you use the traversal framework in java , basically you can build a TraversalDescription and then iterate through what comes back from it by relationships, rather than by Paths or by Nodes. 一个建议是,当你在java中使用遍历框架时 ,基本上你可以构建一个TraversalDescription ,然后迭代通过关系而不是路径或节点从它返回的内容。 If your primary complaint is that each node is visited only once, you can change the TraversalDescription to specify RELATIONSHIP_GLOBAL guaranteeing that all relationships will be followed, whether or not that causes you to hit a node more than once. 如果您的主要抱怨是每个节点只被访问过一次,您可以更改TraversalDescription以指定RELATIONSHIP_GLOBAL,保证将遵循所有关系,无论这是否会导致您多次访问节点。

More broadly, traversers don't tend to go over the same material more than once because if they did, you'd need to be ultra careful about specifying a termination condition. 更广泛地说,遍历者不会多次使用相同的材​​料,因为如果他们这样做,则需要非常小心地指定终止条件。 If hitting certain nodes or relationships more than once is OK, when do you know that you're done? 如果多次击中某些节点或关系是可以的,你什么时候知道你已经完成了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM