Skip to content

Small Node application for efficient storage and look up of lowercase words

Notifications You must be signed in to change notification settings

NRaf/urban-slang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Urban Slang

A (very) simple NodeJS app which allows loading and quick lookup of words.

Usage

Running the application

The application can be accessed at http://localhost:3000

The web application is configured to load files from data/scrabble.txt

# clone repo
git clone https://github.com/NRaf/urban-slang.git

# change directory
cd urban-slang

# install dependencies
npm install

# start the server
npm start

# run the tests (optional)
npm test

Using the library

Creating an instance

var UrbanSlang = require('./urban-slang');
var urbanSlang = new UrbanSlang();

Loading words from a file

One word per line, a-z, lowercase

urbanSlang.loadWordsFromFile('filename', callback);

Manually add words

urbanSlang.insertWord('apple');

Retrieve words

Retrieves all words beginning with the searchTerm (with a limit of 201 words)

urbanSlang.retrieveWords('apple');

How it works

The data is stored as a tree structure, with each node being a single letter. This leads to no duplication of data with words that begin with the same sequence, as can be seen in the diagram below.

      w
    /   \
   a     o--\
 /   \       \
 s*   r*-s*   r
 |    |     /   \
 t    d*   t*    d*
 |    |    |     |
 e*   s*   h*    s*

* indicates that the letters from the root to this node spell a valid word

Can only perform searches from the start of a word. This was a conscious decision given the requirements of the application. The structure allows for fast searching of words beginning with a sequence of characters as well as quick insertion.

As an example, passing 'wa' with the above data with return the values 'was', 'waste', 'war', 'wars', 'ward' and 'wards'.

Compatability

Tested on Chrome version 48. Might not work on older browsers due to the usage of the Fetch API for making the AJAX call.

Should use Node version 4+.

License

BSD

About

Small Node application for efficient storage and look up of lowercase words

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published