{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/82573074","pull_request_review_id":3470656,"id":82573074,"diff_hunk":"@@ -0,0 +1,107 @@\n+#include \"generator/sponsored_scoring.hpp\"\n+\n+#include \"indexer/search_delimiters.hpp\"\n+#include \"indexer/search_string_utils.hpp\"\n+\n+#include \"geometry/distance_on_sphere.hpp\"\n+\n+#include \"std/algorithm.hpp\"\n+#include \"std/vector.hpp\"\n+\n+namespace\n+{\n+using WeightedBagOfWords = vector<pair<strings::UniString, double>>;\n+\n+vector<strings::UniString> StringToSetOfWords(string const & str)\n+{\n+  vector<strings::UniString> result;\n+  search::NormalizeAndTokenizeString(str, result, search::Delimiters{});\n+  sort(begin(result), end(result));\n+  return result;\n+}\n+\n+WeightedBagOfWords MakeWeightedBagOfWords(vector<strings::UniString> const & words)\n+{\n+  // TODO(mgsergio): Calculate tf-idsf score for every word.\n+  auto constexpr kTfIdfScorePlaceholder = 1;\n+\n+  WeightedBagOfWords result;\n+  for (size_t i = 0; i < words.size(); ++i)\n+  {\n+    result.emplace_back(words[i], kTfIdfScorePlaceholder);\n+    while (i + 1 < words.size() && words[i] == words[i + 1])\n+    {\n+      result.back().second += kTfIdfScorePlaceholder;  // TODO(mgsergio): tf-idf score for result[i].frist;\n+      ++i;\n+    }\n+  }\n+  return result;\n+}\n+\n+double WeightedBagsDotProduct(WeightedBagOfWords const & lhs, WeightedBagOfWords const & rhs)\n+{\n+  double result{};\n+\n+  auto lhsIt = begin(lhs);\n+  auto rhsIt = begin(rhs);\n+\n+  while (lhsIt != end(lhs) && rhsIt != end(rhs))\n+  {\n+    if (lhsIt->first == rhsIt->first)\n+    {\n+      result += lhsIt->second * rhsIt->second;\n+      ++lhsIt;\n+      ++rhsIt;\n+    }\n+    else if (lhsIt->first < rhsIt->first)\n+    {\n+      ++lhsIt;\n+    }\n+    else\n+    {\n+      ++rhsIt;\n+    }\n+  }\n+\n+  return result;\n+}\n+\n+double WeightedBagOfWordsCos(WeightedBagOfWords const & lhs, WeightedBagOfWords const & rhs)\n+{\n+  auto const product = WeightedBagsDotProduct(lhs, rhs);\n+  auto const lhsLength = sqrt(WeightedBagsDotProduct(lhs, lhs));\n+  auto const rhsLength = sqrt(WeightedBagsDotProduct(rhs, rhs));\n+\n+  // WeightedBagsDotProduct returns 0.0 if lhs.empty() || rhs.empty() or\n+  // if every element of either lhs or rhs is 0.0.\n+  if (product == 0.0)\n+    return 0.0;\n+\n+  return product / (lhsLength * rhsLength);\n+}\n+}  // namespace\n+\n+namespace generator\n+{\n+namespace impl\n+{\n+double GetLinearNormDistanceScore(double distance, double const maxDistance)\n+{\n+  distance = my::clamp(distance, 0, maxDistance);\n+  return 1.0 - distance / maxDistance;\n+}\n+\n+double GetNameSimilarityScore(string const & booking_name, string const & osm_name)\n+{\n+  auto const aws = MakeWeightedBagOfWords(StringToSetOfWords(booking_name));\n+  auto const bws = MakeWeightedBagOfWords(StringToSetOfWords(osm_name));\n+\n+  if (aws.empty() && bws.empty())","path":"generator/sponsored_scoring.cpp","position":99,"original_position":99,"commit_id":"ee27bc7f508ccef64869b05cd79dfea44c8dd951","original_commit_id":"ee27bc7f508ccef64869b05cd79dfea44c8dd951","user":{"login":"ygorshenin","id":454567,"avatar_url":"https://avatars.githubusercontent.com/u/454567?v=3","gravatar_id":"","url":"https://api.github.com/users/ygorshenin","html_url":"https://github.com/ygorshenin","followers_url":"https://api.github.com/users/ygorshenin/followers","following_url":"https://api.github.com/users/ygorshenin/following{/other_user}","gists_url":"https://api.github.com/users/ygorshenin/gists{/gist_id}","starred_url":"https://api.github.com/users/ygorshenin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ygorshenin/subscriptions","organizations_url":"https://api.github.com/users/ygorshenin/orgs","repos_url":"https://api.github.com/users/ygorshenin/repos","events_url":"https://api.github.com/users/ygorshenin/events{/privacy}","received_events_url":"https://api.github.com/users/ygorshenin/received_events","type":"User","site_admin":false},"body":"Why? Why you return 1.0 if both bags are empty?","created_at":"2016-10-10T09:50:02Z","updated_at":"2016-10-10T09:50:02Z","html_url":"https://github.com/mapsme/omim/pull/4152#discussion_r82573074","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/4152","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/82573074"},"html":{"href":"https://github.com/mapsme/omim/pull/4152#discussion_r82573074"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4152"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/4152","id":82713657,"html_url":"https://github.com/mapsme/omim/pull/4152","diff_url":"https://github.com/mapsme/omim/pull/4152.diff","patch_url":"https://github.com/mapsme/omim/pull/4152.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/4152","number":4152,"state":"open","locked":false,"title":"[booking] Booking workflow","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"body":"@ygorshenin \r\n@milchakov \r\n@Zverik \r\n@syershov ","created_at":"2016-08-25T12:51:15Z","updated_at":"2016-10-10T09:50:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8e35497c8866018098f84c3fe9d983e393bf52c9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/4152/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/4152/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/4152/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/ee27bc7f508ccef64869b05cd79dfea44c8dd951","head":{"label":"mgsergio:booking-workflow","ref":"booking-workflow","sha":"ee27bc7f508ccef64869b05cd79dfea44c8dd951","user":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"repo":{"id":43430406,"name":"omim","full_name":"mgsergio/omim","owner":{"login":"mgsergio","id":6658987,"avatar_url":"https://avatars.githubusercontent.com/u/6658987?v=3","gravatar_id":"","url":"https://api.github.com/users/mgsergio","html_url":"https://github.com/mgsergio","followers_url":"https://api.github.com/users/mgsergio/followers","following_url":"https://api.github.com/users/mgsergio/following{/other_user}","gists_url":"https://api.github.com/users/mgsergio/gists{/gist_id}","starred_url":"https://api.github.com/users/mgsergio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgsergio/subscriptions","organizations_url":"https://api.github.com/users/mgsergio/orgs","repos_url":"https://api.github.com/users/mgsergio/repos","events_url":"https://api.github.com/users/mgsergio/events{/privacy}","received_events_url":"https://api.github.com/users/mgsergio/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mgsergio/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/mgsergio/omim","forks_url":"https://api.github.com/repos/mgsergio/omim/forks","keys_url":"https://api.github.com/repos/mgsergio/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mgsergio/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mgsergio/omim/teams","hooks_url":"https://api.github.com/repos/mgsergio/omim/hooks","issue_events_url":"https://api.github.com/repos/mgsergio/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mgsergio/omim/events","assignees_url":"https://api.github.com/repos/mgsergio/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mgsergio/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mgsergio/omim/tags","blobs_url":"https://api.github.com/repos/mgsergio/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mgsergio/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mgsergio/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mgsergio/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mgsergio/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mgsergio/omim/languages","stargazers_url":"https://api.github.com/repos/mgsergio/omim/stargazers","contributors_url":"https://api.github.com/repos/mgsergio/omim/contributors","subscribers_url":"https://api.github.com/repos/mgsergio/omim/subscribers","subscription_url":"https://api.github.com/repos/mgsergio/omim/subscription","commits_url":"https://api.github.com/repos/mgsergio/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mgsergio/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mgsergio/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mgsergio/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mgsergio/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mgsergio/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mgsergio/omim/merges","archive_url":"https://api.github.com/repos/mgsergio/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mgsergio/omim/downloads","issues_url":"https://api.github.com/repos/mgsergio/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mgsergio/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mgsergio/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mgsergio/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mgsergio/omim/labels{/name}","releases_url":"https://api.github.com/repos/mgsergio/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mgsergio/omim/deployments","created_at":"2015-09-30T11:59:31Z","updated_at":"2016-03-17T15:31:31Z","pushed_at":"2016-10-10T09:06:43Z","git_url":"git://github.com/mgsergio/omim.git","ssh_url":"git@github.com:mgsergio/omim.git","clone_url":"https://github.com/mgsergio/omim.git","svn_url":"https://github.com/mgsergio/omim","homepage":null,"size":2663544,"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":"mapsme:master","ref":"master","sha":"569ea6f2842680a66d3426176cd968798cc333cf","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2016-10-10T09:26:02Z","pushed_at":"2016-10-10T09:44:53Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":2815734,"stargazers_count":2002,"watchers_count":2002,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":370,"mirror_url":null,"open_issues_count":346,"forks":370,"open_issues":346,"watchers":2002,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4152"},"html":{"href":"https://github.com/mapsme/omim/pull/4152"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/4152"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/4152/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4152/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/4152/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/ee27bc7f508ccef64869b05cd79dfea44c8dd951"}}}}
{"actor":{"display_login":"ygorshenin"}}