{"action":"created","comment":{"url":"https://api.github.com/repos/9livesdata/whylog/pulls/comments/58403115","id":58403115,"diff_hunk":"@@ -0,0 +1,107 @@\n+\"\"\"\n+Methods responsible for finding spans (potential params) for given text.\n+Some heuristic included.\n+\"\"\"\n+\n+import re\n+from datetime import datetime\n+\n+from dateutil.parser import parse as date_parse\n+\n+from whylog.assistant.const import DataType, DateParams\n+from whylog.assistant.regex_assistant.regex import DateFromFutureError, create_date_regex\n+from whylog.assistant.span import Span, not_overlapping_spans, sort_as_date\n+\n+\n+def find_date_spans(text, regexes=None):\n+    regexes = regexes or {}\n+\n+    forced_date_spans = _find_date_spans_by_force(text)\n+    regex_date_spans = _find_date_spans_by_regex(regexes, text)\n+\n+    unique_spans = forced_date_spans.union(regex_date_spans)\n+\n+    ordered_date_spans = sort_as_date(unique_spans)\n+\n+    best_spans = not_overlapping_spans(ordered_date_spans)\n+\n+    return best_spans\n+\n+\n+def _find_date_spans_by_regex(regexes, text):\n+    return _find_spans_by_regex(\n+        regexes,\n+        text,\n+        pattern_creator=create_date_regex,\n+        converter=DataType.DATE\n+    )\n+\n+\n+def _find_date_spans_by_force(text):\n+    date_spans = set()\n+\n+    proper_starts, proper_ends = _possible_span_starts_and_ends(text)\n+    proper_ends.reverse()\n+\n+    date_now = datetime.now()\n+    not_overlapping_start = 0\n+\n+    for start in proper_starts:\n+        if start < not_overlapping_start:\n+            continue\n+        for end in proper_ends:\n+            if end < start + DateParams.MIN_DATE_LENGTH:\n+                break\n+            try:\n+                date_text = text[start:end]\n+                date = date_parse(date_text)\n+                if date_now.year - date.year < -1:\n+                    raise DateFromFutureError(date, date_text)\n+            except (ValueError, DateFromFutureError):\n+                # TODO: how to write it without bad looking 'pass'?\n+                pass\n+            else:\n+                date_spans.add(\n+                    Span(\n+                        start,\n+                        end,\n+                        pattern_creator=create_date_regex,\n+                        data_type=DataType.DATE\n+                    )\n+                )\n+                not_overlapping_start = end\n+                # break, because we don't care about shorter date groups\n+                break\n+    return date_spans\n+\n+\n+def _find_spans_by_regex(regexes, text, pattern_creator=None, converter=DataType.STRING):\n+    spans = set()\n+    for compiled_regex, regex in regexes.items():\n+        for match in re.finditer(compiled_regex, text):\n+            s = Span(match.start(0), match.end(0), regex, pattern_creator, converter)","path":"whylog/assistant/spans_finding.py","position":null,"original_position":82,"commit_id":"f1aab9d9b14421b4c43e7080778436622d8088ba","original_commit_id":"3e1e4729ed7e47a1edb3a15a82e79c3edcd2bb0d","user":{"login":"epawlowska","id":15253107,"avatar_url":"https://avatars.githubusercontent.com/u/15253107?v=3","gravatar_id":"","url":"https://api.github.com/users/epawlowska","html_url":"https://github.com/epawlowska","followers_url":"https://api.github.com/users/epawlowska/followers","following_url":"https://api.github.com/users/epawlowska/following{/other_user}","gists_url":"https://api.github.com/users/epawlowska/gists{/gist_id}","starred_url":"https://api.github.com/users/epawlowska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epawlowska/subscriptions","organizations_url":"https://api.github.com/users/epawlowska/orgs","repos_url":"https://api.github.com/users/epawlowska/repos","events_url":"https://api.github.com/users/epawlowska/events{/privacy}","received_events_url":"https://api.github.com/users/epawlowska/received_events","type":"User","site_admin":false},"body":"Agree.","created_at":"2016-04-04T16:18:00Z","updated_at":"2016-04-04T16:18:00Z","html_url":"https://github.com/9livesdata/whylog/pull/79#discussion_r58403115","pull_request_url":"https://api.github.com/repos/9livesdata/whylog/pulls/79","_links":{"self":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/comments/58403115"},"html":{"href":"https://github.com/9livesdata/whylog/pull/79#discussion_r58403115"},"pull_request":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/79"}}},"pull_request":{"url":"https://api.github.com/repos/9livesdata/whylog/pulls/79","id":64996905,"html_url":"https://github.com/9livesdata/whylog/pull/79","diff_url":"https://github.com/9livesdata/whylog/pull/79.diff","patch_url":"https://github.com/9livesdata/whylog/pull/79.patch","issue_url":"https://api.github.com/repos/9livesdata/whylog/issues/79","number":79,"state":"open","locked":false,"title":"RegexAssistant: guessing regex with date groups","user":{"login":"epawlowska","id":15253107,"avatar_url":"https://avatars.githubusercontent.com/u/15253107?v=3","gravatar_id":"","url":"https://api.github.com/users/epawlowska","html_url":"https://github.com/epawlowska","followers_url":"https://api.github.com/users/epawlowska/followers","following_url":"https://api.github.com/users/epawlowska/following{/other_user}","gists_url":"https://api.github.com/users/epawlowska/gists{/gist_id}","starred_url":"https://api.github.com/users/epawlowska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epawlowska/subscriptions","organizations_url":"https://api.github.com/users/epawlowska/orgs","repos_url":"https://api.github.com/users/epawlowska/repos","events_url":"https://api.github.com/users/epawlowska/events{/privacy}","received_events_url":"https://api.github.com/users/epawlowska/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-01T19:57:59Z","updated_at":"2016-04-04T16:18:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83200fa703b85b6f3b4433e683c01c00e3e3f1f6","assignee":{"login":"andrzejgorski","id":13272962,"avatar_url":"https://avatars.githubusercontent.com/u/13272962?v=3","gravatar_id":"","url":"https://api.github.com/users/andrzejgorski","html_url":"https://github.com/andrzejgorski","followers_url":"https://api.github.com/users/andrzejgorski/followers","following_url":"https://api.github.com/users/andrzejgorski/following{/other_user}","gists_url":"https://api.github.com/users/andrzejgorski/gists{/gist_id}","starred_url":"https://api.github.com/users/andrzejgorski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrzejgorski/subscriptions","organizations_url":"https://api.github.com/users/andrzejgorski/orgs","repos_url":"https://api.github.com/users/andrzejgorski/repos","events_url":"https://api.github.com/users/andrzejgorski/events{/privacy}","received_events_url":"https://api.github.com/users/andrzejgorski/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/9livesdata/whylog/pulls/79/commits","review_comments_url":"https://api.github.com/repos/9livesdata/whylog/pulls/79/comments","review_comment_url":"https://api.github.com/repos/9livesdata/whylog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/9livesdata/whylog/issues/79/comments","statuses_url":"https://api.github.com/repos/9livesdata/whylog/statuses/f1aab9d9b14421b4c43e7080778436622d8088ba","head":{"label":"epawlowska:master","ref":"master","sha":"f1aab9d9b14421b4c43e7080778436622d8088ba","user":{"login":"epawlowska","id":15253107,"avatar_url":"https://avatars.githubusercontent.com/u/15253107?v=3","gravatar_id":"","url":"https://api.github.com/users/epawlowska","html_url":"https://github.com/epawlowska","followers_url":"https://api.github.com/users/epawlowska/followers","following_url":"https://api.github.com/users/epawlowska/following{/other_user}","gists_url":"https://api.github.com/users/epawlowska/gists{/gist_id}","starred_url":"https://api.github.com/users/epawlowska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epawlowska/subscriptions","organizations_url":"https://api.github.com/users/epawlowska/orgs","repos_url":"https://api.github.com/users/epawlowska/repos","events_url":"https://api.github.com/users/epawlowska/events{/privacy}","received_events_url":"https://api.github.com/users/epawlowska/received_events","type":"User","site_admin":false},"repo":{"id":46919661,"name":"whylog","full_name":"epawlowska/whylog","owner":{"login":"epawlowska","id":15253107,"avatar_url":"https://avatars.githubusercontent.com/u/15253107?v=3","gravatar_id":"","url":"https://api.github.com/users/epawlowska","html_url":"https://github.com/epawlowska","followers_url":"https://api.github.com/users/epawlowska/followers","following_url":"https://api.github.com/users/epawlowska/following{/other_user}","gists_url":"https://api.github.com/users/epawlowska/gists{/gist_id}","starred_url":"https://api.github.com/users/epawlowska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epawlowska/subscriptions","organizations_url":"https://api.github.com/users/epawlowska/orgs","repos_url":"https://api.github.com/users/epawlowska/repos","events_url":"https://api.github.com/users/epawlowska/events{/privacy}","received_events_url":"https://api.github.com/users/epawlowska/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/epawlowska/whylog","description":"","fork":true,"url":"https://api.github.com/repos/epawlowska/whylog","forks_url":"https://api.github.com/repos/epawlowska/whylog/forks","keys_url":"https://api.github.com/repos/epawlowska/whylog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/epawlowska/whylog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/epawlowska/whylog/teams","hooks_url":"https://api.github.com/repos/epawlowska/whylog/hooks","issue_events_url":"https://api.github.com/repos/epawlowska/whylog/issues/events{/number}","events_url":"https://api.github.com/repos/epawlowska/whylog/events","assignees_url":"https://api.github.com/repos/epawlowska/whylog/assignees{/user}","branches_url":"https://api.github.com/repos/epawlowska/whylog/branches{/branch}","tags_url":"https://api.github.com/repos/epawlowska/whylog/tags","blobs_url":"https://api.github.com/repos/epawlowska/whylog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/epawlowska/whylog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/epawlowska/whylog/git/refs{/sha}","trees_url":"https://api.github.com/repos/epawlowska/whylog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/epawlowska/whylog/statuses/{sha}","languages_url":"https://api.github.com/repos/epawlowska/whylog/languages","stargazers_url":"https://api.github.com/repos/epawlowska/whylog/stargazers","contributors_url":"https://api.github.com/repos/epawlowska/whylog/contributors","subscribers_url":"https://api.github.com/repos/epawlowska/whylog/subscribers","subscription_url":"https://api.github.com/repos/epawlowska/whylog/subscription","commits_url":"https://api.github.com/repos/epawlowska/whylog/commits{/sha}","git_commits_url":"https://api.github.com/repos/epawlowska/whylog/git/commits{/sha}","comments_url":"https://api.github.com/repos/epawlowska/whylog/comments{/number}","issue_comment_url":"https://api.github.com/repos/epawlowska/whylog/issues/comments{/number}","contents_url":"https://api.github.com/repos/epawlowska/whylog/contents/{+path}","compare_url":"https://api.github.com/repos/epawlowska/whylog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/epawlowska/whylog/merges","archive_url":"https://api.github.com/repos/epawlowska/whylog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/epawlowska/whylog/downloads","issues_url":"https://api.github.com/repos/epawlowska/whylog/issues{/number}","pulls_url":"https://api.github.com/repos/epawlowska/whylog/pulls{/number}","milestones_url":"https://api.github.com/repos/epawlowska/whylog/milestones{/number}","notifications_url":"https://api.github.com/repos/epawlowska/whylog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/epawlowska/whylog/labels{/name}","releases_url":"https://api.github.com/repos/epawlowska/whylog/releases{/id}","deployments_url":"https://api.github.com/repos/epawlowska/whylog/deployments","created_at":"2015-11-26T10:22:17Z","updated_at":"2016-03-01T22:57:23Z","pushed_at":"2016-04-04T16:14:51Z","git_url":"git://github.com/epawlowska/whylog.git","ssh_url":"git@github.com:epawlowska/whylog.git","clone_url":"https://github.com/epawlowska/whylog.git","svn_url":"https://github.com/epawlowska/whylog","homepage":null,"size":372,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"9livesdata:master","ref":"master","sha":"bed01e4546844b147c0873f2e8da6496095de148","user":{"login":"9livesdata","id":15250580,"avatar_url":"https://avatars.githubusercontent.com/u/15250580?v=3","gravatar_id":"","url":"https://api.github.com/users/9livesdata","html_url":"https://github.com/9livesdata","followers_url":"https://api.github.com/users/9livesdata/followers","following_url":"https://api.github.com/users/9livesdata/following{/other_user}","gists_url":"https://api.github.com/users/9livesdata/gists{/gist_id}","starred_url":"https://api.github.com/users/9livesdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/9livesdata/subscriptions","organizations_url":"https://api.github.com/users/9livesdata/orgs","repos_url":"https://api.github.com/users/9livesdata/repos","events_url":"https://api.github.com/users/9livesdata/events{/privacy}","received_events_url":"https://api.github.com/users/9livesdata/received_events","type":"Organization","site_admin":false},"repo":{"id":44754618,"name":"whylog","full_name":"9livesdata/whylog","owner":{"login":"9livesdata","id":15250580,"avatar_url":"https://avatars.githubusercontent.com/u/15250580?v=3","gravatar_id":"","url":"https://api.github.com/users/9livesdata","html_url":"https://github.com/9livesdata","followers_url":"https://api.github.com/users/9livesdata/followers","following_url":"https://api.github.com/users/9livesdata/following{/other_user}","gists_url":"https://api.github.com/users/9livesdata/gists{/gist_id}","starred_url":"https://api.github.com/users/9livesdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/9livesdata/subscriptions","organizations_url":"https://api.github.com/users/9livesdata/orgs","repos_url":"https://api.github.com/users/9livesdata/repos","events_url":"https://api.github.com/users/9livesdata/events{/privacy}","received_events_url":"https://api.github.com/users/9livesdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/9livesdata/whylog","description":"","fork":false,"url":"https://api.github.com/repos/9livesdata/whylog","forks_url":"https://api.github.com/repos/9livesdata/whylog/forks","keys_url":"https://api.github.com/repos/9livesdata/whylog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/9livesdata/whylog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/9livesdata/whylog/teams","hooks_url":"https://api.github.com/repos/9livesdata/whylog/hooks","issue_events_url":"https://api.github.com/repos/9livesdata/whylog/issues/events{/number}","events_url":"https://api.github.com/repos/9livesdata/whylog/events","assignees_url":"https://api.github.com/repos/9livesdata/whylog/assignees{/user}","branches_url":"https://api.github.com/repos/9livesdata/whylog/branches{/branch}","tags_url":"https://api.github.com/repos/9livesdata/whylog/tags","blobs_url":"https://api.github.com/repos/9livesdata/whylog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/9livesdata/whylog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/9livesdata/whylog/git/refs{/sha}","trees_url":"https://api.github.com/repos/9livesdata/whylog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/9livesdata/whylog/statuses/{sha}","languages_url":"https://api.github.com/repos/9livesdata/whylog/languages","stargazers_url":"https://api.github.com/repos/9livesdata/whylog/stargazers","contributors_url":"https://api.github.com/repos/9livesdata/whylog/contributors","subscribers_url":"https://api.github.com/repos/9livesdata/whylog/subscribers","subscription_url":"https://api.github.com/repos/9livesdata/whylog/subscription","commits_url":"https://api.github.com/repos/9livesdata/whylog/commits{/sha}","git_commits_url":"https://api.github.com/repos/9livesdata/whylog/git/commits{/sha}","comments_url":"https://api.github.com/repos/9livesdata/whylog/comments{/number}","issue_comment_url":"https://api.github.com/repos/9livesdata/whylog/issues/comments{/number}","contents_url":"https://api.github.com/repos/9livesdata/whylog/contents/{+path}","compare_url":"https://api.github.com/repos/9livesdata/whylog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/9livesdata/whylog/merges","archive_url":"https://api.github.com/repos/9livesdata/whylog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/9livesdata/whylog/downloads","issues_url":"https://api.github.com/repos/9livesdata/whylog/issues{/number}","pulls_url":"https://api.github.com/repos/9livesdata/whylog/pulls{/number}","milestones_url":"https://api.github.com/repos/9livesdata/whylog/milestones{/number}","notifications_url":"https://api.github.com/repos/9livesdata/whylog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/9livesdata/whylog/labels{/name}","releases_url":"https://api.github.com/repos/9livesdata/whylog/releases{/id}","deployments_url":"https://api.github.com/repos/9livesdata/whylog/deployments","created_at":"2015-10-22T15:28:20Z","updated_at":"2016-02-28T22:54:29Z","pushed_at":"2016-04-04T16:14:52Z","git_url":"git://github.com/9livesdata/whylog.git","ssh_url":"git@github.com:9livesdata/whylog.git","clone_url":"https://github.com/9livesdata/whylog.git","svn_url":"https://github.com/9livesdata/whylog","homepage":null,"size":658,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":25,"forks":5,"open_issues":25,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/79"},"html":{"href":"https://github.com/9livesdata/whylog/pull/79"},"issue":{"href":"https://api.github.com/repos/9livesdata/whylog/issues/79"},"comments":{"href":"https://api.github.com/repos/9livesdata/whylog/issues/79/comments"},"review_comments":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/79/comments"},"review_comment":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/9livesdata/whylog/pulls/79/commits"},"statuses":{"href":"https://api.github.com/repos/9livesdata/whylog/statuses/f1aab9d9b14421b4c43e7080778436622d8088ba"}}}}