{"action":"created","comment":{"url":"https://api.github.com/repos/bigmlcom/python/pulls/comments/38882087","id":38882087,"diff_hunk":"@@ -0,0 +1,210 @@\n+# -*- coding: utf-8 -*-\n+#!/usr/bin/env python\n+#\n+# Copyright 2015 BigML\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\"); you may\n+# not use this file except in compliance with the License. You may obtain\n+# a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+# License for the specific language governing permissions and limitations\n+# under the License.\n+\n+\"\"\"Path structure based on Predicates for the BigML local Model\n+\n+This module defines an auxiliary Path structure that is used\n+to store the predicates' info.\n+\n+\"\"\"\n+from bigml.predicate import Predicate\n+\n+\n+EXTENDED = 0\n+BRIEF = 1\n+NUMERIC = 'numeric'\n+CATEGORICAL = 'categorical'\n+TEXT = 'text'\n+DATETIME = 'datetime'\n+\n+REVERSE_OP = {'<': '>', '>': '<'}\n+\n+\n+def reverse(operator):\n+    \"\"\"Reverses the unequality operators\n+\n+    \"\"\"\n+    return \"%s%s\" % (REVERSE_OP[operator[0]], operator[1:])\n+\n+\n+def merge_rules(list_of_predicates, field_info, fields, label='name'):\n+    \"\"\"Summarizes the predicates referring to the same field\n+\n+    \"\"\"\n+    field_type = field_info['optype']\n+    if field_type == NUMERIC:\n+        minor = (None, float('-inf'), True)\n+        major = (None, float('inf'), True)\n+        equal = None\n+        for predicate in list_of_predicates:\n+            if (predicate.operator.startswith('>') and\n+                    predicate.value > minor[1]):\n+                minor = (predicate, predicate.value,\n+                         minor[2] and predicate.missing)\n+            if (predicate.operator.startswith('<') and\n+                    predicate.value < major[1]):\n+                major = (predicate, predicate.value,\n+                         major[2] and predicate.missing)\n+            if predicate.operator[0] in ['!', '=', '/', 'i']:\n+                equal = predicate\n+                break\n+        if equal is not None:\n+            return equal.to_rule(fields, label=label)\n+        rule = u''\n+        name = field_info[label]\n+\n+        if minor[0] is not None and major[0] is not None:\n+            predicate, value, missing = minor\n+            rule = u\"%s %s \" % (value, reverse(predicate.operator))\n+            rule += name\n+            predicate, value, missing = major\n+            rule += u\" %s %s \" % (predicate.operator, value)\n+            if missing and minor[3]:\n+                rule += u\" or missing\"\n+        else:\n+            predicate = minor[0] if minor[0] is not None else major[0]\n+            rule = predicate.to_rule(fields, label=label)\n+        return rule\n+\n+    if field_type == TEXT:\n+        contains = []\n+        not_contains = []\n+        for predicate in list_of_predicates:\n+            if ((predicate.operator == '<' and predicate.value <= 1) or\n+                    (predicate.operator == '<=' and predicate.value == 0)):\n+                not_contains.append(predicate)\n+            else:\n+                contains.append(predicate)\n+        rules = []\n+        rules_not = []\n+        if contains:\n+            rules.append(contains[0].to_rule(fields, label=label).strip())\n+            for predicate in contains[1:]:\n+                if not predicate.term in rules:\n+                    rules.append(predicate.term)\n+        rule = u\" and \".join(rules)\n+        if not_contains:\n+            if not rules:\n+                rules_not.append(\n+                    not_contains[0].to_rule(fields, label=label).strip())\n+            else:\n+                rules_not.append(\n+                    \" and %s\" % \\\n+                    not_contains[0].to_rule(fields, label=None).strip())\n+            for predicate in not_contains[1:]:\n+                if not predicate.term in rules_not:\n+                    rules_not.append(predicate.term)\n+        rule += u\" or \".join(rules_not)\n+        return rule\n+\n+\n+    if field_type == CATEGORICAL:\n+        equal = []\n+        not_equal = []\n+        for predicate in list_of_predicates:\n+            if predicate.operator.startswith(\"!\"):\n+                not_equal.append(predicate)\n+            else:\n+                equal.append(predicate)\n+        rules = []\n+        rules_not = []\n+        if equal:\n+            rules.append(equal[0].to_rule(fields, label=label).strip())\n+            for predicate in equal[1:]:\n+                if not predicate.value in rules:\n+                    rules.append(predicate.value)\n+        rule = u\" and \".join(rules)\n+        if not_equal and not rules:\n+            rules_not.append(not_equal[0].to_rule(fields, label=label).strip())\n+            for predicate in not_equal[1:]:\n+                if not predicate.value in rules_not:\n+                    rules_not.append(predicate.value)\n+        rule += u\" or \".join(rules_not)\n+        return rule\n+\n+    return \" and \".join(\n+        [predicate.to_rule(fields, label=label).strip() for\n+         predicate in list_of_predicates])","path":"bigml/path.py","position":141,"original_position":141,"commit_id":"8afa39ef3d9d16ebd48fabe3cb55c781a46c0641","original_commit_id":"8afa39ef3d9d16ebd48fabe3cb55c781a46c0641","user":{"login":"jaor","id":80719,"avatar_url":"https://avatars.githubusercontent.com/u/80719?v=3","gravatar_id":"","url":"https://api.github.com/users/jaor","html_url":"https://github.com/jaor","followers_url":"https://api.github.com/users/jaor/followers","following_url":"https://api.github.com/users/jaor/following{/other_user}","gists_url":"https://api.github.com/users/jaor/gists{/gist_id}","starred_url":"https://api.github.com/users/jaor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaor/subscriptions","organizations_url":"https://api.github.com/users/jaor/orgs","repos_url":"https://api.github.com/users/jaor/repos","events_url":"https://api.github.com/users/jaor/events{/privacy}","received_events_url":"https://api.github.com/users/jaor/received_events","type":"User","site_admin":false},"body":"three functions?","created_at":"2015-09-07T23:24:36Z","updated_at":"2015-09-07T23:24:36Z","html_url":"https://github.com/bigmlcom/python/pull/150#discussion_r38882087","pull_request_url":"https://api.github.com/repos/bigmlcom/python/pulls/150","_links":{"self":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/comments/38882087"},"html":{"href":"https://github.com/bigmlcom/python/pull/150#discussion_r38882087"},"pull_request":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/150"}}},"pull_request":{"url":"https://api.github.com/repos/bigmlcom/python/pulls/150","id":44382763,"html_url":"https://github.com/bigmlcom/python/pull/150","diff_url":"https://github.com/bigmlcom/python/pull/150.diff","patch_url":"https://github.com/bigmlcom/python/pull/150.patch","issue_url":"https://api.github.com/repos/bigmlcom/python/issues/150","number":150,"state":"open","locked":false,"title":"Brief sum: compressing summary and changing tests to be in a project","user":{"login":"mmerce","id":722203,"avatar_url":"https://avatars.githubusercontent.com/u/722203?v=3","gravatar_id":"","url":"https://api.github.com/users/mmerce","html_url":"https://github.com/mmerce","followers_url":"https://api.github.com/users/mmerce/followers","following_url":"https://api.github.com/users/mmerce/following{/other_user}","gists_url":"https://api.github.com/users/mmerce/gists{/gist_id}","starred_url":"https://api.github.com/users/mmerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmerce/subscriptions","organizations_url":"https://api.github.com/users/mmerce/orgs","repos_url":"https://api.github.com/users/mmerce/repos","events_url":"https://api.github.com/users/mmerce/events{/privacy}","received_events_url":"https://api.github.com/users/mmerce/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-07T23:19:29Z","updated_at":"2015-09-07T23:24:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b3c1a244cee83fafc76c111b4a39d603122fe161","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bigmlcom/python/pulls/150/commits","review_comments_url":"https://api.github.com/repos/bigmlcom/python/pulls/150/comments","review_comment_url":"https://api.github.com/repos/bigmlcom/python/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bigmlcom/python/issues/150/comments","statuses_url":"https://api.github.com/repos/bigmlcom/python/statuses/8afa39ef3d9d16ebd48fabe3cb55c781a46c0641","head":{"label":"mmerce:brief_sum","ref":"brief_sum","sha":"8afa39ef3d9d16ebd48fabe3cb55c781a46c0641","user":{"login":"mmerce","id":722203,"avatar_url":"https://avatars.githubusercontent.com/u/722203?v=3","gravatar_id":"","url":"https://api.github.com/users/mmerce","html_url":"https://github.com/mmerce","followers_url":"https://api.github.com/users/mmerce/followers","following_url":"https://api.github.com/users/mmerce/following{/other_user}","gists_url":"https://api.github.com/users/mmerce/gists{/gist_id}","starred_url":"https://api.github.com/users/mmerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmerce/subscriptions","organizations_url":"https://api.github.com/users/mmerce/orgs","repos_url":"https://api.github.com/users/mmerce/repos","events_url":"https://api.github.com/users/mmerce/events{/privacy}","received_events_url":"https://api.github.com/users/mmerce/received_events","type":"User","site_admin":false},"repo":{"id":5256921,"name":"python","full_name":"mmerce/python","owner":{"login":"mmerce","id":722203,"avatar_url":"https://avatars.githubusercontent.com/u/722203?v=3","gravatar_id":"","url":"https://api.github.com/users/mmerce","html_url":"https://github.com/mmerce","followers_url":"https://api.github.com/users/mmerce/followers","following_url":"https://api.github.com/users/mmerce/following{/other_user}","gists_url":"https://api.github.com/users/mmerce/gists{/gist_id}","starred_url":"https://api.github.com/users/mmerce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmerce/subscriptions","organizations_url":"https://api.github.com/users/mmerce/orgs","repos_url":"https://api.github.com/users/mmerce/repos","events_url":"https://api.github.com/users/mmerce/events{/privacy}","received_events_url":"https://api.github.com/users/mmerce/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mmerce/python","description":"Simple Python bindings for BigML.io","fork":true,"url":"https://api.github.com/repos/mmerce/python","forks_url":"https://api.github.com/repos/mmerce/python/forks","keys_url":"https://api.github.com/repos/mmerce/python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mmerce/python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mmerce/python/teams","hooks_url":"https://api.github.com/repos/mmerce/python/hooks","issue_events_url":"https://api.github.com/repos/mmerce/python/issues/events{/number}","events_url":"https://api.github.com/repos/mmerce/python/events","assignees_url":"https://api.github.com/repos/mmerce/python/assignees{/user}","branches_url":"https://api.github.com/repos/mmerce/python/branches{/branch}","tags_url":"https://api.github.com/repos/mmerce/python/tags","blobs_url":"https://api.github.com/repos/mmerce/python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mmerce/python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mmerce/python/git/refs{/sha}","trees_url":"https://api.github.com/repos/mmerce/python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mmerce/python/statuses/{sha}","languages_url":"https://api.github.com/repos/mmerce/python/languages","stargazers_url":"https://api.github.com/repos/mmerce/python/stargazers","contributors_url":"https://api.github.com/repos/mmerce/python/contributors","subscribers_url":"https://api.github.com/repos/mmerce/python/subscribers","subscription_url":"https://api.github.com/repos/mmerce/python/subscription","commits_url":"https://api.github.com/repos/mmerce/python/commits{/sha}","git_commits_url":"https://api.github.com/repos/mmerce/python/git/commits{/sha}","comments_url":"https://api.github.com/repos/mmerce/python/comments{/number}","issue_comment_url":"https://api.github.com/repos/mmerce/python/issues/comments{/number}","contents_url":"https://api.github.com/repos/mmerce/python/contents/{+path}","compare_url":"https://api.github.com/repos/mmerce/python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mmerce/python/merges","archive_url":"https://api.github.com/repos/mmerce/python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mmerce/python/downloads","issues_url":"https://api.github.com/repos/mmerce/python/issues{/number}","pulls_url":"https://api.github.com/repos/mmerce/python/pulls{/number}","milestones_url":"https://api.github.com/repos/mmerce/python/milestones{/number}","notifications_url":"https://api.github.com/repos/mmerce/python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mmerce/python/labels{/name}","releases_url":"https://api.github.com/repos/mmerce/python/releases{/id}","created_at":"2012-08-01T08:38:09Z","updated_at":"2014-06-20T16:57:36Z","pushed_at":"2015-09-07T23:16:53Z","git_url":"git://github.com/mmerce/python.git","ssh_url":"git@github.com:mmerce/python.git","clone_url":"https://github.com/mmerce/python.git","svn_url":"https://github.com/mmerce/python","homepage":null,"size":2655,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"bigmlcom:next","ref":"next","sha":"6c9f6a37a0317da263c84c9dc2bdff0eb76051a6","user":{"login":"bigmlcom","id":702185,"avatar_url":"https://avatars.githubusercontent.com/u/702185?v=3","gravatar_id":"","url":"https://api.github.com/users/bigmlcom","html_url":"https://github.com/bigmlcom","followers_url":"https://api.github.com/users/bigmlcom/followers","following_url":"https://api.github.com/users/bigmlcom/following{/other_user}","gists_url":"https://api.github.com/users/bigmlcom/gists{/gist_id}","starred_url":"https://api.github.com/users/bigmlcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigmlcom/subscriptions","organizations_url":"https://api.github.com/users/bigmlcom/orgs","repos_url":"https://api.github.com/users/bigmlcom/repos","events_url":"https://api.github.com/users/bigmlcom/events{/privacy}","received_events_url":"https://api.github.com/users/bigmlcom/received_events","type":"Organization","site_admin":false},"repo":{"id":4196332,"name":"python","full_name":"bigmlcom/python","owner":{"login":"bigmlcom","id":702185,"avatar_url":"https://avatars.githubusercontent.com/u/702185?v=3","gravatar_id":"","url":"https://api.github.com/users/bigmlcom","html_url":"https://github.com/bigmlcom","followers_url":"https://api.github.com/users/bigmlcom/followers","following_url":"https://api.github.com/users/bigmlcom/following{/other_user}","gists_url":"https://api.github.com/users/bigmlcom/gists{/gist_id}","starred_url":"https://api.github.com/users/bigmlcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigmlcom/subscriptions","organizations_url":"https://api.github.com/users/bigmlcom/orgs","repos_url":"https://api.github.com/users/bigmlcom/repos","events_url":"https://api.github.com/users/bigmlcom/events{/privacy}","received_events_url":"https://api.github.com/users/bigmlcom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bigmlcom/python","description":"Simple Python bindings for BigML.io","fork":false,"url":"https://api.github.com/repos/bigmlcom/python","forks_url":"https://api.github.com/repos/bigmlcom/python/forks","keys_url":"https://api.github.com/repos/bigmlcom/python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bigmlcom/python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bigmlcom/python/teams","hooks_url":"https://api.github.com/repos/bigmlcom/python/hooks","issue_events_url":"https://api.github.com/repos/bigmlcom/python/issues/events{/number}","events_url":"https://api.github.com/repos/bigmlcom/python/events","assignees_url":"https://api.github.com/repos/bigmlcom/python/assignees{/user}","branches_url":"https://api.github.com/repos/bigmlcom/python/branches{/branch}","tags_url":"https://api.github.com/repos/bigmlcom/python/tags","blobs_url":"https://api.github.com/repos/bigmlcom/python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bigmlcom/python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bigmlcom/python/git/refs{/sha}","trees_url":"https://api.github.com/repos/bigmlcom/python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bigmlcom/python/statuses/{sha}","languages_url":"https://api.github.com/repos/bigmlcom/python/languages","stargazers_url":"https://api.github.com/repos/bigmlcom/python/stargazers","contributors_url":"https://api.github.com/repos/bigmlcom/python/contributors","subscribers_url":"https://api.github.com/repos/bigmlcom/python/subscribers","subscription_url":"https://api.github.com/repos/bigmlcom/python/subscription","commits_url":"https://api.github.com/repos/bigmlcom/python/commits{/sha}","git_commits_url":"https://api.github.com/repos/bigmlcom/python/git/commits{/sha}","comments_url":"https://api.github.com/repos/bigmlcom/python/comments{/number}","issue_comment_url":"https://api.github.com/repos/bigmlcom/python/issues/comments{/number}","contents_url":"https://api.github.com/repos/bigmlcom/python/contents/{+path}","compare_url":"https://api.github.com/repos/bigmlcom/python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bigmlcom/python/merges","archive_url":"https://api.github.com/repos/bigmlcom/python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bigmlcom/python/downloads","issues_url":"https://api.github.com/repos/bigmlcom/python/issues{/number}","pulls_url":"https://api.github.com/repos/bigmlcom/python/pulls{/number}","milestones_url":"https://api.github.com/repos/bigmlcom/python/milestones{/number}","notifications_url":"https://api.github.com/repos/bigmlcom/python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bigmlcom/python/labels{/name}","releases_url":"https://api.github.com/repos/bigmlcom/python/releases{/id}","created_at":"2012-05-01T20:42:24Z","updated_at":"2015-08-22T12:24:24Z","pushed_at":"2015-09-07T23:19:29Z","git_url":"git://github.com/bigmlcom/python.git","ssh_url":"git@github.com:bigmlcom/python.git","clone_url":"https://github.com/bigmlcom/python.git","svn_url":"https://github.com/bigmlcom/python","homepage":null,"size":3006,"stargazers_count":193,"watchers_count":193,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":72,"mirror_url":null,"open_issues_count":2,"forks":72,"open_issues":2,"watchers":193,"default_branch":"next"}},"_links":{"self":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/150"},"html":{"href":"https://github.com/bigmlcom/python/pull/150"},"issue":{"href":"https://api.github.com/repos/bigmlcom/python/issues/150"},"comments":{"href":"https://api.github.com/repos/bigmlcom/python/issues/150/comments"},"review_comments":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/150/comments"},"review_comment":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bigmlcom/python/pulls/150/commits"},"statuses":{"href":"https://api.github.com/repos/bigmlcom/python/statuses/8afa39ef3d9d16ebd48fabe3cb55c781a46c0641"}}}}