Import a dictionary

Hey

Im a beginner, and i try to make a programm who needs to import a dictionary ( the english dictionary with all words). Anyone know how to import this ?

WDYM with an English dictionary? Like something that for each word would return its definition?
The stdlib doesn’t provide such a thing and I doubt that any third-party library will.

Rather, you may find a TXT or JSON file that you may read, but a quick google search showed no result.
If you only need the list of words I did find some but neither would include definitions.

Thinking about it, the data of a dictionary is copyright of the publisher and they would be careful with such a database.

If you only need a list of words without definitions, there’s the words file.

Using the standard library, you could read the file line by line with Source, as described here (preferably going with Using for resource cleanup).

What you do with these words then (put them in a list, set, trie, database,…) depends on your use case.

2 Likes

Thank you, i understand, but how I have or download the “words file” because Im on windows and on the wikipedia’s page, idk the method to get it

words only works on Unix systems.
Not sure if Windows has an equivalent.

But, you may just use this one: https://github.com/dwyl/english-words

If you’re just doing local development, it’s probably fine to read the words list directly from the filesystem.

If this code needs to be deployed somewhere, then you probably want to package the words list with the code as a resource — this is typical in both Java and Scala. If you’re using sbt to build your code, you can throw the words file in src/main/resources and then read it with scala.io.Source.fromResource.

Thank for you fast answer its cool !

According to the Wikipedia entry, the words file is based on the Moby Project corpus, with download mirrors at Gutenberg. It is public domain in all its incarnations, so getting a copy of the words file or the Moby thesaurus file(s) once and distributing it along with the code should be fine.

2 Likes