javascript list of english words for a game

2020-04-02 08:31发布

I'm making a simple JS game that needs a list of English dictionary words. Will I need to build the list myself, or is it possible to access the system's or browser's spell-check dictionary - or maybe there's another solution?

8条回答
疯言疯语
2楼-- · 2020-04-02 09:16

You can use Aspell English dictionary.
Aspell English dictionary is availabe at: ftp://ftp.gnu.org/gnu/aspell/dict/0index.html.

To dump world list from the Aspell dictionary checkout:

The command to dump English list of words should look something like:

aspell -d en dump master | aspell -l en expand > words.txt
查看更多
乱世女痞
3楼-- · 2020-04-02 09:18

As Linked by @aryaman , I too used that GitHub page when I needed an Array for Auto-correct TextBox. https://github.com/dwyl/english-words/blob/master/words.txt[][1]

But If you are looking for a Javascript Array Soultion, Just Create a Python File in the Same directory as The words.txt file and type this into Python File

filepath = 'words.txt'
print("var anyname = [")
with open(filepath) as fp:
   for cnt, line in enumerate(fp):
       print("'{}',".format(line))
print("]")

Just Copy Paste the Output to your Code File and Done !

! Note - It's really big file, I recommend you to use this one from the same respoitory https://github.com/dwyl/english-words/blob/master/words_alpha.txt[][1] . It contains words without any Numbers. Also, Python Script could take 2-3 hours, mine is currently running that's why I'm writing this. I will soon Edit The Answer with Direct Link to File if it is done !

查看更多
登录 后发表回答