{"action":"created","comment":{"url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/comments/242041364","pull_request_review_id":185451960,"id":242041364,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MjA0MTM2NA==","diff_hunk":"@@ -0,0 +1,154 @@\n+/*\n+ * Copyright 2017 HugeGraph Authors\n+ *\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements. See the NOTICE file distributed with this\n+ * work for additional information regarding copyright ownership. The ASF\n+ * licenses this file to You under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package com.baidu.hugegraph.traversal.algorithm;\n+\n+import java.util.HashMap;\n+import java.util.Map;\n+import java.util.Set;\n+\n+import org.apache.tinkerpop.gremlin.structure.Vertex;\n+\n+import com.baidu.hugegraph.HugeGraph;\n+import com.baidu.hugegraph.backend.id.Id;\n+import com.baidu.hugegraph.schema.EdgeLabel;\n+import com.baidu.hugegraph.schema.VertexLabel;\n+import com.baidu.hugegraph.structure.HugeVertex;\n+import com.baidu.hugegraph.traversal.optimize.HugeTraverser;\n+import com.baidu.hugegraph.type.define.Directions;\n+import com.baidu.hugegraph.util.E;\n+import com.google.common.collect.ImmutableSet;\n+\n+public class RankAlgorithm extends HugeTraverser {\n+\n+    private final double alpha;\n+    private final long maxDepth;\n+\n+    public RankAlgorithm(HugeGraph graph, double alpha, long maxDepth) {\n+        super(graph);\n+        this.alpha = alpha;\n+        this.maxDepth = maxDepth;\n+    }\n+\n+    public Map<Id, Double> personalRank(Id sourceId, String label) {\n+        Id labelId = this.graph().edgeLabel(label).id();\n+\n+        long depth = 0;\n+        Set<Id> seeds = ImmutableSet.of(sourceId);\n+        Map<String, Directions> labelDirs = buildLabelDirs(sourceId, label);\n+        Map<Id, Double> ranks = new HashMap<>();\n+        ranks.put(sourceId, 1.0);\n+        while (++depth <= this.maxDepth) {\n+            Map<Id, Double> rankIncrs = this.getRankIncrs(seeds, labelDirs,\n+                                                          labelId, ranks);\n+            ranks = this.compensateSourceVertex(sourceId, rankIncrs);\n+            seeds = ranks.keySet();\n+        }\n+        return ranks;\n+    }\n+\n+    private Map<Id, Double> compensateSourceVertex(Id sourceId,\n+                                                   Map<Id, Double> rankIncrs) {\n+        double sourceRank = rankIncrs.getOrDefault(sourceId, 0.0);\n+        sourceRank += (1 - this.alpha);\n+        rankIncrs.put(sourceId, sourceRank);\n+        return rankIncrs;\n+    }\n+\n+    public Map<Id, Double> neighborRank(Id sourceId, String label) {\n+        Id labelId = this.graph().edgeLabel(label).id();\n+\n+        long depth = 0;\n+        Set<Id> seeds = ImmutableSet.of(sourceId);\n+        Map<String, Directions> labelDirs = buildLabelDirs(sourceId, label);\n+        Map<Id, Double> ranks = new HashMap<>();\n+        ranks.put(sourceId, 1.0);\n+        while (++depth <= this.maxDepth) {\n+            Map<Id, Double> rankIncrs = this.getRankIncrs(seeds, labelDirs,\n+                    labelId, ranks);\n+            this.combineIncrement(seeds, ranks, rankIncrs);\n+            seeds = rankIncrs.keySet();\n+        }\n+        return ranks;\n+    }\n+\n+    private void combineIncrement(Set<Id> seeds, Map<Id, Double> ranks,\n+                                  Map<Id, Double> rankIncrs) {\n+        // Update the rank of the neighbor vertices\n+        for (Map.Entry<Id, Double> entry : rankIncrs.entrySet()) {\n+            double oldRank = ranks.getOrDefault(entry.getKey(), 0.0);\n+            double incr = entry.getValue();","path":"hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/RankAlgorithm.java","position":96,"original_position":96,"commit_id":"c84cab64fba1b4327bc41891e6d784ad45ad2f45","original_commit_id":"c84cab64fba1b4327bc41891e6d784ad45ad2f45","user":{"login":"javeme","id":9625821,"node_id":"MDQ6VXNlcjk2MjU4MjE=","avatar_url":"https://avatars3.githubusercontent.com/u/9625821?v=4","gravatar_id":"","url":"https://api.github.com/users/javeme","html_url":"https://github.com/javeme","followers_url":"https://api.github.com/users/javeme/followers","following_url":"https://api.github.com/users/javeme/following{/other_user}","gists_url":"https://api.github.com/users/javeme/gists{/gist_id}","starred_url":"https://api.github.com/users/javeme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javeme/subscriptions","organizations_url":"https://api.github.com/users/javeme/orgs","repos_url":"https://api.github.com/users/javeme/repos","events_url":"https://api.github.com/users/javeme/events{/privacy}","received_events_url":"https://api.github.com/users/javeme/received_events","type":"User","site_admin":false},"body":"double incrRank = ...\r\ndouble newRank = oldRank + incrRank","created_at":"2018-12-17T07:05:56Z","updated_at":"2018-12-17T07:07:38Z","html_url":"https://github.com/hugegraph/hugegraph/pull/274#discussion_r242041364","pull_request_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/comments/242041364"},"html":{"href":"https://github.com/hugegraph/hugegraph/pull/274#discussion_r242041364"},"pull_request":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274"}}},"pull_request":{"url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274","id":237271080,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM3MjcxMDgw","html_url":"https://github.com/hugegraph/hugegraph/pull/274","diff_url":"https://github.com/hugegraph/hugegraph/pull/274.diff","patch_url":"https://github.com/hugegraph/hugegraph/pull/274.patch","issue_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/274","number":274,"state":"open","locked":false,"title":"Add personalrank  and neighborrank RESTful API","user":{"login":"Linary","id":9151831,"node_id":"MDQ6VXNlcjkxNTE4MzE=","avatar_url":"https://avatars0.githubusercontent.com/u/9151831?v=4","gravatar_id":"","url":"https://api.github.com/users/Linary","html_url":"https://github.com/Linary","followers_url":"https://api.github.com/users/Linary/followers","following_url":"https://api.github.com/users/Linary/following{/other_user}","gists_url":"https://api.github.com/users/Linary/gists{/gist_id}","starred_url":"https://api.github.com/users/Linary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Linary/subscriptions","organizations_url":"https://api.github.com/users/Linary/orgs","repos_url":"https://api.github.com/users/Linary/repos","events_url":"https://api.github.com/users/Linary/events{/privacy}","received_events_url":"https://api.github.com/users/Linary/received_events","type":"User","site_admin":false},"body":"Change-Id: Ifc65c488aac51111551e78bf3deb5790c5e83491","created_at":"2018-12-10T10:37:15Z","updated_at":"2018-12-17T07:07:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"400ec3065c70598d1a4ed0b387c1e74ecf44a217","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274/commits","review_comments_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274/comments","review_comment_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/274/comments","statuses_url":"https://api.github.com/repos/hugegraph/hugegraph/statuses/c84cab64fba1b4327bc41891e6d784ad45ad2f45","head":{"label":"hugegraph:neighbor-rank","ref":"neighbor-rank","sha":"c84cab64fba1b4327bc41891e6d784ad45ad2f45","user":{"login":"hugegraph","id":40235049,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMjM1MDQ5","avatar_url":"https://avatars0.githubusercontent.com/u/40235049?v=4","gravatar_id":"","url":"https://api.github.com/users/hugegraph","html_url":"https://github.com/hugegraph","followers_url":"https://api.github.com/users/hugegraph/followers","following_url":"https://api.github.com/users/hugegraph/following{/other_user}","gists_url":"https://api.github.com/users/hugegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/hugegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugegraph/subscriptions","organizations_url":"https://api.github.com/users/hugegraph/orgs","repos_url":"https://api.github.com/users/hugegraph/repos","events_url":"https://api.github.com/users/hugegraph/events{/privacy}","received_events_url":"https://api.github.com/users/hugegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":141376301,"node_id":"MDEwOlJlcG9zaXRvcnkxNDEzNzYzMDE=","name":"hugegraph","full_name":"hugegraph/hugegraph","private":false,"owner":{"login":"hugegraph","id":40235049,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMjM1MDQ5","avatar_url":"https://avatars0.githubusercontent.com/u/40235049?v=4","gravatar_id":"","url":"https://api.github.com/users/hugegraph","html_url":"https://github.com/hugegraph","followers_url":"https://api.github.com/users/hugegraph/followers","following_url":"https://api.github.com/users/hugegraph/following{/other_user}","gists_url":"https://api.github.com/users/hugegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/hugegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugegraph/subscriptions","organizations_url":"https://api.github.com/users/hugegraph/orgs","repos_url":"https://api.github.com/users/hugegraph/repos","events_url":"https://api.github.com/users/hugegraph/events{/privacy}","received_events_url":"https://api.github.com/users/hugegraph/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/hugegraph/hugegraph","description":"HugeGraph Database core component, including graph engine, API, and built-in backends","fork":false,"url":"https://api.github.com/repos/hugegraph/hugegraph","forks_url":"https://api.github.com/repos/hugegraph/hugegraph/forks","keys_url":"https://api.github.com/repos/hugegraph/hugegraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hugegraph/hugegraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hugegraph/hugegraph/teams","hooks_url":"https://api.github.com/repos/hugegraph/hugegraph/hooks","issue_events_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/events{/number}","events_url":"https://api.github.com/repos/hugegraph/hugegraph/events","assignees_url":"https://api.github.com/repos/hugegraph/hugegraph/assignees{/user}","branches_url":"https://api.github.com/repos/hugegraph/hugegraph/branches{/branch}","tags_url":"https://api.github.com/repos/hugegraph/hugegraph/tags","blobs_url":"https://api.github.com/repos/hugegraph/hugegraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hugegraph/hugegraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hugegraph/hugegraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/hugegraph/hugegraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hugegraph/hugegraph/statuses/{sha}","languages_url":"https://api.github.com/repos/hugegraph/hugegraph/languages","stargazers_url":"https://api.github.com/repos/hugegraph/hugegraph/stargazers","contributors_url":"https://api.github.com/repos/hugegraph/hugegraph/contributors","subscribers_url":"https://api.github.com/repos/hugegraph/hugegraph/subscribers","subscription_url":"https://api.github.com/repos/hugegraph/hugegraph/subscription","commits_url":"https://api.github.com/repos/hugegraph/hugegraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/hugegraph/hugegraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/hugegraph/hugegraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/hugegraph/hugegraph/contents/{+path}","compare_url":"https://api.github.com/repos/hugegraph/hugegraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hugegraph/hugegraph/merges","archive_url":"https://api.github.com/repos/hugegraph/hugegraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hugegraph/hugegraph/downloads","issues_url":"https://api.github.com/repos/hugegraph/hugegraph/issues{/number}","pulls_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls{/number}","milestones_url":"https://api.github.com/repos/hugegraph/hugegraph/milestones{/number}","notifications_url":"https://api.github.com/repos/hugegraph/hugegraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hugegraph/hugegraph/labels{/name}","releases_url":"https://api.github.com/repos/hugegraph/hugegraph/releases{/id}","deployments_url":"https://api.github.com/repos/hugegraph/hugegraph/deployments","created_at":"2018-07-18T03:30:20Z","updated_at":"2018-12-14T08:58:40Z","pushed_at":"2018-12-17T06:54:23Z","git_url":"git://github.com/hugegraph/hugegraph.git","ssh_url":"git@github.com:hugegraph/hugegraph.git","clone_url":"https://github.com/hugegraph/hugegraph.git","svn_url":"https://github.com/hugegraph/hugegraph","homepage":null,"size":5183,"stargazers_count":552,"watchers_count":552,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":57,"mirror_url":null,"archived":false,"open_issues_count":96,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":57,"open_issues":96,"watchers":552,"default_branch":"master"}},"base":{"label":"hugegraph:master","ref":"master","sha":"73d1f2dd4a461f7612083e69d7ac7240d36a6ef1","user":{"login":"hugegraph","id":40235049,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMjM1MDQ5","avatar_url":"https://avatars0.githubusercontent.com/u/40235049?v=4","gravatar_id":"","url":"https://api.github.com/users/hugegraph","html_url":"https://github.com/hugegraph","followers_url":"https://api.github.com/users/hugegraph/followers","following_url":"https://api.github.com/users/hugegraph/following{/other_user}","gists_url":"https://api.github.com/users/hugegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/hugegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugegraph/subscriptions","organizations_url":"https://api.github.com/users/hugegraph/orgs","repos_url":"https://api.github.com/users/hugegraph/repos","events_url":"https://api.github.com/users/hugegraph/events{/privacy}","received_events_url":"https://api.github.com/users/hugegraph/received_events","type":"Organization","site_admin":false},"repo":{"id":141376301,"node_id":"MDEwOlJlcG9zaXRvcnkxNDEzNzYzMDE=","name":"hugegraph","full_name":"hugegraph/hugegraph","private":false,"owner":{"login":"hugegraph","id":40235049,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMjM1MDQ5","avatar_url":"https://avatars0.githubusercontent.com/u/40235049?v=4","gravatar_id":"","url":"https://api.github.com/users/hugegraph","html_url":"https://github.com/hugegraph","followers_url":"https://api.github.com/users/hugegraph/followers","following_url":"https://api.github.com/users/hugegraph/following{/other_user}","gists_url":"https://api.github.com/users/hugegraph/gists{/gist_id}","starred_url":"https://api.github.com/users/hugegraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugegraph/subscriptions","organizations_url":"https://api.github.com/users/hugegraph/orgs","repos_url":"https://api.github.com/users/hugegraph/repos","events_url":"https://api.github.com/users/hugegraph/events{/privacy}","received_events_url":"https://api.github.com/users/hugegraph/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/hugegraph/hugegraph","description":"HugeGraph Database core component, including graph engine, API, and built-in backends","fork":false,"url":"https://api.github.com/repos/hugegraph/hugegraph","forks_url":"https://api.github.com/repos/hugegraph/hugegraph/forks","keys_url":"https://api.github.com/repos/hugegraph/hugegraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hugegraph/hugegraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hugegraph/hugegraph/teams","hooks_url":"https://api.github.com/repos/hugegraph/hugegraph/hooks","issue_events_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/events{/number}","events_url":"https://api.github.com/repos/hugegraph/hugegraph/events","assignees_url":"https://api.github.com/repos/hugegraph/hugegraph/assignees{/user}","branches_url":"https://api.github.com/repos/hugegraph/hugegraph/branches{/branch}","tags_url":"https://api.github.com/repos/hugegraph/hugegraph/tags","blobs_url":"https://api.github.com/repos/hugegraph/hugegraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hugegraph/hugegraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hugegraph/hugegraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/hugegraph/hugegraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hugegraph/hugegraph/statuses/{sha}","languages_url":"https://api.github.com/repos/hugegraph/hugegraph/languages","stargazers_url":"https://api.github.com/repos/hugegraph/hugegraph/stargazers","contributors_url":"https://api.github.com/repos/hugegraph/hugegraph/contributors","subscribers_url":"https://api.github.com/repos/hugegraph/hugegraph/subscribers","subscription_url":"https://api.github.com/repos/hugegraph/hugegraph/subscription","commits_url":"https://api.github.com/repos/hugegraph/hugegraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/hugegraph/hugegraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/hugegraph/hugegraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/hugegraph/hugegraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/hugegraph/hugegraph/contents/{+path}","compare_url":"https://api.github.com/repos/hugegraph/hugegraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hugegraph/hugegraph/merges","archive_url":"https://api.github.com/repos/hugegraph/hugegraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hugegraph/hugegraph/downloads","issues_url":"https://api.github.com/repos/hugegraph/hugegraph/issues{/number}","pulls_url":"https://api.github.com/repos/hugegraph/hugegraph/pulls{/number}","milestones_url":"https://api.github.com/repos/hugegraph/hugegraph/milestones{/number}","notifications_url":"https://api.github.com/repos/hugegraph/hugegraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hugegraph/hugegraph/labels{/name}","releases_url":"https://api.github.com/repos/hugegraph/hugegraph/releases{/id}","deployments_url":"https://api.github.com/repos/hugegraph/hugegraph/deployments","created_at":"2018-07-18T03:30:20Z","updated_at":"2018-12-14T08:58:40Z","pushed_at":"2018-12-17T06:54:23Z","git_url":"git://github.com/hugegraph/hugegraph.git","ssh_url":"git@github.com:hugegraph/hugegraph.git","clone_url":"https://github.com/hugegraph/hugegraph.git","svn_url":"https://github.com/hugegraph/hugegraph","homepage":null,"size":5183,"stargazers_count":552,"watchers_count":552,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":57,"mirror_url":null,"archived":false,"open_issues_count":96,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":57,"open_issues":96,"watchers":552,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274"},"html":{"href":"https://github.com/hugegraph/hugegraph/pull/274"},"issue":{"href":"https://api.github.com/repos/hugegraph/hugegraph/issues/274"},"comments":{"href":"https://api.github.com/repos/hugegraph/hugegraph/issues/274/comments"},"review_comments":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274/comments"},"review_comment":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hugegraph/hugegraph/pulls/274/commits"},"statuses":{"href":"https://api.github.com/repos/hugegraph/hugegraph/statuses/c84cab64fba1b4327bc41891e6d784ad45ad2f45"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"javeme"}}