{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/comments/54375399","id":54375399,"diff_hunk":"@@ -0,0 +1,217 @@\n+var github = require('./github_parses.js');\n+var natural = require('natural');\n+var stopWords = require('./stop_words.js');\n+var events = require('events');\n+var eventEmitter = new events.EventEmitter();\n+\n+// Храним статистику\n+// Слово -> ['однокоренные']\n+var resTokens = {};\n+var sortStat = [];\n+\n+// Подсчет статистики немного асинхронный\n+// поэтому устанавливаем переменную, когда считаем\n+// чтобы сделать синхронно\n+var calcInProgress = false;\n+\n+/**\n+ * Стемминг токена\n+ * @param token\n+ * @returns {String}\n+ */\n+function stemToken(token) {\n+    return natural.PorterStemmerRu.stem(token);\n+}\n+\n+/**\n+ * Сравнение на 'однокоренные' слова\n+ * С магической константой\n+ * @param token1\n+ * @param token2\n+ * @returns {boolean}\n+ */\n+function isCognatesWords(token1, token2) {\n+    return natural.JaroWinklerDistance(token1, token2) > 0.8;\n+}\n+\n+/**\n+ * Степень похожести слов\n+ * @param token1\n+ * @param token2\n+ * @returns {Number}\n+ */\n+function congateRate(token1, token2) {\n+    return natural.JaroWinklerDistance(token1, token2);\n+}\n+\n+/**\n+ * По слову находим самое 'однокоренное'\n+ * @param word\n+ * @returns {string}\n+ */\n+function nearestWord(word) {\n+    var bestWordRate = 0;\n+    var bestWord = '';\n+    for (var key in resTokens) {\n+        if (congateRate(key, word) >= bestWordRate) {\n+            bestWord = key;\n+            bestWordRate = congateRate(key, word);\n+        }\n+    }\n+    return bestWord;\n+}\n+\n+/**\n+ * Разбивание текста на токены\n+ * @param text\n+ * @param cb\n+ */\n+function tokenize(text, cb) {\n+    var res = text.match(/[а-яА-я]+/g);\n+    cb(res);\n+}\n+\n+/**\n+ * Фильтрация стоп-слов (предлогов и тд.)\n+ * @param tokens\n+ * @param cb\n+ */\n+function filterStopWords(tokens, cb) {\n+    tokens = tokens.map(function(token) {\n+        return token.toLowerCase();\n+    });\n+    var res = tokens.filter(function(a){return !~this.indexOf(a);},stopWords);\n+    //res = tokens.filter(function(a){return !a.match(/[а-яА-я]{1,2}/g);});\n+    cb(res);\n+}\n+\n+/**\n+ * Стемминг списка слов\n+ * @param tokens\n+ * @param cb\n+ */\n+function stemming(tokens, cb) {\n+    var stemmedTokens = tokens.map(function(token) {\n+        return stemToken(token);\n+    });\n+    cb(tokens, stemmedTokens);\n+}\n+\n+/**\n+ * Разбивание слов на классы 'однокоренных'\n+ * @param tokens\n+ * @param stemmedTokens\n+ * @param cb\n+ */\n+function sortCognatesWords(tokens, stemmedTokens, cb) {\n+    stemmedTokens.forEach(function(stemmedToken, idx) {\n+        if (!resTokens[tokens[idx]]) {\n+            // Проверяем слово с представителями 'однокоренных'\n+            // (ключами словаря)\n+            // Если совпадение 'хорошее', то добавим его в однокоренные\n+            var added = false;\n+            for (var key in resTokens) {\n+                if (congateRate(stemToken(key), stemmedToken) > 0.87) {\n+                    resTokens[key].push(tokens[idx]);\n+                    added = true;\n+                }\n+            }\n+            // Если слово не 'совпало' ни с одним,\n+            // полагаем, что это слово с новым корнем\n+            if (!added) {\n+                resTokens[tokens[idx]] = [tokens[idx]];\n+            }\n+        } else {\n+            resTokens[tokens[idx]].push(tokens[idx]);\n+        }\n+    });\n+    sortStat = Object.keys(resTokens).map(function (key) {\n+        return [key, resTokens[key].length];\n+    });\n+    sortStat.sort(function (first, second) {\n+        return second[1] - first[1];\n+    });\n+    cb();\n+}\n+\n+/**\n+ * Последовательно делаем анализ\n+ * Результат кладем в глобальную переменную\n+ * @param cb\n+ */\n+function calculate(cb) {\n+    github.getAllTasksReadme(function(text){\n+        tokenize(text, function(tokens) {\n+            filterStopWords(tokens, function(tokens) {\n+                stemming(tokens, function(tokens, stemmedTokens) {\n+                    sortCognatesWords(tokens, stemmedTokens, cb);\n+                })\n+            })\n+        })\n+    });\n+}\n+\n+/**\n+ * Топ n слов\n+ * @param n\n+ */\n+function top(n) {\n+    function printResults() {","path":"counter.js","position":159,"original_position":159,"commit_id":"96d58231295aa4801973677c376a0e9b7dfeb3b3","original_commit_id":"96d58231295aa4801973677c376a0e9b7dfeb3b3","user":{"login":"mokhov","id":357689,"avatar_url":"https://avatars.githubusercontent.com/u/357689?v=3","gravatar_id":"","url":"https://api.github.com/users/mokhov","html_url":"https://github.com/mokhov","followers_url":"https://api.github.com/users/mokhov/followers","following_url":"https://api.github.com/users/mokhov/following{/other_user}","gists_url":"https://api.github.com/users/mokhov/gists{/gist_id}","starred_url":"https://api.github.com/users/mokhov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mokhov/subscriptions","organizations_url":"https://api.github.com/users/mokhov/orgs","repos_url":"https://api.github.com/users/mokhov/repos","events_url":"https://api.github.com/users/mokhov/events{/privacy}","received_events_url":"https://api.github.com/users/mokhov/received_events","type":"User","site_admin":false},"body":"Пам-пам-пам и и как же вызвать эту функцию? :)","created_at":"2016-02-29T07:23:02Z","updated_at":"2016-02-29T07:23:02Z","html_url":"https://github.com/urfu-2015/webdev-tasks-1/pull/6#discussion_r54375399","pull_request_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/comments/54375399"},"html":{"href":"https://github.com/urfu-2015/webdev-tasks-1/pull/6#discussion_r54375399"},"pull_request":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6","id":60101358,"html_url":"https://github.com/urfu-2015/webdev-tasks-1/pull/6","diff_url":"https://github.com/urfu-2015/webdev-tasks-1/pull/6.diff","patch_url":"https://github.com/urfu-2015/webdev-tasks-1/pull/6.patch","issue_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/6","number":6,"state":"open","locked":false,"title":"Миронов Данил","user":{"login":"danmir","id":1074336,"avatar_url":"https://avatars.githubusercontent.com/u/1074336?v=3","gravatar_id":"","url":"https://api.github.com/users/danmir","html_url":"https://github.com/danmir","followers_url":"https://api.github.com/users/danmir/followers","following_url":"https://api.github.com/users/danmir/following{/other_user}","gists_url":"https://api.github.com/users/danmir/gists{/gist_id}","starred_url":"https://api.github.com/users/danmir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danmir/subscriptions","organizations_url":"https://api.github.com/users/danmir/orgs","repos_url":"https://api.github.com/users/danmir/repos","events_url":"https://api.github.com/users/danmir/events{/privacy}","received_events_url":"https://api.github.com/users/danmir/received_events","type":"User","site_admin":false},"body":"Нужно искать с учетом однокоренных, но нет четкой формулировки - какое слово будет представителем класса однокоренных, поэтому по вызову `count(слово)` может быть предложено слово похожее на заданное. \r\nИз модуля также доступна переменная `resTokens` - словарь, в котором можно посмотреть - какие слова считались однокоренными\r\n\r\nСтатистика\r\n- задача 100\r\n- проверьте 88\r\n- элемент 50\r\n- код 50\r\n- создать 46\r\n- требования 45\r\n- библиотеками 41\r\n- решение 40\r\n- котиков 40\r\n- файл 37\r\n","created_at":"2016-02-21T19:55:01Z","updated_at":"2016-02-29T07:23:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43d0fa7ac2c498a59160405349763b58811e2697","assignee":{"login":"mokhov","id":357689,"avatar_url":"https://avatars.githubusercontent.com/u/357689?v=3","gravatar_id":"","url":"https://api.github.com/users/mokhov","html_url":"https://github.com/mokhov","followers_url":"https://api.github.com/users/mokhov/followers","following_url":"https://api.github.com/users/mokhov/following{/other_user}","gists_url":"https://api.github.com/users/mokhov/gists{/gist_id}","starred_url":"https://api.github.com/users/mokhov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mokhov/subscriptions","organizations_url":"https://api.github.com/users/mokhov/orgs","repos_url":"https://api.github.com/users/mokhov/repos","events_url":"https://api.github.com/users/mokhov/events{/privacy}","received_events_url":"https://api.github.com/users/mokhov/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6/commits","review_comments_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6/comments","review_comment_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/6/comments","statuses_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/statuses/96d58231295aa4801973677c376a0e9b7dfeb3b3","head":{"label":"danmir:master","ref":"master","sha":"96d58231295aa4801973677c376a0e9b7dfeb3b3","user":{"login":"danmir","id":1074336,"avatar_url":"https://avatars.githubusercontent.com/u/1074336?v=3","gravatar_id":"","url":"https://api.github.com/users/danmir","html_url":"https://github.com/danmir","followers_url":"https://api.github.com/users/danmir/followers","following_url":"https://api.github.com/users/danmir/following{/other_user}","gists_url":"https://api.github.com/users/danmir/gists{/gist_id}","starred_url":"https://api.github.com/users/danmir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danmir/subscriptions","organizations_url":"https://api.github.com/users/danmir/orgs","repos_url":"https://api.github.com/users/danmir/repos","events_url":"https://api.github.com/users/danmir/events{/privacy}","received_events_url":"https://api.github.com/users/danmir/received_events","type":"User","site_admin":false},"repo":{"id":52031194,"name":"webdev-tasks-1","full_name":"danmir/webdev-tasks-1","owner":{"login":"danmir","id":1074336,"avatar_url":"https://avatars.githubusercontent.com/u/1074336?v=3","gravatar_id":"","url":"https://api.github.com/users/danmir","html_url":"https://github.com/danmir","followers_url":"https://api.github.com/users/danmir/followers","following_url":"https://api.github.com/users/danmir/following{/other_user}","gists_url":"https://api.github.com/users/danmir/gists{/gist_id}","starred_url":"https://api.github.com/users/danmir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danmir/subscriptions","organizations_url":"https://api.github.com/users/danmir/orgs","repos_url":"https://api.github.com/users/danmir/repos","events_url":"https://api.github.com/users/danmir/events{/privacy}","received_events_url":"https://api.github.com/users/danmir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danmir/webdev-tasks-1","description":"","fork":true,"url":"https://api.github.com/repos/danmir/webdev-tasks-1","forks_url":"https://api.github.com/repos/danmir/webdev-tasks-1/forks","keys_url":"https://api.github.com/repos/danmir/webdev-tasks-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danmir/webdev-tasks-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danmir/webdev-tasks-1/teams","hooks_url":"https://api.github.com/repos/danmir/webdev-tasks-1/hooks","issue_events_url":"https://api.github.com/repos/danmir/webdev-tasks-1/issues/events{/number}","events_url":"https://api.github.com/repos/danmir/webdev-tasks-1/events","assignees_url":"https://api.github.com/repos/danmir/webdev-tasks-1/assignees{/user}","branches_url":"https://api.github.com/repos/danmir/webdev-tasks-1/branches{/branch}","tags_url":"https://api.github.com/repos/danmir/webdev-tasks-1/tags","blobs_url":"https://api.github.com/repos/danmir/webdev-tasks-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danmir/webdev-tasks-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danmir/webdev-tasks-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/danmir/webdev-tasks-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danmir/webdev-tasks-1/statuses/{sha}","languages_url":"https://api.github.com/repos/danmir/webdev-tasks-1/languages","stargazers_url":"https://api.github.com/repos/danmir/webdev-tasks-1/stargazers","contributors_url":"https://api.github.com/repos/danmir/webdev-tasks-1/contributors","subscribers_url":"https://api.github.com/repos/danmir/webdev-tasks-1/subscribers","subscription_url":"https://api.github.com/repos/danmir/webdev-tasks-1/subscription","commits_url":"https://api.github.com/repos/danmir/webdev-tasks-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/danmir/webdev-tasks-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/danmir/webdev-tasks-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/danmir/webdev-tasks-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/danmir/webdev-tasks-1/contents/{+path}","compare_url":"https://api.github.com/repos/danmir/webdev-tasks-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danmir/webdev-tasks-1/merges","archive_url":"https://api.github.com/repos/danmir/webdev-tasks-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danmir/webdev-tasks-1/downloads","issues_url":"https://api.github.com/repos/danmir/webdev-tasks-1/issues{/number}","pulls_url":"https://api.github.com/repos/danmir/webdev-tasks-1/pulls{/number}","milestones_url":"https://api.github.com/repos/danmir/webdev-tasks-1/milestones{/number}","notifications_url":"https://api.github.com/repos/danmir/webdev-tasks-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danmir/webdev-tasks-1/labels{/name}","releases_url":"https://api.github.com/repos/danmir/webdev-tasks-1/releases{/id}","deployments_url":"https://api.github.com/repos/danmir/webdev-tasks-1/deployments","created_at":"2016-02-18T19:04:28Z","updated_at":"2016-02-21T19:49:14Z","pushed_at":"2016-02-22T19:25:56Z","git_url":"git://github.com/danmir/webdev-tasks-1.git","ssh_url":"git@github.com:danmir/webdev-tasks-1.git","clone_url":"https://github.com/danmir/webdev-tasks-1.git","svn_url":"https://github.com/danmir/webdev-tasks-1","homepage":null,"size":9,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"urfu-2015:master","ref":"master","sha":"6ff732253132f88e1eec631e611136f3676768b7","user":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"repo":{"id":52003967,"name":"webdev-tasks-1","full_name":"urfu-2015/webdev-tasks-1","owner":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2015/webdev-tasks-1","description":"","fork":false,"url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1","forks_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/forks","keys_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/teams","hooks_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/hooks","issue_events_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/events","assignees_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/tags","blobs_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/languages","stargazers_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/stargazers","contributors_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/contributors","subscribers_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/subscribers","subscription_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/subscription","commits_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/merges","archive_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/downloads","issues_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/releases{/id}","deployments_url":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/deployments","created_at":"2016-02-18T11:54:14Z","updated_at":"2016-02-18T11:54:14Z","pushed_at":"2016-02-28T21:26:22Z","git_url":"git://github.com/urfu-2015/webdev-tasks-1.git","ssh_url":"git@github.com:urfu-2015/webdev-tasks-1.git","clone_url":"https://github.com/urfu-2015/webdev-tasks-1.git","svn_url":"https://github.com/urfu-2015/webdev-tasks-1","homepage":null,"size":5,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":20,"forks":34,"open_issues":20,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6"},"html":{"href":"https://github.com/urfu-2015/webdev-tasks-1/pull/6"},"issue":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/6"},"comments":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2015/webdev-tasks-1/statuses/96d58231295aa4801973677c376a0e9b7dfeb3b3"}}}}