{"action":"created","comment":{"url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/comments/83516765","pull_request_review_id":4359013,"id":83516765,"diff_hunk":"@@ -0,0 +1,213 @@\n+\"use strict\";\n+\n+class Index{\n+  constructor() {\n+    // an empty object that keeps track of files uploaded\n+    // and their index\n+    this.filesIndexed = {};\n+  }\n+  \n+\n+  /**\n+    createIndex function is used to get all the index\n+    @param {object} jsonData- the json data to index\n+    @parame {string} filename- the name of the file to be indexed\n+    @return {boolean} true or false if the createIndex was successful\n+  */\n+  createIndex(jsonData, filename) {\n+    //checks if the jsondata is accurate and not empty\n+    try {\n+      jsonData = JSON.parse(jsonData);\n+    } catch(e) {\n+      return false;\n+    }\n+\n+    //adds the filename as a key to the filesIndex and\n+    //initializes it to an empty object\n+    this.filesIndexed[filename] = {};\n+    if(!this.prepareJsonData(jsonData, filename)) {\n+      //if the file was not indexed, the key is removed\n+      delete this.filesIndexed[filename];\n+      return false;\n+    }\n+    return true;\n+\n+  }\n+\n+  /**\n+  prepareJsonData gets the json ready for indexing by tokenizing the\n+  statements\n+  @param {object} jsonData - the jsonData that has been read from the file\n+  @param {string} filename - the name of the file uploaded \n+  */\n+  prepareJsonData(jsonData, filename) {\n+\n+    let textArray = [], documentNum = 0;\n+    //loop through each doc in the json\n+    let aDocument = [];\n+    for(let eachIndex in jsonData) {\n+      aDocument = jsonData[eachIndex];\n+      //check if each doc has the text and title property\n+      if(aDocument.hasOwnProperty(\"text\") &&\n+        aDocument.hasOwnProperty(\"title\")) {\n+          //convert the string of both title and text into array\n+          //and keep track of the document number\n+          let textTokens = this.tokenize(aDocument.text + \" \" + aDocument.title);\n+          //the documentNum is the index of the doc that has been tokenied\n+          textArray.push({documentNum, textTokens});\n+      } else {\n+        return false;\n+      }\n+      documentNum++;\n+    }\n+    //saves the number of documents\n+    this.filesIndexed[filename].numOfDocs = documentNum;\n+    //adds the attribute wordIndex to the class instance if the constructIndex\n+    //was successful\n+    this.filesIndexed[filename].index = this.constructIndex(textArray);\n+\n+    return true;\n+  }\n+\n+  /**\n+    tokenize: method converts the text to lowercase and then returns the\n+    array of words\n+    @param {string} text- the text to be tokenized\n+    @return {array} array of words in the documents\n+  */\n+  tokenize(text) {\n+    text = text.replace(/[.,\\/#!$%\\^&\\*;:'{}=\\-_`~()]/g, \"\");\n+    return text.toLowerCase().split(\" \");\n+  }\n+\n+  /**\n+    constructIndex method searches through the array of documents objects\n+    and identifies the words in each\n+    @param {array} documents - array of objects with each obect representing\n+    a document\n+    @return {object} objects of tokens. Each token is a key in the object and\n+    contains an array of documents in which it was found\n+  */\n+  constructIndex(documents) {\n+    let indexDict = {};\n+    //loop through the documents\n+    for(let each in documents) {\n+      let tokenArray = documents[each].textTokens;\n+      for(let i = 0; i < tokenArray.length; i++){\n+        let token = tokenArray[i];\n+        //check if the word has not been indexed and used as key in the object\n+        if(!indexDict.hasOwnProperty(token)) {\n+          //the token is used as a key and initialized to an empty array\n+          indexDict[token] = [];\n+        }\n+        //a check is run to confirm if the document has been indexed\n+        //with the word\n+        if(indexDict[token].indexOf(documents[each].documentNum) === -1) {\n+          indexDict[token].push(documents[each].documentNum);\n+        }\n+      }\n+    }\n+\n+    return indexDict;\n+  }\n+\n+  /**\n+  getIndex method returns the indexed words and the documents they were found\n+  @filename {string} name of the file to get its index\n+  @return {Object} the words index\n+  */\n+  getIndex(filename) {\n+    let returnValue = this.filesIndexed[filename].index === undefined ? false : this.filesIndexed[filename].index;\n+    return returnValue;\n+  }\n+\n+  /**\n+  searchIndex searches the indexed words to determine the documents that the\n+  searchterms can be found\n+  @params searchTerm {string, array} the search query\n+  @params filename {string}- the name of the file to search its index\n+  @return {object|boolean} it returns boolean if the searchTerm is empty and\n+  it retrns object if it is not. Each index is each searcykeyword.\n+  Each with an array value of the document index\n+  */\n+  searchIndex(searchTerm, filename) {\n+    if((typeof searchTerm === \"string\" && searchTerm.trim() === \"\") ||\n+      (typeof searchTerm === \"object\" && searchTerm.length === 0) ||\n+      searchTerm === undefined) {\n+        return false;\n+    }\n+\n+    let result = [];\n+    if(filename === \"all\") {\n+      for(let eachFile in this.filesIndexed) {","path":"src/inverted-index.js","position":142,"original_position":142,"commit_id":"5113c0a7a9dd364d441dd33155ac3c8831104513","original_commit_id":"5113c0a7a9dd364d441dd33155ac3c8831104513","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).","created_at":"2016-10-14T23:23:36Z","updated_at":"2016-10-14T23:23:36Z","html_url":"https://github.com/andela-foladeji/inverted-index/pull/3#discussion_r83516765","pull_request_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/comments/83516765"},"html":{"href":"https://github.com/andela-foladeji/inverted-index/pull/3#discussion_r83516765"},"pull_request":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3","id":89469866,"html_url":"https://github.com/andela-foladeji/inverted-index/pull/3","diff_url":"https://github.com/andela-foladeji/inverted-index/pull/3.diff","patch_url":"https://github.com/andela-foladeji/inverted-index/pull/3.patch","issue_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/3","number":3,"state":"open","locked":false,"title":"Develop","user":{"login":"andela-foladeji","id":17332992,"avatar_url":"https://avatars.githubusercontent.com/u/17332992?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-foladeji","html_url":"https://github.com/andela-foladeji","followers_url":"https://api.github.com/users/andela-foladeji/followers","following_url":"https://api.github.com/users/andela-foladeji/following{/other_user}","gists_url":"https://api.github.com/users/andela-foladeji/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-foladeji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-foladeji/subscriptions","organizations_url":"https://api.github.com/users/andela-foladeji/orgs","repos_url":"https://api.github.com/users/andela-foladeji/repos","events_url":"https://api.github.com/users/andela-foladeji/events{/privacy}","received_events_url":"https://api.github.com/users/andela-foladeji/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-14T23:23:27Z","updated_at":"2016-10-14T23:23:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc830d7674df66c9ab756ce081e2aa007e86d4d4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3/commits","review_comments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3/comments","review_comment_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/3/comments","statuses_url":"https://api.github.com/repos/andela-foladeji/inverted-index/statuses/5113c0a7a9dd364d441dd33155ac3c8831104513","head":{"label":"andela-foladeji:develop","ref":"develop","sha":"5113c0a7a9dd364d441dd33155ac3c8831104513","user":{"login":"andela-foladeji","id":17332992,"avatar_url":"https://avatars.githubusercontent.com/u/17332992?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-foladeji","html_url":"https://github.com/andela-foladeji","followers_url":"https://api.github.com/users/andela-foladeji/followers","following_url":"https://api.github.com/users/andela-foladeji/following{/other_user}","gists_url":"https://api.github.com/users/andela-foladeji/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-foladeji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-foladeji/subscriptions","organizations_url":"https://api.github.com/users/andela-foladeji/orgs","repos_url":"https://api.github.com/users/andela-foladeji/repos","events_url":"https://api.github.com/users/andela-foladeji/events{/privacy}","received_events_url":"https://api.github.com/users/andela-foladeji/received_events","type":"User","site_admin":false},"repo":{"id":70052343,"name":"inverted-index","full_name":"andela-foladeji/inverted-index","owner":{"login":"andela-foladeji","id":17332992,"avatar_url":"https://avatars.githubusercontent.com/u/17332992?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-foladeji","html_url":"https://github.com/andela-foladeji","followers_url":"https://api.github.com/users/andela-foladeji/followers","following_url":"https://api.github.com/users/andela-foladeji/following{/other_user}","gists_url":"https://api.github.com/users/andela-foladeji/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-foladeji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-foladeji/subscriptions","organizations_url":"https://api.github.com/users/andela-foladeji/orgs","repos_url":"https://api.github.com/users/andela-foladeji/repos","events_url":"https://api.github.com/users/andela-foladeji/events{/privacy}","received_events_url":"https://api.github.com/users/andela-foladeji/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-foladeji/inverted-index","description":"Inverted index aids quick searching of text","fork":false,"url":"https://api.github.com/repos/andela-foladeji/inverted-index","forks_url":"https://api.github.com/repos/andela-foladeji/inverted-index/forks","keys_url":"https://api.github.com/repos/andela-foladeji/inverted-index/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-foladeji/inverted-index/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-foladeji/inverted-index/teams","hooks_url":"https://api.github.com/repos/andela-foladeji/inverted-index/hooks","issue_events_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/events{/number}","events_url":"https://api.github.com/repos/andela-foladeji/inverted-index/events","assignees_url":"https://api.github.com/repos/andela-foladeji/inverted-index/assignees{/user}","branches_url":"https://api.github.com/repos/andela-foladeji/inverted-index/branches{/branch}","tags_url":"https://api.github.com/repos/andela-foladeji/inverted-index/tags","blobs_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-foladeji/inverted-index/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-foladeji/inverted-index/languages","stargazers_url":"https://api.github.com/repos/andela-foladeji/inverted-index/stargazers","contributors_url":"https://api.github.com/repos/andela-foladeji/inverted-index/contributors","subscribers_url":"https://api.github.com/repos/andela-foladeji/inverted-index/subscribers","subscription_url":"https://api.github.com/repos/andela-foladeji/inverted-index/subscription","commits_url":"https://api.github.com/repos/andela-foladeji/inverted-index/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-foladeji/inverted-index/contents/{+path}","compare_url":"https://api.github.com/repos/andela-foladeji/inverted-index/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-foladeji/inverted-index/merges","archive_url":"https://api.github.com/repos/andela-foladeji/inverted-index/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-foladeji/inverted-index/downloads","issues_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues{/number}","pulls_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-foladeji/inverted-index/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-foladeji/inverted-index/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-foladeji/inverted-index/labels{/name}","releases_url":"https://api.github.com/repos/andela-foladeji/inverted-index/releases{/id}","deployments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/deployments","created_at":"2016-10-05T11:00:26Z","updated_at":"2016-10-05T11:00:26Z","pushed_at":"2016-10-14T23:23:27Z","git_url":"git://github.com/andela-foladeji/inverted-index.git","ssh_url":"git@github.com:andela-foladeji/inverted-index.git","clone_url":"https://github.com/andela-foladeji/inverted-index.git","svn_url":"https://github.com/andela-foladeji/inverted-index","homepage":null,"size":105,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"andela-foladeji:master","ref":"master","sha":"04739bc3501536d402e3c56b14033cb6b57d88da","user":{"login":"andela-foladeji","id":17332992,"avatar_url":"https://avatars.githubusercontent.com/u/17332992?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-foladeji","html_url":"https://github.com/andela-foladeji","followers_url":"https://api.github.com/users/andela-foladeji/followers","following_url":"https://api.github.com/users/andela-foladeji/following{/other_user}","gists_url":"https://api.github.com/users/andela-foladeji/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-foladeji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-foladeji/subscriptions","organizations_url":"https://api.github.com/users/andela-foladeji/orgs","repos_url":"https://api.github.com/users/andela-foladeji/repos","events_url":"https://api.github.com/users/andela-foladeji/events{/privacy}","received_events_url":"https://api.github.com/users/andela-foladeji/received_events","type":"User","site_admin":false},"repo":{"id":70052343,"name":"inverted-index","full_name":"andela-foladeji/inverted-index","owner":{"login":"andela-foladeji","id":17332992,"avatar_url":"https://avatars.githubusercontent.com/u/17332992?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-foladeji","html_url":"https://github.com/andela-foladeji","followers_url":"https://api.github.com/users/andela-foladeji/followers","following_url":"https://api.github.com/users/andela-foladeji/following{/other_user}","gists_url":"https://api.github.com/users/andela-foladeji/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-foladeji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-foladeji/subscriptions","organizations_url":"https://api.github.com/users/andela-foladeji/orgs","repos_url":"https://api.github.com/users/andela-foladeji/repos","events_url":"https://api.github.com/users/andela-foladeji/events{/privacy}","received_events_url":"https://api.github.com/users/andela-foladeji/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-foladeji/inverted-index","description":"Inverted index aids quick searching of text","fork":false,"url":"https://api.github.com/repos/andela-foladeji/inverted-index","forks_url":"https://api.github.com/repos/andela-foladeji/inverted-index/forks","keys_url":"https://api.github.com/repos/andela-foladeji/inverted-index/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-foladeji/inverted-index/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-foladeji/inverted-index/teams","hooks_url":"https://api.github.com/repos/andela-foladeji/inverted-index/hooks","issue_events_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/events{/number}","events_url":"https://api.github.com/repos/andela-foladeji/inverted-index/events","assignees_url":"https://api.github.com/repos/andela-foladeji/inverted-index/assignees{/user}","branches_url":"https://api.github.com/repos/andela-foladeji/inverted-index/branches{/branch}","tags_url":"https://api.github.com/repos/andela-foladeji/inverted-index/tags","blobs_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-foladeji/inverted-index/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-foladeji/inverted-index/languages","stargazers_url":"https://api.github.com/repos/andela-foladeji/inverted-index/stargazers","contributors_url":"https://api.github.com/repos/andela-foladeji/inverted-index/contributors","subscribers_url":"https://api.github.com/repos/andela-foladeji/inverted-index/subscribers","subscription_url":"https://api.github.com/repos/andela-foladeji/inverted-index/subscription","commits_url":"https://api.github.com/repos/andela-foladeji/inverted-index/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-foladeji/inverted-index/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-foladeji/inverted-index/contents/{+path}","compare_url":"https://api.github.com/repos/andela-foladeji/inverted-index/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-foladeji/inverted-index/merges","archive_url":"https://api.github.com/repos/andela-foladeji/inverted-index/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-foladeji/inverted-index/downloads","issues_url":"https://api.github.com/repos/andela-foladeji/inverted-index/issues{/number}","pulls_url":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-foladeji/inverted-index/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-foladeji/inverted-index/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-foladeji/inverted-index/labels{/name}","releases_url":"https://api.github.com/repos/andela-foladeji/inverted-index/releases{/id}","deployments_url":"https://api.github.com/repos/andela-foladeji/inverted-index/deployments","created_at":"2016-10-05T11:00:26Z","updated_at":"2016-10-05T11:00:26Z","pushed_at":"2016-10-14T23:23:27Z","git_url":"git://github.com/andela-foladeji/inverted-index.git","ssh_url":"git@github.com:andela-foladeji/inverted-index.git","clone_url":"https://github.com/andela-foladeji/inverted-index.git","svn_url":"https://github.com/andela-foladeji/inverted-index","homepage":null,"size":105,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3"},"html":{"href":"https://github.com/andela-foladeji/inverted-index/pull/3"},"issue":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/3"},"comments":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/andela-foladeji/inverted-index/statuses/5113c0a7a9dd364d441dd33155ac3c8831104513"}}}}
{"actor":{"display_login":"houndci-bot"}}