Search in sources :

Example 1 with PageRankVertexProgramStep

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;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) PageRankVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge)

Aggregations

GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 PageRankVertexProgramStep (org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep)1 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1