Skip to content

Basic Usage

Importing and initializing WordSiv

Once you've installed WordSiv, try generating a sentence:

from wordsiv import WordSiv

# Make a WordSiv object, w/ default Vocab set to English
wsv = WordSiv(vocab="en")

# Generate a sentence w/out any word filtering
print(wsv.sent())

You should see a random sentence in the console in the lower-right of DrawBot!

Check out the Quick Reference if you want to quickly jump into WordSiv, or read on for more detailed information.

Listing Vocabs

WordSiv generates text using Vocabs: objects that contain a word list (usually with occurrence counts) for a given language. WordSiv includes some Vocabs, and you can make your own (instructions coming soon!). You can see all available Vocabs with: list_vocabs():

from wordsiv import WordSiv

wsv = WordSiv()
print(wsv.list_vocabs())

Selecting a Vocab

You can set which Vocab you want to use on WordSiv object initialization, which will affect all text generation methods you call:

from wordsiv import WordSiv

wsv = WordSiv(vocab="ar")
print(wsv.para())

Alternatively, you can specify vocab when you are calling word(), sent(), etc.:

from wordsiv import WordSiv

wsv = WordSiv()
print(wsv.para(vocab="en"))

Note

The vocab argument for word(), sent(), etc. has precedence:

from wordsiv import WordSiv

wsv = WordSiv(vocab="en")

# paragraph in English
print(wsv.para())
# paragraph in Spanish
print(wsv.para(vocab="es"))

Restricting the Glyph Set

The glyphs argument specifies a whitelist of glyphs that WordSiv will use to constrain text generation.

You can set glyphs on WordSiv object initialization, which will affect all subsequent text generation methods you call:

from wordsiv import WordSiv

wsv = WordSiv(vocab="en", glyphs="HAMBUGERFONTShambugerfonts.,")
print(wsv.words())

Alternatively, you can specify glyphs when you are calling word(), sent(), etc.:

from wordsiv import WordSiv

wsv = WordSiv(vocab="en")
print(wsv.words(glyphs="hambugerfonts.,"))

Note

The glyphs argument for word(), sent(), etc. has precedence:

from wordsiv import WordSiv

wsv = WordSiv(vocab="en", glyphs="HAMBUGERFONTShambugerfonts.,")

# uses glyphs "HAMBUGERFONTShambugerfonts.,"
print(wsv.words())
# uses glyphs "hambugerfonts.,""
print(wsv.words(glyphs="hambugerfonts.,"))