Giter Site home page Giter Site logo

inverted-index's Introduction

inverted-index

Running the checkpoint.

For security reasons Javascript cannot load local files in chrome. Therefore, we need to make the file containing the checkpoint a webserver. To do this I used local web server a node js package that can be found at https://www.npmjs.com/package/local-web-server. Once installed, run ws at the folder you want to serve.

Module explanation.

createIndex: It uses jQuery's getJSON mehod(used to get JSON data using an AJAX HTTP GET request) to read the book.json file. It then returns the data which should be an array containing objects.

getIndex: It takes the data obtained by createIndex as an argument. THe data returned is in form of an array. It loops through the array to obtain its contents(objects). It then obtains the keys of the object using Object.keys(object) method which ouputs an array. After this, it loops through the array using each key to access the particular object's value which is a string. The strings are split into individual words which are added to an array. Duplicate words are removed and the array sorted. Next, the words are compared to the contents of a stoplist array that contains english words not very important to the context such as a, an, the and at. Words not in the stoplist are put in an array contain the final words to be indexed. Finally, we loop through this array of words comparing them to the contents of the array read from the json file and then add the word as a key in an object and the index of the containing object as its value. Since there weren't occurences of words in both objects, if the key already exists in the object, the word is ignored. If it doesn't a new key is created. getIndex then creates a prototype dataIndex of the class Index and assigns it the object containing the indexed words.

searchIndex: It takes arguements either as an array of words or several strings and searches for them in dataIndex then returns an array containing the values that point to the location of the object(in the json data array) containing the word searched for. If the word isn't present, it returns -1.

inverted-index's People

Contributors

andela-ioraelosi avatar jkithome avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.