gpt4 book ai didi

java - 遍历器关系方向顺序neo4j java

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:24 24 4
gpt4 key购买 nike

我想遍历具有相同关系的图,但首先是传出关系,其次是传入关系(按此特定顺序)。我发现了

    traverse(Traverser.Order traversalOrder, 
StopEvaluator stopEvaluator,ReturnableEvaluator returnableEvaluator,
RelationshipType firstRelationshipType,Direction firstDirection,
RelationshipType secondRelationshipType,Direction secondDirection)

我还没有找到任何关于如何填充字段 traversalOrder stopEvaluator、returnableEvaluator 的示例

我的示例代码是:

for (Path position : graphDb.traversalDescription()
.relationships(Wikilections_user.RelTypes.Voted, Direction.OUTGOING)
.relationships(Wikilections_user.RelTypes.Voted, Direction.INCOMING)
.evaluator(Evaluators.fromDepth(1))
.evaluator(Evaluators.toDepth(2))
.evaluator(Evaluators.includeWhereEndNodeIs(node2))
.uniqueness(Uniqueness.RELATIONSHIP_PATH)
//.evaluator(Evaluators.excludeStartPosition())
.traverse(node1)) {

我想更改 .traverse(node1)) 部分,以便仅返回首先遇到传出关系,然后遇到传入关系的路径。这怎么可能?

最佳答案

对于更复杂的行为,您可以使用 TraversalDescription.expand() 提供自定义 PathExpander 。伪实现可能如下所示:

class MyPathExpander implements PathExpander {
Iterable<Relationship> expand(Path path, BranchState state) {
switch (path.length()) {
case 0:
return path.endNode().getRelationships(Wikilections_user.RelTypes.Voted, Direction.OUTGOING);
case 1:
return path.endNode().getRelationships(Wikilections_user.RelTypes.Voted, Direction.INCOMING)
default:
return Iterables.empty();

}
}
}

关于java - 遍历器关系方向顺序neo4j java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com