All English words in Javascript: WordList-JS

Got a project near completion? Got a project with lots of screens and media? This is the place. This is for nearly finished and Projects with lots of media.
Post Reply
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

All English words in Javascript: WordList-JS

Post by Jackolantern »

Completed library linked in following post

This is an issue I have been wanting to have solved for some time now. I have wanted to make some word games in Javascript, but the problem is how do you check them? There are a couple of web services, and that works for web games (to a certain degree, as it depends on the word list itself since it can be too in-depth or scientific), but as we all know Javascript's importance goes far beyond web applications. There are mobile apps that can be made in JS and much more. So I wanted a way to have all English words in a JS application without having to connect to the Internet.

Then I found the English Open Word List, which is an awesome public domain word list that is specifically made for word games and spell checkers, and contains around 128k words.

Long story short, I downloaded the list, which was in CSV format and wrote a C# program to write them into Javascript arrays, and then wrote a JS interface that checks if a submitted word is in the list, and can also pull random words based on either a certain number of letters or a random number of letters.

Once I am done I will release it under MIT license on Github. Right now I have all functionality working, but there are issues. Namely, it is polluting the global namespace with each letter's array. Later today I am going to compile each word list into one file (each is separate) and change them from array initializations into module method calls to initialize them inside the main module. Also, it is extremely heavy, currently clocking in at around 3mb. Once I get it in a form I like, I am going to minify it all, which will hopefully earn me some kb back. Finally, the letter count-specific word find function is inefficient, but I have very few ideas for that.

I don't have anything to show for this right now, but I put it in PSII because I should have it released to Github later this week at the latest. Word games are hot right now, and quite easy to program and market if you have access to a reliable word list, and the list that this project is based on was designed specifically with Scabble-type games in mind. I hope maybe some others can make use of it as well :)
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: All English words in Javascript

Post by hallsofvallhalla »

Wow thats very awesome. How are you doing the checks as far as checking the word against 128k list? I am sure you are now cycling through all the words until it finds it.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: All English words in Javascript

Post by Jackolantern »

Each letter is in a separate array, and then I am using the built-in Javascript functions to see if the word (after being forced to all lowercase) is contained in the word bank array. Since this is designed for games and not spell-checking, there is no spell-checking of the entry. Of course, someone could pretty easily add in some regular expression-powered methods to add in spell checking. :cool:
The indelible lord of tl;dr
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: All English words in Javascript

Post by Jackolantern »

Got WordList-JS up on GitHub now!

As far as the searching goes, I would assume most JS engines probably implement their native array searching functions as at least binary searches, which would probably be the best I could do myself. However, if anyone finds that they are having performance issues, I could look into building it out into some other method :)
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: All English words in Javascript: WordList-JS

Post by hallsofvallhalla »

makes sense to use the built in searches. Was not sure on the performance of them though so was just curious.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: All English words in Javascript: WordList-JS

Post by Jackolantern »

The only part of the library that is not performance-savvy is choosing a random word based on a certain number of letters. I should have thought ahead while making the word bank to put them in order of letter count so I could have at least made some indexes of where each word list of certain lengths was. If there is interest in it and anyone has problems with the speed of pulling random words based on character length, I will sit down and re-do it. My testing showed it as being basically instant, but I don't know how long it could begin to take if people needed to loop that function and pull 100+ random words :P
The indelible lord of tl;dr
Post Reply

Return to “Project Showoff Tier II”