{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/comments/35326213","id":35326213,"diff_hunk":"@@ -0,0 +1,195 @@\n+#!/usr/bin/env python\n+# ----------------------------------------------------------------------\n+# Numenta Platform for Intelligent Computing (NuPIC)\n+# Copyright (C) 2015, Numenta, Inc.  Unless you have purchased from\n+# Numenta, Inc. a separate commercial license for this software code, the\n+# following terms and conditions apply:\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License version 3 as\n+# published by the Free Software Foundation.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n+# See the GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see http://www.gnu.org/licenses.\n+#\n+# http://numenta.org/licenses/\n+# ----------------------------------------------------------------------\n+\"\"\"\n+This file contains a class that tokenizes, randomizes, and writes the data to a\n+file in the format of the network API\n+\"\"\"\n+\n+import argparse\n+import csv\n+import json\n+import pandas\n+import pprint\n+import random\n+\n+from collections import defaultdict\n+from fluent.utils.text_preprocess import TextPreprocess\n+\n+\n+class NetworkDataGenerator(object):\n+  \"\"\"Class for generating data for the network\"\"\"\n+\n+\n+  def  __init__(self):\n+    self.preprocessedData = []\n+    self.fieldNames = [\"token\", \"_sequenceID\", \"_reset\"]\n+    self.types = {\"token\": \"str\",\n+                  \"_sequenceID\": \"int\",\n+                  \"_reset\": \"bool\"}\n+    self.specials = {\"token\": \"\",\n+                     \"_sequenceID\": \"S\",\n+                     \"_reset\": \"R\"}\n+\n+    # len(self.categoryToId) gives each category a unique id without having\n+    # duplicates\n+    self.categoryToId = defaultdict(lambda: len(self.categoryToId))\n+\n+\n+  def preprocess(self, filename, sampleIdx, categoryIndices, abbrCSV=\"\",\n+      contrCSV=\"\", ignoreCommon=None, removeStrings=None, correctSpell=False,\n+      **kwargs):\n+    \"\"\"\n+    Process all the comments in a file.\n+    @param filename        (str)    Path to csv file\n+    @param sampleIdx       (int)    Column number of the text sample\n+    @param categoryIndices (list)   List of numbers indicating the categories\n+    Please see TextPreprocess tokenize() for the other parameters\n+    \"\"\"\n+    # Update header details\n+    for i in xrange(len(categoryIndices)):\n+      categoryKey = \"_category{}\".format(i)\n+      self.fieldNames.append(categoryKey)\n+      self.types[categoryKey] = \"int\"\n+      self.specials[categoryKey] = \"C\"\n+    \n+    dataTable = pandas.read_csv(filename).fillna('')\n+    numInstances, _ = dataTable.shape\n+    keys = dataTable.keys()\n+    categoryHeaders = [keys[i] for i in categoryIndices]\n+\n+    textPreprocess = TextPreprocess(abbrCSV=abbrCSV, contrCSV=contrCSV)\n+    expandAbbr = (abbrCSV != \"\")\n+    expandContr = (contrCSV != \"\")\n+\n+    for i in xrange(numInstances):\n+      # Get the category and convert it to an id\n+      categories = [self.categoryToId[dataTable[ch][i]]\n+                    for ch in categoryHeaders]\n+      comment = dataTable[keys[sampleIdx]][i]\n+\n+      tokens = textPreprocess.tokenize(comment, ignoreCommon, removeStrings,\n+        correctSpell, expandAbbr, expandContr)\n+\n+      record = {\"_category{}\".format(i): c for i,c in enumerate(categories)}\n+      record[\"_sequenceID\"] = i\n+\n+      data = []\n+      reset = 1\n+      for t in tokens:\n+        tokenRecord = record.copy()\n+        tokenRecord[\"token\"] = t\n+        tokenRecord[\"_reset\"] = reset\n+        reset = 0\n+        data.append(tokenRecord)\n+\n+      self.preprocessedData.append(data)\n+\n+\n+  def randomizeData(self):\n+    self.preprocesseData = random.shuffle(self.preprocessedData)","path":"fluent/utils/network_data_generator.py","position":108,"original_position":108,"commit_id":"8080f2233b17f8eb3f552ab50c3a9705d6466830","original_commit_id":"8080f2233b17f8eb3f552ab50c3a9705d6466830","user":{"login":"BoltzmannBrain","id":8323700,"avatar_url":"https://avatars.githubusercontent.com/u/8323700?v=3","gravatar_id":"","url":"https://api.github.com/users/BoltzmannBrain","html_url":"https://github.com/BoltzmannBrain","followers_url":"https://api.github.com/users/BoltzmannBrain/followers","following_url":"https://api.github.com/users/BoltzmannBrain/following{/other_user}","gists_url":"https://api.github.com/users/BoltzmannBrain/gists{/gist_id}","starred_url":"https://api.github.com/users/BoltzmannBrain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BoltzmannBrain/subscriptions","organizations_url":"https://api.github.com/users/BoltzmannBrain/orgs","repos_url":"https://api.github.com/users/BoltzmannBrain/repos","events_url":"https://api.github.com/users/BoltzmannBrain/events{/privacy}","received_events_url":"https://api.github.com/users/BoltzmannBrain/received_events","type":"User","site_admin":false},"body":"`random.shuffle` operates in place, not to mention the variable being assigned (a None value) is spelled wrong","created_at":"2015-07-23T14:24:27Z","updated_at":"2015-07-23T14:24:27Z","html_url":"https://github.com/numenta/nupic.fluent/pull/121#discussion_r35326213","pull_request_url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121","_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/comments/35326213"},"html":{"href":"https://github.com/numenta/nupic.fluent/pull/121#discussion_r35326213"},"pull_request":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121","id":40614972,"html_url":"https://github.com/numenta/nupic.fluent/pull/121","diff_url":"https://github.com/numenta/nupic.fluent/pull/121.diff","patch_url":"https://github.com/numenta/nupic.fluent/pull/121.patch","issue_url":"https://api.github.com/repos/numenta/nupic.fluent/issues/121","number":121,"state":"open","locked":false,"title":"RES-21: Process data for network API","user":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"body":"NetworkDataGenerator creates a two files, the first one contains the data in the format that the network API FileRecordStream needs and the other is a mapping of category labels to ids.  It has the option to randomize and/or tokenize as well.\r\n\r\n@BoltzmannBrain ","created_at":"2015-07-22T21:40:17Z","updated_at":"2015-07-23T14:24:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c75d72f6b40c44c2a2d3591e3a8eda3bf1be630b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121/commits","review_comments_url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121/comments","review_comment_url":"https://api.github.com/repos/numenta/nupic.fluent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numenta/nupic.fluent/issues/121/comments","statuses_url":"https://api.github.com/repos/numenta/nupic.fluent/statuses/8080f2233b17f8eb3f552ab50c3a9705d6466830","head":{"label":"akhilaananthram:network_data","ref":"network_data","sha":"8080f2233b17f8eb3f552ab50c3a9705d6466830","user":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"repo":{"id":37288881,"name":"nupic.fluent","full_name":"akhilaananthram/nupic.fluent","owner":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akhilaananthram/nupic.fluent","description":"A platform for building language / NLP-based applications using NuPIC and Cortical.io.","fork":true,"url":"https://api.github.com/repos/akhilaananthram/nupic.fluent","forks_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/forks","keys_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/teams","hooks_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/hooks","issue_events_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/issues/events{/number}","events_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/events","assignees_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/assignees{/user}","branches_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/branches{/branch}","tags_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/tags","blobs_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/git/refs{/sha}","trees_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/statuses/{sha}","languages_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/languages","stargazers_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/stargazers","contributors_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/contributors","subscribers_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/subscribers","subscription_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/subscription","commits_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/commits{/sha}","git_commits_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/git/commits{/sha}","comments_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/comments{/number}","issue_comment_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/issues/comments{/number}","contents_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/contents/{+path}","compare_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/merges","archive_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/downloads","issues_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/issues{/number}","pulls_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/pulls{/number}","milestones_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/milestones{/number}","notifications_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/labels{/name}","releases_url":"https://api.github.com/repos/akhilaananthram/nupic.fluent/releases{/id}","created_at":"2015-06-11T22:11:28Z","updated_at":"2015-06-11T22:11:28Z","pushed_at":"2015-07-22T21:36:58Z","git_url":"git://github.com/akhilaananthram/nupic.fluent.git","ssh_url":"git@github.com:akhilaananthram/nupic.fluent.git","clone_url":"https://github.com/akhilaananthram/nupic.fluent.git","svn_url":"https://github.com/akhilaananthram/nupic.fluent","homepage":"","size":3553,"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":"numenta:master","ref":"master","sha":"044500571e4c7f82a2f12dfbdadf33584e7c3a83","user":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"repo":{"id":17183816,"name":"nupic.fluent","full_name":"numenta/nupic.fluent","owner":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numenta/nupic.fluent","description":"A platform for building language / NLP-based applications using NuPIC and Cortical.io.","fork":false,"url":"https://api.github.com/repos/numenta/nupic.fluent","forks_url":"https://api.github.com/repos/numenta/nupic.fluent/forks","keys_url":"https://api.github.com/repos/numenta/nupic.fluent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numenta/nupic.fluent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numenta/nupic.fluent/teams","hooks_url":"https://api.github.com/repos/numenta/nupic.fluent/hooks","issue_events_url":"https://api.github.com/repos/numenta/nupic.fluent/issues/events{/number}","events_url":"https://api.github.com/repos/numenta/nupic.fluent/events","assignees_url":"https://api.github.com/repos/numenta/nupic.fluent/assignees{/user}","branches_url":"https://api.github.com/repos/numenta/nupic.fluent/branches{/branch}","tags_url":"https://api.github.com/repos/numenta/nupic.fluent/tags","blobs_url":"https://api.github.com/repos/numenta/nupic.fluent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numenta/nupic.fluent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numenta/nupic.fluent/git/refs{/sha}","trees_url":"https://api.github.com/repos/numenta/nupic.fluent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numenta/nupic.fluent/statuses/{sha}","languages_url":"https://api.github.com/repos/numenta/nupic.fluent/languages","stargazers_url":"https://api.github.com/repos/numenta/nupic.fluent/stargazers","contributors_url":"https://api.github.com/repos/numenta/nupic.fluent/contributors","subscribers_url":"https://api.github.com/repos/numenta/nupic.fluent/subscribers","subscription_url":"https://api.github.com/repos/numenta/nupic.fluent/subscription","commits_url":"https://api.github.com/repos/numenta/nupic.fluent/commits{/sha}","git_commits_url":"https://api.github.com/repos/numenta/nupic.fluent/git/commits{/sha}","comments_url":"https://api.github.com/repos/numenta/nupic.fluent/comments{/number}","issue_comment_url":"https://api.github.com/repos/numenta/nupic.fluent/issues/comments{/number}","contents_url":"https://api.github.com/repos/numenta/nupic.fluent/contents/{+path}","compare_url":"https://api.github.com/repos/numenta/nupic.fluent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numenta/nupic.fluent/merges","archive_url":"https://api.github.com/repos/numenta/nupic.fluent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numenta/nupic.fluent/downloads","issues_url":"https://api.github.com/repos/numenta/nupic.fluent/issues{/number}","pulls_url":"https://api.github.com/repos/numenta/nupic.fluent/pulls{/number}","milestones_url":"https://api.github.com/repos/numenta/nupic.fluent/milestones{/number}","notifications_url":"https://api.github.com/repos/numenta/nupic.fluent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numenta/nupic.fluent/labels{/name}","releases_url":"https://api.github.com/repos/numenta/nupic.fluent/releases{/id}","created_at":"2014-02-25T18:41:17Z","updated_at":"2015-07-05T11:09:46Z","pushed_at":"2015-07-22T22:33:59Z","git_url":"git://github.com/numenta/nupic.fluent.git","ssh_url":"git@github.com:numenta/nupic.fluent.git","clone_url":"https://github.com/numenta/nupic.fluent.git","svn_url":"https://github.com/numenta/nupic.fluent","homepage":"","size":6446,"stargazers_count":21,"watchers_count":21,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":20,"forks":18,"open_issues":20,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121"},"html":{"href":"https://github.com/numenta/nupic.fluent/pull/121"},"issue":{"href":"https://api.github.com/repos/numenta/nupic.fluent/issues/121"},"comments":{"href":"https://api.github.com/repos/numenta/nupic.fluent/issues/121/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121/comments"},"review_comment":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numenta/nupic.fluent/pulls/121/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/nupic.fluent/statuses/8080f2233b17f8eb3f552ab50c3a9705d6466830"}}}}