{"action":"created","comment":{"url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/comments/34868317","id":34868317,"diff_hunk":"@@ -0,0 +1,139 @@\n+/*\r\n+ * UndirectWeightedGraph.hpp\r\n+ *\r\n+ *  Created on: 2015年7月7日\r\n+ *      Author: oliverlwang\r\n+ */\r\n+\r\n+#ifndef UNDIRECTWEIGHTEDGRAPH_H_\r\n+#define UNDIRECTWEIGHTEDGRAPH_H_\r\n+\r\n+#include <iostream>\r\n+#include <algorithm>\r\n+#include <vector>\r\n+#include <map>\r\n+#include <set>\r\n+\r\n+using namespace std;\r\n+\r\n+namespace CppJieba\r\n+{\r\n+\r\n+/* edge type */\r\n+struct edge_t\r\n+{\r\n+\tstring start;\r\n+\tstring end;\r\n+\tdouble weight;\r\n+};\r\n+\r\n+class UndirectWeightedGraph\r\n+{\r\n+public:\r\n+\tUndirectWeightedGraph(): _dampingFactor(0.85){};\r\n+\tvirtual ~UndirectWeightedGraph(){};\r\n+\r\n+    /**\r\n+\t * @brief add an edge for the UndirectedWeighted Graph\r\n+\t *\r\n+\t * @param string &start\r\n+\t * @param  string &end\r\n+\t * @param\r\n+\t *\r\n+     * @retval\r\n+     */\r\n+\tvoid addEdge(const string &start, const string &end, double weight)\r\n+\t{\r\n+\t\t/* add an out edge for vertex start */\r\n+\t\tedge_t _edge;\r\n+\t\t_edge.start = start;\r\n+\t\t_edge.end = end;\r\n+\t\t_edge.weight = weight;\r\n+\r\n+\t\t_graph[start].push_back(_edge);\r\n+\r\n+\t\t/* add an out edge for vertex end */\r\n+\t\t_edge.start = end;\r\n+\t\t_edge.end = start;\r\n+\r\n+\t\t_graph[end].push_back(_edge);\r\n+\t}\r\n+\r\n+    /**\r\n+\t * @brief rank the words according to its score\r\n+\t *\r\n+\t * @param none\r\n+\t *\r\n+     * @retval none\r\n+     */\r\n+\tvoid rank()\r\n+\t{\r\n+\t\tmap<string, double> outSum;\r\n+\r\n+\t\t/* initialize words score */\r\n+\t\tdouble wsdef = (_graph.size() > 0) ? (1.0 / _graph.size()) : 1.0;\r\n+\r\n+\t\tfor(map<string, vector<edge_t> >::iterator it = _graph.begin(); it != _graph.end(); ++it)\r\n+\t\t{\r\n+\t        ws[it->first] = wsdef;\r\n+\t        outSum[it->first] = weightOutSum(it->second);\r\n+\t\t}\r\n+\r\n+\t\t/* iterator 10 times */\r\n+\t\tfor(int i = 0; i < 10; ++i)\r\n+\t\t{\r\n+\t\t\t/* stl map is sorted by key by default */\r\n+\t\t\tfor(map<string, vector<edge_t> >::iterator i = _graph.begin(); i != _graph.end(); ++i)\r\n+\t\t\t{\r\n+\t            double score = 0.0;\r\n+\t            for(vector<edge_t>::iterator j = i->second.begin(); j != i->second.end(); ++j)\r\n+\t            {\r\n+\t                score += j->weight / outSum[j->end] * ws[j->end];\r\n+\t            }\r\n+\r\n+\t            ws[i->first] = (1.0 - _dampingFactor) + _dampingFactor * score;\r\n+\t\t\t}\r\n+\t\t}\r\n+\r\n+\t\t/* normalize */\r\n+\t\tdouble max_rank = max_element(ws.begin(), ws.end())->second;\r","path":"src/UndirectWeightedGraph.hpp","position":99,"original_position":99,"commit_id":"1ebc3937c358983dd5c4397e651bf7ffd959ad7b","original_commit_id":"1ebc3937c358983dd5c4397e651bf7ffd959ad7b","user":{"login":"yanyiwu","id":2162645,"avatar_url":"https://avatars.githubusercontent.com/u/2162645?v=3","gravatar_id":"","url":"https://api.github.com/users/yanyiwu","html_url":"https://github.com/yanyiwu","followers_url":"https://api.github.com/users/yanyiwu/followers","following_url":"https://api.github.com/users/yanyiwu/following{/other_user}","gists_url":"https://api.github.com/users/yanyiwu/gists{/gist_id}","starred_url":"https://api.github.com/users/yanyiwu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanyiwu/subscriptions","organizations_url":"https://api.github.com/users/yanyiwu/orgs","repos_url":"https://api.github.com/users/yanyiwu/repos","events_url":"https://api.github.com/users/yanyiwu/events{/privacy}","received_events_url":"https://api.github.com/users/yanyiwu/received_events","type":"User","site_admin":false},"body":"我说的是99行，就是 max_element 那行，和update或者insert没有关系啊。你回复的好像和我说的不是一回事，还是我没理解对？","created_at":"2015-07-17T07:42:46Z","updated_at":"2015-07-17T07:42:46Z","html_url":"https://github.com/yanyiwu/cppjieba/pull/42#discussion_r34868317","pull_request_url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42","_links":{"self":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/comments/34868317"},"html":{"href":"https://github.com/yanyiwu/cppjieba/pull/42#discussion_r34868317"},"pull_request":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42","id":39573345,"html_url":"https://github.com/yanyiwu/cppjieba/pull/42","diff_url":"https://github.com/yanyiwu/cppjieba/pull/42.diff","patch_url":"https://github.com/yanyiwu/cppjieba/pull/42.patch","issue_url":"https://api.github.com/repos/yanyiwu/cppjieba/issues/42","number":42,"state":"open","locked":false,"title":"新增TextRank算法","user":{"login":"CasyWang","id":6657398,"avatar_url":"https://avatars.githubusercontent.com/u/6657398?v=3","gravatar_id":"","url":"https://api.github.com/users/CasyWang","html_url":"https://github.com/CasyWang","followers_url":"https://api.github.com/users/CasyWang/followers","following_url":"https://api.github.com/users/CasyWang/following{/other_user}","gists_url":"https://api.github.com/users/CasyWang/gists{/gist_id}","starred_url":"https://api.github.com/users/CasyWang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CasyWang/subscriptions","organizations_url":"https://api.github.com/users/CasyWang/orgs","repos_url":"https://api.github.com/users/CasyWang/repos","events_url":"https://api.github.com/users/CasyWang/events{/privacy}","received_events_url":"https://api.github.com/users/CasyWang/received_events","type":"User","site_admin":false},"body":"添加新特性\r\n1. 添加原生的TextRank算法；","created_at":"2015-07-09T11:33:25Z","updated_at":"2015-07-17T07:42:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02d823cd53c53f1888797e4e6182a2caf01214c0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42/commits","review_comments_url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42/comments","review_comment_url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yanyiwu/cppjieba/issues/42/comments","statuses_url":"https://api.github.com/repos/yanyiwu/cppjieba/statuses/1ebc3937c358983dd5c4397e651bf7ffd959ad7b","head":{"label":"CasyWang:master","ref":"master","sha":"1ebc3937c358983dd5c4397e651bf7ffd959ad7b","user":{"login":"CasyWang","id":6657398,"avatar_url":"https://avatars.githubusercontent.com/u/6657398?v=3","gravatar_id":"","url":"https://api.github.com/users/CasyWang","html_url":"https://github.com/CasyWang","followers_url":"https://api.github.com/users/CasyWang/followers","following_url":"https://api.github.com/users/CasyWang/following{/other_user}","gists_url":"https://api.github.com/users/CasyWang/gists{/gist_id}","starred_url":"https://api.github.com/users/CasyWang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CasyWang/subscriptions","organizations_url":"https://api.github.com/users/CasyWang/orgs","repos_url":"https://api.github.com/users/CasyWang/repos","events_url":"https://api.github.com/users/CasyWang/events{/privacy}","received_events_url":"https://api.github.com/users/CasyWang/received_events","type":"User","site_admin":false},"repo":{"id":38814774,"name":"cppjieba","full_name":"CasyWang/cppjieba","owner":{"login":"CasyWang","id":6657398,"avatar_url":"https://avatars.githubusercontent.com/u/6657398?v=3","gravatar_id":"","url":"https://api.github.com/users/CasyWang","html_url":"https://github.com/CasyWang","followers_url":"https://api.github.com/users/CasyWang/followers","following_url":"https://api.github.com/users/CasyWang/following{/other_user}","gists_url":"https://api.github.com/users/CasyWang/gists{/gist_id}","starred_url":"https://api.github.com/users/CasyWang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CasyWang/subscriptions","organizations_url":"https://api.github.com/users/CasyWang/orgs","repos_url":"https://api.github.com/users/CasyWang/repos","events_url":"https://api.github.com/users/CasyWang/events{/privacy}","received_events_url":"https://api.github.com/users/CasyWang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CasyWang/cppjieba","description":"\"结巴\"中文分词的C++版本","fork":true,"url":"https://api.github.com/repos/CasyWang/cppjieba","forks_url":"https://api.github.com/repos/CasyWang/cppjieba/forks","keys_url":"https://api.github.com/repos/CasyWang/cppjieba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CasyWang/cppjieba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CasyWang/cppjieba/teams","hooks_url":"https://api.github.com/repos/CasyWang/cppjieba/hooks","issue_events_url":"https://api.github.com/repos/CasyWang/cppjieba/issues/events{/number}","events_url":"https://api.github.com/repos/CasyWang/cppjieba/events","assignees_url":"https://api.github.com/repos/CasyWang/cppjieba/assignees{/user}","branches_url":"https://api.github.com/repos/CasyWang/cppjieba/branches{/branch}","tags_url":"https://api.github.com/repos/CasyWang/cppjieba/tags","blobs_url":"https://api.github.com/repos/CasyWang/cppjieba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CasyWang/cppjieba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CasyWang/cppjieba/git/refs{/sha}","trees_url":"https://api.github.com/repos/CasyWang/cppjieba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CasyWang/cppjieba/statuses/{sha}","languages_url":"https://api.github.com/repos/CasyWang/cppjieba/languages","stargazers_url":"https://api.github.com/repos/CasyWang/cppjieba/stargazers","contributors_url":"https://api.github.com/repos/CasyWang/cppjieba/contributors","subscribers_url":"https://api.github.com/repos/CasyWang/cppjieba/subscribers","subscription_url":"https://api.github.com/repos/CasyWang/cppjieba/subscription","commits_url":"https://api.github.com/repos/CasyWang/cppjieba/commits{/sha}","git_commits_url":"https://api.github.com/repos/CasyWang/cppjieba/git/commits{/sha}","comments_url":"https://api.github.com/repos/CasyWang/cppjieba/comments{/number}","issue_comment_url":"https://api.github.com/repos/CasyWang/cppjieba/issues/comments{/number}","contents_url":"https://api.github.com/repos/CasyWang/cppjieba/contents/{+path}","compare_url":"https://api.github.com/repos/CasyWang/cppjieba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CasyWang/cppjieba/merges","archive_url":"https://api.github.com/repos/CasyWang/cppjieba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CasyWang/cppjieba/downloads","issues_url":"https://api.github.com/repos/CasyWang/cppjieba/issues{/number}","pulls_url":"https://api.github.com/repos/CasyWang/cppjieba/pulls{/number}","milestones_url":"https://api.github.com/repos/CasyWang/cppjieba/milestones{/number}","notifications_url":"https://api.github.com/repos/CasyWang/cppjieba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CasyWang/cppjieba/labels{/name}","releases_url":"https://api.github.com/repos/CasyWang/cppjieba/releases{/id}","created_at":"2015-07-09T10:46:18Z","updated_at":"2015-07-09T10:46:21Z","pushed_at":"2015-07-09T11:30:33Z","git_url":"git://github.com/CasyWang/cppjieba.git","ssh_url":"git@github.com:CasyWang/cppjieba.git","clone_url":"https://github.com/CasyWang/cppjieba.git","svn_url":"https://github.com/CasyWang/cppjieba","homepage":"","size":9871,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yanyiwu:master","ref":"master","sha":"6e723c2c587fb260e5bc9b8d630fcd4a0603f7d1","user":{"login":"yanyiwu","id":2162645,"avatar_url":"https://avatars.githubusercontent.com/u/2162645?v=3","gravatar_id":"","url":"https://api.github.com/users/yanyiwu","html_url":"https://github.com/yanyiwu","followers_url":"https://api.github.com/users/yanyiwu/followers","following_url":"https://api.github.com/users/yanyiwu/following{/other_user}","gists_url":"https://api.github.com/users/yanyiwu/gists{/gist_id}","starred_url":"https://api.github.com/users/yanyiwu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanyiwu/subscriptions","organizations_url":"https://api.github.com/users/yanyiwu/orgs","repos_url":"https://api.github.com/users/yanyiwu/repos","events_url":"https://api.github.com/users/yanyiwu/events{/privacy}","received_events_url":"https://api.github.com/users/yanyiwu/received_events","type":"User","site_admin":false},"repo":{"id":10885469,"name":"cppjieba","full_name":"yanyiwu/cppjieba","owner":{"login":"yanyiwu","id":2162645,"avatar_url":"https://avatars.githubusercontent.com/u/2162645?v=3","gravatar_id":"","url":"https://api.github.com/users/yanyiwu","html_url":"https://github.com/yanyiwu","followers_url":"https://api.github.com/users/yanyiwu/followers","following_url":"https://api.github.com/users/yanyiwu/following{/other_user}","gists_url":"https://api.github.com/users/yanyiwu/gists{/gist_id}","starred_url":"https://api.github.com/users/yanyiwu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanyiwu/subscriptions","organizations_url":"https://api.github.com/users/yanyiwu/orgs","repos_url":"https://api.github.com/users/yanyiwu/repos","events_url":"https://api.github.com/users/yanyiwu/events{/privacy}","received_events_url":"https://api.github.com/users/yanyiwu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yanyiwu/cppjieba","description":"\"结巴\"中文分词的C++版本","fork":false,"url":"https://api.github.com/repos/yanyiwu/cppjieba","forks_url":"https://api.github.com/repos/yanyiwu/cppjieba/forks","keys_url":"https://api.github.com/repos/yanyiwu/cppjieba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yanyiwu/cppjieba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yanyiwu/cppjieba/teams","hooks_url":"https://api.github.com/repos/yanyiwu/cppjieba/hooks","issue_events_url":"https://api.github.com/repos/yanyiwu/cppjieba/issues/events{/number}","events_url":"https://api.github.com/repos/yanyiwu/cppjieba/events","assignees_url":"https://api.github.com/repos/yanyiwu/cppjieba/assignees{/user}","branches_url":"https://api.github.com/repos/yanyiwu/cppjieba/branches{/branch}","tags_url":"https://api.github.com/repos/yanyiwu/cppjieba/tags","blobs_url":"https://api.github.com/repos/yanyiwu/cppjieba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yanyiwu/cppjieba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yanyiwu/cppjieba/git/refs{/sha}","trees_url":"https://api.github.com/repos/yanyiwu/cppjieba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yanyiwu/cppjieba/statuses/{sha}","languages_url":"https://api.github.com/repos/yanyiwu/cppjieba/languages","stargazers_url":"https://api.github.com/repos/yanyiwu/cppjieba/stargazers","contributors_url":"https://api.github.com/repos/yanyiwu/cppjieba/contributors","subscribers_url":"https://api.github.com/repos/yanyiwu/cppjieba/subscribers","subscription_url":"https://api.github.com/repos/yanyiwu/cppjieba/subscription","commits_url":"https://api.github.com/repos/yanyiwu/cppjieba/commits{/sha}","git_commits_url":"https://api.github.com/repos/yanyiwu/cppjieba/git/commits{/sha}","comments_url":"https://api.github.com/repos/yanyiwu/cppjieba/comments{/number}","issue_comment_url":"https://api.github.com/repos/yanyiwu/cppjieba/issues/comments{/number}","contents_url":"https://api.github.com/repos/yanyiwu/cppjieba/contents/{+path}","compare_url":"https://api.github.com/repos/yanyiwu/cppjieba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yanyiwu/cppjieba/merges","archive_url":"https://api.github.com/repos/yanyiwu/cppjieba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yanyiwu/cppjieba/downloads","issues_url":"https://api.github.com/repos/yanyiwu/cppjieba/issues{/number}","pulls_url":"https://api.github.com/repos/yanyiwu/cppjieba/pulls{/number}","milestones_url":"https://api.github.com/repos/yanyiwu/cppjieba/milestones{/number}","notifications_url":"https://api.github.com/repos/yanyiwu/cppjieba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yanyiwu/cppjieba/labels{/name}","releases_url":"https://api.github.com/repos/yanyiwu/cppjieba/releases{/id}","created_at":"2013-06-23T14:04:03Z","updated_at":"2015-07-09T11:36:12Z","pushed_at":"2015-07-09T11:33:26Z","git_url":"git://github.com/yanyiwu/cppjieba.git","ssh_url":"git@github.com:yanyiwu/cppjieba.git","clone_url":"https://github.com/yanyiwu/cppjieba.git","svn_url":"https://github.com/yanyiwu/cppjieba","homepage":"","size":11731,"stargazers_count":270,"watchers_count":270,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":115,"mirror_url":null,"open_issues_count":4,"forks":115,"open_issues":4,"watchers":270,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42"},"html":{"href":"https://github.com/yanyiwu/cppjieba/pull/42"},"issue":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/issues/42"},"comments":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/yanyiwu/cppjieba/statuses/1ebc3937c358983dd5c4397e651bf7ffd959ad7b"}}}}