{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/30610661","id":30610661,"diff_hunk":"@@ -120,6 +130,47 @@ def transformer(reviews):\n         for user in UserProfile.objects.no_cache().filter(id__in=user_ids):\n             user_ids[user.id].user = user\n \n+    def guess_language(self):\n+        self.update(lang=guess_language(unicode(self.body)))\n+\n+\n+# Determined by examining review corpus and confidence levels produced by\n+# langid, 18 May 2015. See bug 875455 for details.\n+COMMON_REVIEW_WORDS = {\n+    'bom': 'pt',\n+    'buena': 'es',\n+    'bueno': 'es',\n+    'cool': 'en',\n+    'esta': 'es',\n+    'excelente': 'es',\n+    'good': 'en',\n+    'great': 'en',\n+    'gusta': 'es',\n+    'muito': 'pt',\n+    'muy': 'es',\n+    'nice': 'en',\n+    'ok': 'en',\n+    'super': 'en',\n+    'the': 'en',\n+    'very': 'en'\n+}\n+\n+\n+def guess_language(text):\n+    guessed_lang, confidence = langid.classify(text)\n+    if confidence < 0.9:\n+        depunct = dict.fromkeys([ord(c) for c in string.punctuation], u' ')\n+        words = text.lower().translate(depunct).split()\n+        for w in words:\n+            assumed_lang = COMMON_REVIEW_WORDS.get(w)\n+            if assumed_lang:\n+                break\n+        if assumed_lang is None and len(words) <= 3:\n+            # Too little text to reliably guess.\n+            return None","path":"mkt/ratings/models.py","position":86,"original_position":86,"commit_id":"29918dedd61d385ec28728171c0e6efa90fd9986","original_commit_id":"29918dedd61d385ec28728171c0e6efa90fd9986","user":{"login":"mstriemer","id":211578,"avatar_url":"https://avatars.githubusercontent.com/u/211578?v=3","gravatar_id":"","url":"https://api.github.com/users/mstriemer","html_url":"https://github.com/mstriemer","followers_url":"https://api.github.com/users/mstriemer/followers","following_url":"https://api.github.com/users/mstriemer/following{/other_user}","gists_url":"https://api.github.com/users/mstriemer/gists{/gist_id}","starred_url":"https://api.github.com/users/mstriemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstriemer/subscriptions","organizations_url":"https://api.github.com/users/mstriemer/orgs","repos_url":"https://api.github.com/users/mstriemer/repos","events_url":"https://api.github.com/users/mstriemer/events{/privacy}","received_events_url":"https://api.github.com/users/mstriemer/received_events","type":"User","site_admin":false},"body":"Could we fallback to the user's language at this point?","created_at":"2015-05-19T15:20:40Z","updated_at":"2015-05-19T15:20:40Z","html_url":"https://github.com/mozilla/zamboni/pull/3091#discussion_r30610661","pull_request_url":"https://api.github.com/repos/mozilla/zamboni/pulls/3091","_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments/30610661"},"html":{"href":"https://github.com/mozilla/zamboni/pull/3091#discussion_r30610661"},"pull_request":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/3091"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/zamboni/pulls/3091","id":35694763,"html_url":"https://github.com/mozilla/zamboni/pull/3091","diff_url":"https://github.com/mozilla/zamboni/pull/3091.diff","patch_url":"https://github.com/mozilla/zamboni/pull/3091.patch","issue_url":"https://api.github.com/repos/mozilla/zamboni/issues/3091","number":3091,"state":"open","locked":false,"title":"Guess rating language and filter queries on it (bug 875455)","user":{"login":"washort","id":947487,"avatar_url":"https://avatars.githubusercontent.com/u/947487?v=3","gravatar_id":"","url":"https://api.github.com/users/washort","html_url":"https://github.com/washort","followers_url":"https://api.github.com/users/washort/followers","following_url":"https://api.github.com/users/washort/following{/other_user}","gists_url":"https://api.github.com/users/washort/gists{/gist_id}","starred_url":"https://api.github.com/users/washort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washort/subscriptions","organizations_url":"https://api.github.com/users/washort/orgs","repos_url":"https://api.github.com/users/washort/repos","events_url":"https://api.github.com/users/washort/events{/privacy}","received_events_url":"https://api.github.com/users/washort/received_events","type":"User","site_admin":false},"body":"Based on mstriemer's code in https://github.com/mozilla/zamboni/pull/2818","created_at":"2015-05-19T04:13:29Z","updated_at":"2015-05-19T15:20:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2cef69efcea4d4737cb2ec2df2bdec6ecceed1e7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/zamboni/pulls/3091/commits","review_comments_url":"https://api.github.com/repos/mozilla/zamboni/pulls/3091/comments","review_comment_url":"https://api.github.com/repos/mozilla/zamboni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/zamboni/issues/3091/comments","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/29918dedd61d385ec28728171c0e6efa90fd9986","head":{"label":"washort:875455","ref":"875455","sha":"29918dedd61d385ec28728171c0e6efa90fd9986","user":{"login":"washort","id":947487,"avatar_url":"https://avatars.githubusercontent.com/u/947487?v=3","gravatar_id":"","url":"https://api.github.com/users/washort","html_url":"https://github.com/washort","followers_url":"https://api.github.com/users/washort/followers","following_url":"https://api.github.com/users/washort/following{/other_user}","gists_url":"https://api.github.com/users/washort/gists{/gist_id}","starred_url":"https://api.github.com/users/washort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washort/subscriptions","organizations_url":"https://api.github.com/users/washort/orgs","repos_url":"https://api.github.com/users/washort/repos","events_url":"https://api.github.com/users/washort/events{/privacy}","received_events_url":"https://api.github.com/users/washort/received_events","type":"User","site_admin":false},"repo":{"id":2126060,"name":"zamboni","full_name":"washort/zamboni","owner":{"login":"washort","id":947487,"avatar_url":"https://avatars.githubusercontent.com/u/947487?v=3","gravatar_id":"","url":"https://api.github.com/users/washort","html_url":"https://github.com/washort","followers_url":"https://api.github.com/users/washort/followers","following_url":"https://api.github.com/users/washort/following{/other_user}","gists_url":"https://api.github.com/users/washort/gists{/gist_id}","starred_url":"https://api.github.com/users/washort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washort/subscriptions","organizations_url":"https://api.github.com/users/washort/orgs","repos_url":"https://api.github.com/users/washort/repos","events_url":"https://api.github.com/users/washort/events{/privacy}","received_events_url":"https://api.github.com/users/washort/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/washort/zamboni","description":"A clandestine operation to make AMO happy","fork":true,"url":"https://api.github.com/repos/washort/zamboni","forks_url":"https://api.github.com/repos/washort/zamboni/forks","keys_url":"https://api.github.com/repos/washort/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/washort/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/washort/zamboni/teams","hooks_url":"https://api.github.com/repos/washort/zamboni/hooks","issue_events_url":"https://api.github.com/repos/washort/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/washort/zamboni/events","assignees_url":"https://api.github.com/repos/washort/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/washort/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/washort/zamboni/tags","blobs_url":"https://api.github.com/repos/washort/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/washort/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/washort/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/washort/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/washort/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/washort/zamboni/languages","stargazers_url":"https://api.github.com/repos/washort/zamboni/stargazers","contributors_url":"https://api.github.com/repos/washort/zamboni/contributors","subscribers_url":"https://api.github.com/repos/washort/zamboni/subscribers","subscription_url":"https://api.github.com/repos/washort/zamboni/subscription","commits_url":"https://api.github.com/repos/washort/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/washort/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/washort/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/washort/zamboni/issues/comments{/number}","contents_url":"https://api.github.com/repos/washort/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/washort/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/washort/zamboni/merges","archive_url":"https://api.github.com/repos/washort/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/washort/zamboni/downloads","issues_url":"https://api.github.com/repos/washort/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/washort/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/washort/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/washort/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/washort/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/washort/zamboni/releases{/id}","created_at":"2011-07-29T20:50:16Z","updated_at":"2015-03-03T00:13:01Z","pushed_at":"2015-05-19T04:12:07Z","git_url":"git://github.com/washort/zamboni.git","ssh_url":"git@github.com:washort/zamboni.git","clone_url":"https://github.com/washort/zamboni.git","svn_url":"https://github.com/washort/zamboni","homepage":"http://jbalogh.github.com/zamboni/","size":355446,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"c13b3e4015778e74d57271e11683d3d1098eebf9","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":347655,"name":"zamboni","full_name":"mozilla/zamboni","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/zamboni","description":"Backend for the Firefox Marketplace","fork":false,"url":"https://api.github.com/repos/mozilla/zamboni","forks_url":"https://api.github.com/repos/mozilla/zamboni/forks","keys_url":"https://api.github.com/repos/mozilla/zamboni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/zamboni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/zamboni/teams","hooks_url":"https://api.github.com/repos/mozilla/zamboni/hooks","issue_events_url":"https://api.github.com/repos/mozilla/zamboni/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/zamboni/events","assignees_url":"https://api.github.com/repos/mozilla/zamboni/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/zamboni/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/zamboni/tags","blobs_url":"https://api.github.com/repos/mozilla/zamboni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/zamboni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/zamboni/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/zamboni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/zamboni/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/zamboni/languages","stargazers_url":"https://api.github.com/repos/mozilla/zamboni/stargazers","contributors_url":"https://api.github.com/repos/mozilla/zamboni/contributors","subscribers_url":"https://api.github.com/repos/mozilla/zamboni/subscribers","subscription_url":"https://api.github.com/repos/mozilla/zamboni/subscription","commits_url":"https://api.github.com/repos/mozilla/zamboni/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/zamboni/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/zamboni/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/zamboni/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/zamboni/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/zamboni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/zamboni/merges","archive_url":"https://api.github.com/repos/mozilla/zamboni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/zamboni/downloads","issues_url":"https://api.github.com/repos/mozilla/zamboni/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/zamboni/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/zamboni/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/zamboni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/zamboni/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/zamboni/releases{/id}","created_at":"2009-10-23T19:35:34Z","updated_at":"2015-05-14T01:02:50Z","pushed_at":"2015-05-19T14:57:11Z","git_url":"git://github.com/mozilla/zamboni.git","ssh_url":"git@github.com:mozilla/zamboni.git","clone_url":"https://github.com/mozilla/zamboni.git","svn_url":"https://github.com/mozilla/zamboni","homepage":"http://marketplace.readthedocs.org/en/latest/topics/backend.html","size":424055,"stargazers_count":459,"watchers_count":459,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":241,"mirror_url":null,"open_issues_count":16,"forks":241,"open_issues":16,"watchers":459,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/3091"},"html":{"href":"https://github.com/mozilla/zamboni/pull/3091"},"issue":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/3091"},"comments":{"href":"https://api.github.com/repos/mozilla/zamboni/issues/3091/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/3091/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/zamboni/pulls/3091/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/zamboni/statuses/29918dedd61d385ec28728171c0e6efa90fd9986"}}}}