{"action":"created","comment":{"url":"https://api.github.com/repos/fxbox/calendar/pulls/comments/68941929","id":68941929,"diff_hunk":"@@ -55,11 +119,94 @@ export default class IntentParser {\n     return string.trim();\n   }\n \n-  normalise(string = '') {\n-    string = string.replace(/\\s+/g, ' '); // Normalise whitespaces to space.\n-    string = string.trim();\n-    string = string.replace(pattern.punctuation, ''); // Strip punctuations.\n+  normalise(string = '', locale = this.locale) {\n+    // Normalise whitespaces to space.\n+    return string\n+      .replace(/\\s+/g, ' ')\n+      .trim()\n+      // Strip punctuations.\n+      .replace(PATTERNS[locale].punctuation, '');\n+  }\n+\n+  /**\n+   * Build the `regexps` property as an object mapping locale code to list of\n+   * patterns and placeholders pairs.\n+   */\n+  init() {\n+    Object.keys(PATTERNS).forEach((locale) => {\n+      this.regexps[locale] = PATTERNS[locale].patterns.map((phrase) =>\n+        this.buildRegExp(locale, phrase, PATTERNS[locale].placeholders));\n+    });\n+\n+    console.log(this.regexps);\n+  }\n+\n+  buildRegExp(locale = 'en', phrase = '', placeholders) {\n+    phrase = this.normalise(phrase, locale);\n+\n+    const tokens = this.tokenise(phrase);\n+    const order = {};\n+    let placeholderIndex = 0;\n+    let patterns = tokens.map((token) => {\n+      if (token.substr(0, 1) === '[') {\n+        const placeholder = token\n+          .substr(1)\n+          // Strip trailing `]`.\n+          .replace(new RegExp('\\\\]$', 'u'), '');\n+\n+        order[placeholder] = placeholderIndex;","path":"app/js/lib/intent-parser.js","position":181,"original_position":181,"commit_id":"a403707a88943f3d4e0faa23704c85424b5443f4","original_commit_id":"a403707a88943f3d4e0faa23704c85424b5443f4","user":{"login":"samgiles","id":840334,"avatar_url":"https://avatars.githubusercontent.com/u/840334?v=3","gravatar_id":"","url":"https://api.github.com/users/samgiles","html_url":"https://github.com/samgiles","followers_url":"https://api.github.com/users/samgiles/followers","following_url":"https://api.github.com/users/samgiles/following{/other_user}","gists_url":"https://api.github.com/users/samgiles/gists{/gist_id}","starred_url":"https://api.github.com/users/samgiles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samgiles/subscriptions","organizations_url":"https://api.github.com/users/samgiles/orgs","repos_url":"https://api.github.com/users/samgiles/repos","events_url":"https://api.github.com/users/samgiles/events{/privacy}","received_events_url":"https://api.github.com/users/samgiles/received_events","type":"User","site_admin":false},"body":"Maybe a comment somewhere to explain why we save the order of the placeholders?","created_at":"2016-06-29T13:07:43Z","updated_at":"2016-06-29T13:07:43Z","html_url":"https://github.com/fxbox/calendar/pull/9#discussion_r68941929","pull_request_url":"https://api.github.com/repos/fxbox/calendar/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/comments/68941929"},"html":{"href":"https://github.com/fxbox/calendar/pull/9#discussion_r68941929"},"pull_request":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/fxbox/calendar/pulls/9","id":75495060,"html_url":"https://github.com/fxbox/calendar/pull/9","diff_url":"https://github.com/fxbox/calendar/pull/9.diff","patch_url":"https://github.com/fxbox/calendar/pull/9.patch","issue_url":"https://api.github.com/repos/fxbox/calendar/issues/9","number":9,"state":"open","locked":false,"title":"Generate intent parser from regular strings. r=samgiles","user":{"login":"gmarty","id":333865,"avatar_url":"https://avatars.githubusercontent.com/u/333865?v=3","gravatar_id":"","url":"https://api.github.com/users/gmarty","html_url":"https://github.com/gmarty","followers_url":"https://api.github.com/users/gmarty/followers","following_url":"https://api.github.com/users/gmarty/following{/other_user}","gists_url":"https://api.github.com/users/gmarty/gists{/gist_id}","starred_url":"https://api.github.com/users/gmarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmarty/subscriptions","organizations_url":"https://api.github.com/users/gmarty/orgs","repos_url":"https://api.github.com/users/gmarty/repos","events_url":"https://api.github.com/users/gmarty/events{/privacy}","received_events_url":"https://api.github.com/users/gmarty/received_events","type":"User","site_admin":false},"body":"I improved the intent parser to allow the creation of patterns dynamically from regular strings (more user-friendly).\r\nI added samples in French and Japanese too. I'm not suggesting that we should work on i18n now but it's good to know what type of challenges to expect in the future with multilanguage support and get something flexible from day 1.\r\n\r\n@samgiles: what do you think?","created_at":"2016-06-28T15:11:56Z","updated_at":"2016-06-29T13:07:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e4bf31416dbe1ba6c630c7d52c7a547b1b04179","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fxbox/calendar/pulls/9/commits","review_comments_url":"https://api.github.com/repos/fxbox/calendar/pulls/9/comments","review_comment_url":"https://api.github.com/repos/fxbox/calendar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fxbox/calendar/issues/9/comments","statuses_url":"https://api.github.com/repos/fxbox/calendar/statuses/a403707a88943f3d4e0faa23704c85424b5443f4","head":{"label":"gmarty:dyn-intent-parser","ref":"dyn-intent-parser","sha":"a403707a88943f3d4e0faa23704c85424b5443f4","user":{"login":"gmarty","id":333865,"avatar_url":"https://avatars.githubusercontent.com/u/333865?v=3","gravatar_id":"","url":"https://api.github.com/users/gmarty","html_url":"https://github.com/gmarty","followers_url":"https://api.github.com/users/gmarty/followers","following_url":"https://api.github.com/users/gmarty/following{/other_user}","gists_url":"https://api.github.com/users/gmarty/gists{/gist_id}","starred_url":"https://api.github.com/users/gmarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmarty/subscriptions","organizations_url":"https://api.github.com/users/gmarty/orgs","repos_url":"https://api.github.com/users/gmarty/repos","events_url":"https://api.github.com/users/gmarty/events{/privacy}","received_events_url":"https://api.github.com/users/gmarty/received_events","type":"User","site_admin":false},"repo":{"id":61630644,"name":"calendar","full_name":"gmarty/calendar","owner":{"login":"gmarty","id":333865,"avatar_url":"https://avatars.githubusercontent.com/u/333865?v=3","gravatar_id":"","url":"https://api.github.com/users/gmarty","html_url":"https://github.com/gmarty","followers_url":"https://api.github.com/users/gmarty/followers","following_url":"https://api.github.com/users/gmarty/following{/other_user}","gists_url":"https://api.github.com/users/gmarty/gists{/gist_id}","starred_url":"https://api.github.com/users/gmarty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gmarty/subscriptions","organizations_url":"https://api.github.com/users/gmarty/orgs","repos_url":"https://api.github.com/users/gmarty/repos","events_url":"https://api.github.com/users/gmarty/events{/privacy}","received_events_url":"https://api.github.com/users/gmarty/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gmarty/calendar","description":"","fork":true,"url":"https://api.github.com/repos/gmarty/calendar","forks_url":"https://api.github.com/repos/gmarty/calendar/forks","keys_url":"https://api.github.com/repos/gmarty/calendar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gmarty/calendar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gmarty/calendar/teams","hooks_url":"https://api.github.com/repos/gmarty/calendar/hooks","issue_events_url":"https://api.github.com/repos/gmarty/calendar/issues/events{/number}","events_url":"https://api.github.com/repos/gmarty/calendar/events","assignees_url":"https://api.github.com/repos/gmarty/calendar/assignees{/user}","branches_url":"https://api.github.com/repos/gmarty/calendar/branches{/branch}","tags_url":"https://api.github.com/repos/gmarty/calendar/tags","blobs_url":"https://api.github.com/repos/gmarty/calendar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gmarty/calendar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gmarty/calendar/git/refs{/sha}","trees_url":"https://api.github.com/repos/gmarty/calendar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gmarty/calendar/statuses/{sha}","languages_url":"https://api.github.com/repos/gmarty/calendar/languages","stargazers_url":"https://api.github.com/repos/gmarty/calendar/stargazers","contributors_url":"https://api.github.com/repos/gmarty/calendar/contributors","subscribers_url":"https://api.github.com/repos/gmarty/calendar/subscribers","subscription_url":"https://api.github.com/repos/gmarty/calendar/subscription","commits_url":"https://api.github.com/repos/gmarty/calendar/commits{/sha}","git_commits_url":"https://api.github.com/repos/gmarty/calendar/git/commits{/sha}","comments_url":"https://api.github.com/repos/gmarty/calendar/comments{/number}","issue_comment_url":"https://api.github.com/repos/gmarty/calendar/issues/comments{/number}","contents_url":"https://api.github.com/repos/gmarty/calendar/contents/{+path}","compare_url":"https://api.github.com/repos/gmarty/calendar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gmarty/calendar/merges","archive_url":"https://api.github.com/repos/gmarty/calendar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gmarty/calendar/downloads","issues_url":"https://api.github.com/repos/gmarty/calendar/issues{/number}","pulls_url":"https://api.github.com/repos/gmarty/calendar/pulls{/number}","milestones_url":"https://api.github.com/repos/gmarty/calendar/milestones{/number}","notifications_url":"https://api.github.com/repos/gmarty/calendar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gmarty/calendar/labels{/name}","releases_url":"https://api.github.com/repos/gmarty/calendar/releases{/id}","deployments_url":"https://api.github.com/repos/gmarty/calendar/deployments","created_at":"2016-06-21T12:04:00Z","updated_at":"2016-06-21T12:04:02Z","pushed_at":"2016-06-29T12:44:30Z","git_url":"git://github.com/gmarty/calendar.git","ssh_url":"git@github.com:gmarty/calendar.git","clone_url":"https://github.com/gmarty/calendar.git","svn_url":"https://github.com/gmarty/calendar","homepage":null,"size":2140,"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":"fxbox:master","ref":"master","sha":"d7b5cd0322e85dbe56a33621f65ac206f9fc5960","user":{"login":"fxbox","id":17052474,"avatar_url":"https://avatars.githubusercontent.com/u/17052474?v=3","gravatar_id":"","url":"https://api.github.com/users/fxbox","html_url":"https://github.com/fxbox","followers_url":"https://api.github.com/users/fxbox/followers","following_url":"https://api.github.com/users/fxbox/following{/other_user}","gists_url":"https://api.github.com/users/fxbox/gists{/gist_id}","starred_url":"https://api.github.com/users/fxbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fxbox/subscriptions","organizations_url":"https://api.github.com/users/fxbox/orgs","repos_url":"https://api.github.com/users/fxbox/repos","events_url":"https://api.github.com/users/fxbox/events{/privacy}","received_events_url":"https://api.github.com/users/fxbox/received_events","type":"Organization","site_admin":false},"repo":{"id":61548154,"name":"calendar","full_name":"fxbox/calendar","owner":{"login":"fxbox","id":17052474,"avatar_url":"https://avatars.githubusercontent.com/u/17052474?v=3","gravatar_id":"","url":"https://api.github.com/users/fxbox","html_url":"https://github.com/fxbox","followers_url":"https://api.github.com/users/fxbox/followers","following_url":"https://api.github.com/users/fxbox/following{/other_user}","gists_url":"https://api.github.com/users/fxbox/gists{/gist_id}","starred_url":"https://api.github.com/users/fxbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fxbox/subscriptions","organizations_url":"https://api.github.com/users/fxbox/orgs","repos_url":"https://api.github.com/users/fxbox/repos","events_url":"https://api.github.com/users/fxbox/events{/privacy}","received_events_url":"https://api.github.com/users/fxbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fxbox/calendar","description":"","fork":false,"url":"https://api.github.com/repos/fxbox/calendar","forks_url":"https://api.github.com/repos/fxbox/calendar/forks","keys_url":"https://api.github.com/repos/fxbox/calendar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fxbox/calendar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fxbox/calendar/teams","hooks_url":"https://api.github.com/repos/fxbox/calendar/hooks","issue_events_url":"https://api.github.com/repos/fxbox/calendar/issues/events{/number}","events_url":"https://api.github.com/repos/fxbox/calendar/events","assignees_url":"https://api.github.com/repos/fxbox/calendar/assignees{/user}","branches_url":"https://api.github.com/repos/fxbox/calendar/branches{/branch}","tags_url":"https://api.github.com/repos/fxbox/calendar/tags","blobs_url":"https://api.github.com/repos/fxbox/calendar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fxbox/calendar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fxbox/calendar/git/refs{/sha}","trees_url":"https://api.github.com/repos/fxbox/calendar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fxbox/calendar/statuses/{sha}","languages_url":"https://api.github.com/repos/fxbox/calendar/languages","stargazers_url":"https://api.github.com/repos/fxbox/calendar/stargazers","contributors_url":"https://api.github.com/repos/fxbox/calendar/contributors","subscribers_url":"https://api.github.com/repos/fxbox/calendar/subscribers","subscription_url":"https://api.github.com/repos/fxbox/calendar/subscription","commits_url":"https://api.github.com/repos/fxbox/calendar/commits{/sha}","git_commits_url":"https://api.github.com/repos/fxbox/calendar/git/commits{/sha}","comments_url":"https://api.github.com/repos/fxbox/calendar/comments{/number}","issue_comment_url":"https://api.github.com/repos/fxbox/calendar/issues/comments{/number}","contents_url":"https://api.github.com/repos/fxbox/calendar/contents/{+path}","compare_url":"https://api.github.com/repos/fxbox/calendar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fxbox/calendar/merges","archive_url":"https://api.github.com/repos/fxbox/calendar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fxbox/calendar/downloads","issues_url":"https://api.github.com/repos/fxbox/calendar/issues{/number}","pulls_url":"https://api.github.com/repos/fxbox/calendar/pulls{/number}","milestones_url":"https://api.github.com/repos/fxbox/calendar/milestones{/number}","notifications_url":"https://api.github.com/repos/fxbox/calendar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fxbox/calendar/labels{/name}","releases_url":"https://api.github.com/repos/fxbox/calendar/releases{/id}","deployments_url":"https://api.github.com/repos/fxbox/calendar/deployments","created_at":"2016-06-20T13:03:37Z","updated_at":"2016-06-20T16:18:26Z","pushed_at":"2016-06-29T12:49:06Z","git_url":"git://github.com/fxbox/calendar.git","ssh_url":"git@github.com:fxbox/calendar.git","clone_url":"https://github.com/fxbox/calendar.git","svn_url":"https://github.com/fxbox/calendar","homepage":null,"size":2195,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/9"},"html":{"href":"https://github.com/fxbox/calendar/pull/9"},"issue":{"href":"https://api.github.com/repos/fxbox/calendar/issues/9"},"comments":{"href":"https://api.github.com/repos/fxbox/calendar/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fxbox/calendar/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/fxbox/calendar/statuses/a403707a88943f3d4e0faa23704c85424b5443f4"}}}}
{"actor":{"display_login":"samgiles"}}