@Procedure(value = "mytraverser.pathIncludingAtLeastOneNode")
@Description("createIncludingAtLeastOneNode")
public void createIncludingAtLeastOneNode(@Name("startPoint") String startPoint, @Name("endPoint") String endPoint) {
try (Transaction tx = db.beginTx()) {
TraversalDescription td = db.traversalDescription().depthFirst()
.uniqueness(Uniqueness.NODE_PATH)
.uniqueness(Uniqueness.RELATIONSHIP_PATH)
.relationships(RelationshipTypes.rel, Direction.BOTH)
.evaluator(Evaluators.includingDepths(0, 10));
Traverser tr = td
.evaluator(Evaluators.includeWhereEndNodeIs(db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904013846978").getId())))
.evaluator(new PathEvaluator.Adapter() {
@Override
public Evaluation evaluate(Path path, BranchState branchState) {
if (path.length()==0) return Evaluation.INCLUDE_AND_CONTINUE;
else {
ArrayList<Node> listNode = new ArrayList<>();
for (Node n:path.nodes()){
listNode.add(n);
}
if (listNode.contains(db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904013846972").getId())) ||
listNode.contains(db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904013846980").getId())) ||
listNode.contains(db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904013846974").getId()))) {
return Evaluation.INCLUDE_AND_CONTINUE;
} else {
return Evaluation.EXCLUDE_AND_CONTINUE;
}
}
}
})
.sort(new PathSorting("weight"))
.traverse(db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904413851091").getId()));
createPath(tr, "IncludingAtLeastOneNode");
tx.success();
}
}
db.getNodeById(db.findNode(Labels.nodes, "id", "9149892904013846978").getId()))but
db.findNode(Labels.nodes, "id", "9149892904013846978")
public class PathSorting implements Comparator<Path>{
private String sortType;
public PathSorting(String sortType){
this.sortType=sortType;
}
@Override
public int compare (Path path1, Path path2){
switch (sortType){
case "length" :
if (path1.length()!=path2.length()) {
return path1.length()<path2.length() ? -1 : 1 ;
}else return 0;
case "weight" :
long p1Weight_0 = 0, p2Weight_0 = 0;
for (Relationship r : path1.relationships()){
p1Weight_0 += (long)r.getProperty("weight");
}
for (Relationship r : path2.relationships()){
p2Weight_0 += (long)r.getProperty("weight");
}
if (p1Weight_0!=p2Weight_0) {
return p1Weight_0<p2Weight_0 ? -1 : 1 ;
}
else return 0;
default:return 0;
}
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
>> To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.