让我们假设一个非常简单的示例图表,其中人(作为节点)和KNOWS-和FRIEND_OF-之间的关系。 现在我想让每个节点知道一个随机的人并且是FRIEND_OF(这个或另一个人)。请考虑一下,我想使用遍历来检查这些关系,而不是简单的node.hasRelationship()。
因此,我将描述一个TraversalDescription,它检查其Evaluator中的路径长度,并在步骤1中选择KNOWS-relation。如果有一个I(自动)转到路径中连接的KNOWS节点,然后会退一步到传出节点。因此,我只检查path.length == 2何时传入KNOWS-relation,如果当前遍历节点具有path-startnode的id,则将continue-variable设置为true。
问题:我从未回到path-startnode(我检查过KNOWS关系的那个),它从未出现在评估者中;我也尝试使用不同的UNIQUENESS参数,但没有一个工作。
/编辑: 这是我的遍历描述(伪代码或多或少):
TraversalDescription td = Traversal.description()
.relationships(RelTypes.KNOWS, Direction.BOTH)
.relationships(RelTypes.FRIEND_OF, Direction.OUTGOING)
.uniqueness(Uniqueness.NONE)
.evaluate(new Evaluator(){
public Object evaluate(final Path path){
if (path.length == 0) return EXCLUDE_CONTINUE;
Relation currentRel = path.lastRelationship();
boolean continue = false;
boolean include = false;
if (path.length == 1){
// check for outgoing knows-relation
continue = currentRel.isType(KNOWS) && currentRel.startNode().getId == path.startNode().getId();
}
else if (path.length == 2){
// check for outgoing knows-relation to the original start node
// SECOND PART OF STATEMENT NEVER GETS TRUE!
toContinue = currentRel.isType(KNOWS) && currentRel.startNode().getId == path.startNode().getId();
}
else if (path.length == 3){
// ...
}
return Evaluation.of(toContinue, include);
}
答案 0 :(得分:0)
试
private static Traverser getHomies(final Node ofPerson) {
TraversalDescription td = Traversal.description().breadthFirst().relationships(RelTypes.KNOWS, Direction.INCOMING)
.relationships(RelTypes.FRIEND_OF, Direction.OUTGOING).evaluator(Evaluators.includingDepths(1, 2))
.evaluator(Evaluators.returnWhereLastRelationshipTypeIs(RelTypes.FRIEND_OF));
return td.traverse(ofPerson);
}
您的伪代码: