Werder - Meaningless gibberish generator
use Silly::Werder; my $werds = new Silly::Werder; # Set the min and max number of werds per line $werds->set_werds_num(5, 9); # Set the min and max # of syllables per werd $werds->set_syllables_num(3, 7); # End the sentences in a newline $werds->end_with_newline(1); # Set the language to mimic $werds->set_language("English", "small"); # Return a random sentence, question, or exclamation $line = $werds->line; $sentence = $werds->sentence; $question = $werds->question; $exclamation = $werds->exclamation; # Get a single werd $werd = $werds->get_werd; # Generate a long random sentence calling as a class method Silly::Werder->set_werds_num(10,20); print Silly::Werder->line; # All of the methods can be used as either class methods # or object methods.
This module is used to create pronounceable yet completely meaningless language. It is good for sending to a text-to-speech program (ala festival), generating passwords, annoying people on irc, and all kinds of fun things.
This new release is a full rewrite of the engine. It is based on grammar files derived from real text of real languages. Several grammars are provided for you to use, and you can also create your own.
- set_werds_num(min, max)
Sets the minimum and maximum werds to be generated. Both arguments are required. min must be lower than max. Returns 0 on success, -1 on error.
- set_syllables_num(min, max)
Sets the minimum and maximum syllables per werd. The max is a soft limit unless you call set_hard_syllable_max with a non-zero argument. The reason for this is that in mimicking real speech, not every syllable is a valid ending to a werd. If this is called with either min or max higher than the value set by set_hard_syllable_max, the hard max will be disabled. Returns 0 on success, and -1 on error.
Sets the hard max for syllables in a werd. This will end a werd when it's reached this number of syllables regardless of whether it makes sense as an ending or not. Setting this to zero will disable it. If you pass a non-zero value lower than the current minimum, it will not set the hard max and return -1. Returns 0 on success.
Silly::Werder no longer returns sentences with a newline at the end by default!
If you want that behavior, call this function with a non-zero argument. Calling with zero will disable it.
If you want to ignore the syllable linkage built into a grammar and just pick random syllables, call this with a non-zero argument. To disable, call with 0. This feature is off by default.
- set_language(language, [variant])
Load a different language grammar than the default (which is English). The languages included with Silly::Werder are
- English - the default grammar
- English, small - a smaller and faster English
- German - a German derived grammar
- German, small - smaller German
- French - a French derived grammar
- French, small - smaller French
- Swedish - a Swedish derived grammar
- Swedish, small - smaller Swedish
- Shakespeare - a grammar modeled after The Bard
Generate a random sentence and end in period.
Same as sentence but with a ? at the end.
Same as sentence but with a ! at the end. In previous versions this was misspelled as exclaimation. That method is deprecated but still works for compatibility.
Creates a sentence with . ? or ! randomly.
Create and return a single werd.
- build_grammar(text, [appear, [follow, [locale]]])
By calling this routine, you can build your own grammar to produce Silly::Werder text.
* The first argument should be a scalar containing text to parse. If this text is not sufficiently long, there will not be enough of a sample to generate decent werds so be sure to feed it enough!
The appear and follow arguments are thresholds that Silly::Werder uses to determine if a particular syllable pair is worthy of adding to the grammar. These are mainly used to reduce the size of the resulting grammar.
* appear means that the pair must appear in that order greater than or equal to that number of times.
* follow means that any given syllable must have that number of unique other syllables (the end of a word is a special "syllable", and counts as 1).
* locale is your system locale which can be used to let Perl know what is upper and lower case for a particular locale. In other words, if you are parsing French, pass fr_FR, if you are parsing German, pass de_DE. This is not required but will improve the results of your grammar. Also note that your system needs to have the locales you want installed in order to use them. See the perllocale pod for more information.
This routine will return an array reference containing any words that were unable to be parsed.
This routine will save the current grammar used by Silly::Werder to a file who's path is passed as the argument. If no grammar has been loaded, it will load and dump English. Returns -1 if there is an error, and 0 on success.
This routine will save the current list of syllables that is being used by Silly::Werder to a file who's path is passed as the argument. Returns -1 if there is an error, and 0 on success.
Loads a grammar file of the format output by dump_grammar. Returns -1 if there is an error, and 0 on success.
Loads a syllable file of the format output by dump_syllables. Returns -1 if there is an error, 0 on success.
* Word is misspelled (quite intentionally!) as werd throughout the source and docs.
* locales not being loaded for each grammar result in incorrect capitalization sometimes.
Silly::Werder was created and implemented by Dave Olszewski, aka cxreg. You can send comments, suggestions, flames, or love letters to email@example.com