{"action":"created","comment":{"url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/comments/46085156","id":46085156,"diff_hunk":"@@ -1 +1,50 @@\n-rpc.py\n\\ No newline at end of file\n+import socket\n+\n+EOM = '---EOM'\n+\n+\n+def start_ir(host, port, ir, max_connections=1):\n+    # Setup socket\n+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n+    s.bind((host, port))\n+    s.listen(max_connections)\n+    conn, addr = s.accept()\n+\n+    # Keep on listening\n+    while True:\n+        # accept new message\n+        newsock, address = s.accept()\n+\n+        # receive questions from new connection\n+        message = recv_end(newsock)\n+        type, question = message.split(\" \", 1)\n+        answers = ir.question(type, question)\n+\n+        # format question\n+        formatted_answers = \"\\n---\\n\".join(\n+            [\"\\n\".join([str(a[0]), a[1], a[2]])\n+                for a in answers]) + \"\\n---EOM\"\n+        conn.send(formatted_answers)\n+\n+\n+# this makes sure that we receive a question in the following form:\n+#    any message here as long as it ends with---EOM\n+def recv_end(the_socket):\n+    total_data = []\n+    data = ''\n+    while True:\n+        data = the_socket.recv(8192)\n+        if EOM in data:\n+            total_data.append(data[:data.find(EOM)])\n+            break\n+        total_data.append(data)\n+        if len(total_data) > 1:\n+\n+            # check if end_of_data was split\n+            last_pair = total_data[-2] + total_data[-1]\n+            if EOM in last_pair:\n+                total_data[-2] = last_pair[:last_pair.find(EOM)]","path":"code/ir/rpc.py","position":70,"original_position":48,"commit_id":"721c532c8f1bd281918f5912d8d55d78493db713","original_commit_id":"07e351435304c9827e47ac22d8663b221e2203c6","user":{"login":"nicola","id":1424850,"avatar_url":"https://avatars.githubusercontent.com/u/1424850?v=3","gravatar_id":"","url":"https://api.github.com/users/nicola","html_url":"https://github.com/nicola","followers_url":"https://api.github.com/users/nicola/followers","following_url":"https://api.github.com/users/nicola/following{/other_user}","gists_url":"https://api.github.com/users/nicola/gists{/gist_id}","starred_url":"https://api.github.com/users/nicola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicola/subscriptions","organizations_url":"https://api.github.com/users/nicola/orgs","repos_url":"https://api.github.com/users/nicola/repos","events_url":"https://api.github.com/users/nicola/events{/privacy}","received_events_url":"https://api.github.com/users/nicola/received_events","type":"User","site_admin":false},"body":"r+","created_at":"2015-11-28T22:14:56Z","updated_at":"2015-11-28T22:14:56Z","html_url":"https://github.com/flare-ai/learning_from_questions/pull/8#discussion_r46085156","pull_request_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/comments/46085156"},"html":{"href":"https://github.com/flare-ai/learning_from_questions/pull/8#discussion_r46085156"},"pull_request":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8","id":52048732,"html_url":"https://github.com/flare-ai/learning_from_questions/pull/8","diff_url":"https://github.com/flare-ai/learning_from_questions/pull/8.diff","patch_url":"https://github.com/flare-ai/learning_from_questions/pull/8.patch","issue_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/8","number":8,"state":"open","locked":false,"title":"RPC","user":{"login":"nicola","id":1424850,"avatar_url":"https://avatars.githubusercontent.com/u/1424850?v=3","gravatar_id":"","url":"https://api.github.com/users/nicola","html_url":"https://github.com/nicola","followers_url":"https://api.github.com/users/nicola/followers","following_url":"https://api.github.com/users/nicola/following{/other_user}","gists_url":"https://api.github.com/users/nicola/gists{/gist_id}","starred_url":"https://api.github.com/users/nicola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicola/subscriptions","organizations_url":"https://api.github.com/users/nicola/orgs","repos_url":"https://api.github.com/users/nicola/repos","events_url":"https://api.github.com/users/nicola/events{/privacy}","received_events_url":"https://api.github.com/users/nicola/received_events","type":"User","site_admin":false},"body":"- [x] Python Server listening and generating a response\r\n- [ ] C++ asking a question via RPC (send)\r\n- [ ] C++ understanding the response (receive)\r\n- [ ] Add script to run IR system\r\n\r\n## How to ask question?\r\n\r\nTo simplify the way we ask questions, I put `---EOM` to be the marker for end of message\r\n```\r\n$question + '---EOM'\r\n```\r\n\r\n## What is the answer?\r\n\r\n```\r\n12\r\nThis is an example of a sentence all in one line .\r\nPathDep::nsubj::0::0::Forw::::|1|84|270|12\r\nPathDep::nsubj::0::0::Forw::::|1|84|271|12\r\nPathDep::nsubj::0::0::Forw::::|1|84|272|12\r\nPathDep::nsubj::0::0::Forw::::|1|84|273|12\r\nPathDep::nsubj::0::0::Forw::::|1|84|274|12\r\nPathDep::nsubj::0::0::Forw::::|1|84|275|12\r\nPathDep::nsubj::0::0::Forw::::|1|85|270|12\r\nPathDep::nsubj::0::0::Forw::::|1|85|271|12\r\nPathDep::nsubj::0::0::Forw::::|1|85|272|12\r\n---\r\n13\r\nThis is an example of a sentence all in one line .\r\nPathDep::nsubj::0::0::Forw::::|1|84|270|13\r\n---\r\n14\r\nThis is an example of a sentence all in one line .\r\n\r\n---EOM\r\n```\r\n\r\nNote that C++ should handle the case for which no feature has been extracted","created_at":"2015-11-28T21:27:23Z","updated_at":"2015-11-28T22:14:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de427d0632ae6765f7f84aa79489bfdcad58b6ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8/commits","review_comments_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8/comments","review_comment_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/8/comments","statuses_url":"https://api.github.com/repos/flare-ai/learning_from_questions/statuses/721c532c8f1bd281918f5912d8d55d78493db713","head":{"label":"flare-ai:rpc","ref":"rpc","sha":"721c532c8f1bd281918f5912d8d55d78493db713","user":{"login":"flare-ai","id":15962024,"avatar_url":"https://avatars.githubusercontent.com/u/15962024?v=3","gravatar_id":"","url":"https://api.github.com/users/flare-ai","html_url":"https://github.com/flare-ai","followers_url":"https://api.github.com/users/flare-ai/followers","following_url":"https://api.github.com/users/flare-ai/following{/other_user}","gists_url":"https://api.github.com/users/flare-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/flare-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flare-ai/subscriptions","organizations_url":"https://api.github.com/users/flare-ai/orgs","repos_url":"https://api.github.com/users/flare-ai/repos","events_url":"https://api.github.com/users/flare-ai/events{/privacy}","received_events_url":"https://api.github.com/users/flare-ai/received_events","type":"Organization","site_admin":false},"repo":{"id":44832039,"name":"learning_from_questions","full_name":"flare-ai/learning_from_questions","owner":{"login":"flare-ai","id":15962024,"avatar_url":"https://avatars.githubusercontent.com/u/15962024?v=3","gravatar_id":"","url":"https://api.github.com/users/flare-ai","html_url":"https://github.com/flare-ai","followers_url":"https://api.github.com/users/flare-ai/followers","following_url":"https://api.github.com/users/flare-ai/following{/other_user}","gists_url":"https://api.github.com/users/flare-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/flare-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flare-ai/subscriptions","organizations_url":"https://api.github.com/users/flare-ai/orgs","repos_url":"https://api.github.com/users/flare-ai/repos","events_url":"https://api.github.com/users/flare-ai/events{/privacy}","received_events_url":"https://api.github.com/users/flare-ai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flare-ai/learning_from_questions","description":"This extending the work by Branavan at MIT described in:","fork":false,"url":"https://api.github.com/repos/flare-ai/learning_from_questions","forks_url":"https://api.github.com/repos/flare-ai/learning_from_questions/forks","keys_url":"https://api.github.com/repos/flare-ai/learning_from_questions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flare-ai/learning_from_questions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flare-ai/learning_from_questions/teams","hooks_url":"https://api.github.com/repos/flare-ai/learning_from_questions/hooks","issue_events_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/events{/number}","events_url":"https://api.github.com/repos/flare-ai/learning_from_questions/events","assignees_url":"https://api.github.com/repos/flare-ai/learning_from_questions/assignees{/user}","branches_url":"https://api.github.com/repos/flare-ai/learning_from_questions/branches{/branch}","tags_url":"https://api.github.com/repos/flare-ai/learning_from_questions/tags","blobs_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/refs{/sha}","trees_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flare-ai/learning_from_questions/statuses/{sha}","languages_url":"https://api.github.com/repos/flare-ai/learning_from_questions/languages","stargazers_url":"https://api.github.com/repos/flare-ai/learning_from_questions/stargazers","contributors_url":"https://api.github.com/repos/flare-ai/learning_from_questions/contributors","subscribers_url":"https://api.github.com/repos/flare-ai/learning_from_questions/subscribers","subscription_url":"https://api.github.com/repos/flare-ai/learning_from_questions/subscription","commits_url":"https://api.github.com/repos/flare-ai/learning_from_questions/commits{/sha}","git_commits_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/commits{/sha}","comments_url":"https://api.github.com/repos/flare-ai/learning_from_questions/comments{/number}","issue_comment_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/comments{/number}","contents_url":"https://api.github.com/repos/flare-ai/learning_from_questions/contents/{+path}","compare_url":"https://api.github.com/repos/flare-ai/learning_from_questions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flare-ai/learning_from_questions/merges","archive_url":"https://api.github.com/repos/flare-ai/learning_from_questions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flare-ai/learning_from_questions/downloads","issues_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues{/number}","pulls_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls{/number}","milestones_url":"https://api.github.com/repos/flare-ai/learning_from_questions/milestones{/number}","notifications_url":"https://api.github.com/repos/flare-ai/learning_from_questions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flare-ai/learning_from_questions/labels{/name}","releases_url":"https://api.github.com/repos/flare-ai/learning_from_questions/releases{/id}","created_at":"2015-10-23T18:49:05Z","updated_at":"2015-11-25T19:18:43Z","pushed_at":"2015-11-28T22:12:31Z","git_url":"git://github.com/flare-ai/learning_from_questions.git","ssh_url":"git@github.com:flare-ai/learning_from_questions.git","clone_url":"https://github.com/flare-ai/learning_from_questions.git","svn_url":"https://github.com/flare-ai/learning_from_questions","homepage":null,"size":20701,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"flare-ai:master","ref":"master","sha":"256682c2432abd892221b1a3516e18c196a46bf1","user":{"login":"flare-ai","id":15962024,"avatar_url":"https://avatars.githubusercontent.com/u/15962024?v=3","gravatar_id":"","url":"https://api.github.com/users/flare-ai","html_url":"https://github.com/flare-ai","followers_url":"https://api.github.com/users/flare-ai/followers","following_url":"https://api.github.com/users/flare-ai/following{/other_user}","gists_url":"https://api.github.com/users/flare-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/flare-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flare-ai/subscriptions","organizations_url":"https://api.github.com/users/flare-ai/orgs","repos_url":"https://api.github.com/users/flare-ai/repos","events_url":"https://api.github.com/users/flare-ai/events{/privacy}","received_events_url":"https://api.github.com/users/flare-ai/received_events","type":"Organization","site_admin":false},"repo":{"id":44832039,"name":"learning_from_questions","full_name":"flare-ai/learning_from_questions","owner":{"login":"flare-ai","id":15962024,"avatar_url":"https://avatars.githubusercontent.com/u/15962024?v=3","gravatar_id":"","url":"https://api.github.com/users/flare-ai","html_url":"https://github.com/flare-ai","followers_url":"https://api.github.com/users/flare-ai/followers","following_url":"https://api.github.com/users/flare-ai/following{/other_user}","gists_url":"https://api.github.com/users/flare-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/flare-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flare-ai/subscriptions","organizations_url":"https://api.github.com/users/flare-ai/orgs","repos_url":"https://api.github.com/users/flare-ai/repos","events_url":"https://api.github.com/users/flare-ai/events{/privacy}","received_events_url":"https://api.github.com/users/flare-ai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flare-ai/learning_from_questions","description":"This extending the work by Branavan at MIT described in:","fork":false,"url":"https://api.github.com/repos/flare-ai/learning_from_questions","forks_url":"https://api.github.com/repos/flare-ai/learning_from_questions/forks","keys_url":"https://api.github.com/repos/flare-ai/learning_from_questions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flare-ai/learning_from_questions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flare-ai/learning_from_questions/teams","hooks_url":"https://api.github.com/repos/flare-ai/learning_from_questions/hooks","issue_events_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/events{/number}","events_url":"https://api.github.com/repos/flare-ai/learning_from_questions/events","assignees_url":"https://api.github.com/repos/flare-ai/learning_from_questions/assignees{/user}","branches_url":"https://api.github.com/repos/flare-ai/learning_from_questions/branches{/branch}","tags_url":"https://api.github.com/repos/flare-ai/learning_from_questions/tags","blobs_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/refs{/sha}","trees_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flare-ai/learning_from_questions/statuses/{sha}","languages_url":"https://api.github.com/repos/flare-ai/learning_from_questions/languages","stargazers_url":"https://api.github.com/repos/flare-ai/learning_from_questions/stargazers","contributors_url":"https://api.github.com/repos/flare-ai/learning_from_questions/contributors","subscribers_url":"https://api.github.com/repos/flare-ai/learning_from_questions/subscribers","subscription_url":"https://api.github.com/repos/flare-ai/learning_from_questions/subscription","commits_url":"https://api.github.com/repos/flare-ai/learning_from_questions/commits{/sha}","git_commits_url":"https://api.github.com/repos/flare-ai/learning_from_questions/git/commits{/sha}","comments_url":"https://api.github.com/repos/flare-ai/learning_from_questions/comments{/number}","issue_comment_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/comments{/number}","contents_url":"https://api.github.com/repos/flare-ai/learning_from_questions/contents/{+path}","compare_url":"https://api.github.com/repos/flare-ai/learning_from_questions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flare-ai/learning_from_questions/merges","archive_url":"https://api.github.com/repos/flare-ai/learning_from_questions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flare-ai/learning_from_questions/downloads","issues_url":"https://api.github.com/repos/flare-ai/learning_from_questions/issues{/number}","pulls_url":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls{/number}","milestones_url":"https://api.github.com/repos/flare-ai/learning_from_questions/milestones{/number}","notifications_url":"https://api.github.com/repos/flare-ai/learning_from_questions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flare-ai/learning_from_questions/labels{/name}","releases_url":"https://api.github.com/repos/flare-ai/learning_from_questions/releases{/id}","created_at":"2015-10-23T18:49:05Z","updated_at":"2015-11-25T19:18:43Z","pushed_at":"2015-11-28T22:12:31Z","git_url":"git://github.com/flare-ai/learning_from_questions.git","ssh_url":"git@github.com:flare-ai/learning_from_questions.git","clone_url":"https://github.com/flare-ai/learning_from_questions.git","svn_url":"https://github.com/flare-ai/learning_from_questions","homepage":null,"size":20701,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8"},"html":{"href":"https://github.com/flare-ai/learning_from_questions/pull/8"},"issue":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/8"},"comments":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/flare-ai/learning_from_questions/statuses/721c532c8f1bd281918f5912d8d55d78493db713"}}}}