mrmaxguns / wonderwordsmodule

Generate random words and sentences with ease in Python. Be on the lookout for bugfixes and speed improvements in 2.3
https://wonderwords.readthedocs.io
MIT License
53 stars 11 forks source link

How much vocabulary range it has? #10

Closed jaytimbadia closed 3 years ago

jaytimbadia commented 3 years ago

Hey there, I am lucky I got here, exactly what I was in need of.

Just need to ask, which dictionary are you using to get the random word? Also is there any method to incorporate words from fantasy novels and other genres?

If yes, will methods like starts_with and ends_with work for newly added words?

Thanks in advance!!

mrmaxguns commented 3 years ago

Hello! I'm glad you found my library useful.

Currently, I am using 4 dictionaries for nouns, verbs, adjectives and curse words (curse words are disabled by default). They're found here.

With Wonderwords version 2.2 (the latest version; upgrade with pip install --upgrade wonderwords), there's built-in functionality to include your own custom word lists. Assuming you have fantasy_words.txt in the current folder, you could do something like this:

from wonderwords import RandomWord

# Read the text file with the words from fantasy novels
# and add the words to a list.
with open("fantasy_words.txt") as f:
    words = f.readlines()

# Now remove newlines (\n) from the words
words = [i.strip() for i in words]
# Finally, remove empty strings (caused by extra
# newlines at the end of the file).
words = [i for i in words if i]

# Here's where the magic happens. We create a RandomWord
# object with our list of words. Here, we create a category called
# 'fantasy_words' and set it to our list of words. This category
# is like nouns and verbs, except for our own custom words.
generator = RandomWord(fantasy_words=words)

# Finally, we can perform all the same operations with our
# custom words:
generator.word(starts_with="dr") # dragon

The example above is a brief summary. If you want to learn more about custom categories, check out the advanced tutorial.

I hope that helps! If you have any more questions or problems, please let me know.

mrmaxguns commented 3 years ago

Since this is a question about the use-case, I'll convert it to a discussion.