Home | Docs | Download | Subversion
Monday August 21, 2017

PyWordGen

Documentation

Example Usage

Defining a Language

To define a language, you need to have the stats file, the vowel file and the consonant file. With those in hand, instantiating Syntagmata will work. Assigning a Syntagmata instance to a Language class's language attribute is pretty much all there is to creating a new language.
    from wordgen.languages import Language
    from wordgen.syntagmata import Syntagmata

    class Gaelic(Language):

        def __init__(self):
            super(Gaelic, self).__init__()
            self.language = Syntagmata('gaelic')
    

Using a Language

Now we can do fun stuff like creating new words, passing an integer for the desired syllable count:
    >>> lang = Gaelic()
    >>> lang.makeWord(4)
    u'gachareag'
    >>> lang.makeWord(1)
    u'rod'
    >>> lang.makeWord(7)
    u"a'eannadhlirairie"
    
There are also some convenience functions for creating word lists:
  • a word list generator (just call next on it)
  • a method for retruning a word list (slice of the python geneator above)
  • printing a word list
  • saving a word list to disk
Here's the generator in action:
    >>> wl = lang.wordList()
    >>> wl.next()
    u'eilththarathrodaichase'
    >>> wl.next()
    u'saen'
    >>> wl.next()
    u'anne'
    >>> wl.next()
    u'anntealtrainear'
    >>> wl.next()
    u'masteathealeadalich'
    
With any of those methods, you can pass a maxSyllables parameter that will limit how long the words in the llist will be (the number of syllables for each generated word is determined randomly for the word list methods). The last three methods take an additional count parameter limiting the number of words to return.

Supported Languages

To get a list of languages currently supported, you can do the following:
    >>> from wordgen.languages import printSupportedLanguages
    >>> printSupportedLanguages()
    Afrikaner
    Arabic
    Chinese
    English
    French
    Gaelic
    German
    Hebrew
    Hindi
    Japanese
    Korean
    Latin
    OldEnglish
    OldNorse
    Onomatopoetic
    Sanskrit
    Spanish
    

Creating a Composite Language

Creating composite languages is just plain fun. There are probably all sorts of reasons to do this, but for the authors of this software, the one it was designed for and is used for most of the time is creating fictional worlds. You can often get just the "sound" you're looking for by combining different languages in different ratios. Here's how it works:
    >>> from wordgen.languages import Composite
    >>> from wordgen.languages import Sanskrit, Korean, French
    >>> c = Composite()
    >>> c.addLanguage(Sanskrit, 5)
    >>> c.addLanguage(Korean 2)
    
If we're going to be doing a lot of combination, it could be helpful to see what the current composition of our new language is:
    
    >>> c.report()
    sanskrit: 5 parts (71%)
    korean: 2 parts (28%)
    
Let's add another one and then check the ratios again:
    >>> c.addLanguage(French, 3)
    >>> c.report()
    sanskrit: 5 parts (50%)
    korean: 2 parts (20%)
    french: 3 parts (30%)
    
Now, let's take a look at what we've just created:
    >>> c.printWordList()
    bhalathae
    bodayadskis
    elmjnaanam
    estmpte
    etxapa
    fonalatol
    jeims
    kaaaantdasapaahi
    leine
    lemakabaaptan
    meksharetim
    motyuskaalahnaalam
    nangjuvyaadhyanchakaatre
    neh
    ninnals
    pouncha
    san
    shie
    traisondima
    trayint
    

Dessert

If you want to see a sampling of all languages, you can do something like this:
    >>> for name in languages.getSupportedLanguages():
    ...   print name
    ...   words = getattr(languages, name)().getWordList(3,4)
    ...   for w in words:
    ...     print w,
    ...   print
    
Which will give you something along these lines:
    Afrikaner
    disans ngees taam
    Arabic
    alddn suu warau
    Chinese
    xian juanggoun nungzhain
    English
    ins logs paidittos
    French
    deuigigt leroies oumers
    Gaelic
    airsch annn rilbh
    German
    geckebjell lepiwe wich
    Hebrew
    klhl kzbyhrn vxkmal
    Hindi
    paya rapnarao sadbhasya
    Japanese
    taeshi tanaishi tosagyonko
    Korean
    ayng gwammyam junsu
    Latin
    deorr expnum intm
    OldEnglish
    cypeneed gen wætoloor
    OldNorse
    föðingu keguggði okngleitssi
    Onomatopoetic
    boot mune weechazzle
    Sanskrit
    chagashhtaa syan yogh
    Spanish
    els poial suntemano
    

Home | Docs | Download | Subversion
Copyright © 2003 AdytumSolutions, Inc.
All rights reserved.
SourceForge.net Logo