use of org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep in project GraphScope by alibaba.
the class PageRankVertexProgramTreeNode method createOperatorArgument.
private Message.Value.Builder createOperatorArgument() {
Message.Value.Builder valueBuilder = Message.Value.newBuilder();
Message.ProgramPageRankArg.Builder pageRankArgBuilder = Message.ProgramPageRankArg.newBuilder();
String pageRankProperty = ReflectionUtils.getFieldValue(PageRankVertexProgramStep.class, pageRankVertexProgramStep, "pageRankProperty");
double alpha = ReflectionUtils.getFieldValue(PageRankVertexProgramStep.class, pageRankVertexProgramStep, "alpha");
int times = ReflectionUtils.getFieldValue(PageRankVertexProgramStep.class, pageRankVertexProgramStep, "times");
Traversal.Admin<Vertex, Edge> edgeTraversal = pageRankVertexProgramStep.getLocalChildren().get(0);
if (pageRankProperty.equals(PageRankVertexProgram.PAGE_RANK)) {
pageRankProperty = PAGERANK;
}
pageRankArgBuilder.setPropertyPrId(SchemaUtils.getPropId(pageRankProperty, schema));
checkArgument(alpha > 0 && alpha < 1, "alpha must > 0 and < 1 for PageRank");
pageRankArgBuilder.setAlpha(alpha);
checkArgument(times > 0, "iteration must > 0 for PageRank");
pageRankArgBuilder.setLoopLimit(times);
List<Step> steps = edgeTraversal.getSteps();
// supports with(PageRank.edges,outE('knows'))
VertexStep vstep = (VertexStep) steps.get(0);
String[] labels = vstep.getEdgeLabels();
for (String edgeLabel : labels) {
GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
pageRankArgBuilder.addEdgeLabels(edgeType.getLabelId());
}
if (Direction.BOTH.equals(vstep.getDirection())) {
pageRankArgBuilder.setDirection(Message.EdgeDirection.DIR_NONE);
} else if (Direction.IN.equals(vstep.getDirection())) {
pageRankArgBuilder.setDirection(Message.EdgeDirection.DIR_IN);
} else if (Direction.OUT.equals(vstep.getDirection())) {
pageRankArgBuilder.setDirection(Message.EdgeDirection.DIR_OUT);
} else {
checkArgument(false, "direction must be in/out/both for pagerank");
}
for (int i = 1; i < steps.size(); ++i) {
Step step = steps.get(i);
if (step instanceof HasStep) {
HasContainer hasContainer = (HasContainer) ((HasStep) step).getHasContainers().get(0);
Object value = hasContainer.getPredicate().getValue();
GraphEdge edgeType = (GraphEdge) schema.getElement(value.toString());
pageRankArgBuilder.addEdgeLabels(edgeType.getLabelId());
}
}
valueBuilder.setPayload(pageRankArgBuilder.build().toByteString());
return valueBuilder;
}
Aggregations