Groan
Javascript RTN text generation
About Groan
Groan is a Javascript library that generates random texts based on simple grammars. The original Groan program was written in FORTRAN by Dr. Chris Boyd. Inspired by his work, I implemented my own Groan in Perl. More recently, I wrote a new version from scratch using Javascript. The only thing that the Perl and Javascript versions share with the original version -- or with each other -- is the name and the general idea. They were implemented independently without reference to the original FORTRAN sources.
Examples
- Fantasy
- Randomly-generated descriptions of sword-and-sorcery novels.
- Headlines
- Randomly-generated headlines from tabloid newspapers.
- War of the Worlds
- Random nonsense texts inspired by the first paragraph of H.G. Wells’ classic novel, “The War of the Worlds”.
Technical notes
Groan implements text generation based on simple grammars. Each grammar is a set of rules that describe the text to be generated. Groan makes random choices based on that grammar to create new texts. Groan’s grammars are technically Type 2 Grammars, capable of generating context-free languages.
This makes them very limited: they don't have the richness of real natural languages. For example, the grammars used in Groan can’t cope easily with agreement between different words in a sentence. For example, if we wanted to generate ‘she says’ and ‘they say’, we might want to write a grammar that looked like this:
Phrase => Pronoun Verb Pronoun => ['she', 'they'] Verb => ['says', 'say']
The problem is that while that would let Groan generate the phrases we want, it would also generate ungrammatical phrases such as ‘she say’ and ‘they says’. If we wanted to avoid this, we’d need to write a larger grammar.
Phrase => SingularPhrase Phrase => PluralPhrase SingularPhrase => SingularPronoun SingularVerb PluralPhrase => PluralPronoun PluralVerb SingularPronoun => ['she'] PluralPronoun => ['they'] SingularVerb => ['says'] PluralVerb => ['say']
With its simple grammars, Groan doesn’t have any way to use information from one part of a phrase when it’s generating a different part. This is what is meant by ‘context-free’. To make Groan smarter would require adding mechanisms to let it process more complex -- ‘context-sensitive’ -- grammars.
Even though it’s very simple, Groan can still be useful. The examples on these pages are all fairly silly, but Groan could potentially be used in any application that requires generating texts -- for games, or sample data for interfaces or QA testing, or anything else.