This is a toy Markov chain generator that spun out of a game project. I wanted an easy way to create madlib-style scripts that could be selectively filled in use known word lists as well as generated text.
Beak isn't really meant for standalone use, but has enough baked in, I hope, where it should be relatively easy to integrate into any other project. It has no dependencies other than to node's fs
to load the source files. If you want to use it in the browser it should "just work" if you replace fs
with fetch
.
This demo implementation of beak will generate a snippet of text generated from the Markov chains if you don't pass it any arguments,
$ node beak.js
If you pass the file a script, though, it gets more interesting!
A script is a plaintext file that uses specific keys to pull in random text either from the Markov chains or from word lists. Here is an example script,
The @NOUN@ @ADVERB@ @VERB@ some @ADJECTIVE@ @NOUN@ under the @COLOR@ @NOUN@ of @PLACE@ while the tide sang @MARKOV 22@ -- wow.
Stuff like @NOUN@
and @VERB@
will pull a random entry from the associated list. @MARKOV 22@
will pull in a 22 element long generated piece of text.
$ node beak.js script.txt
Tune your word lists and corpus for outputs that most vibe with you.
Sample word lists and corpus are included here to get you started. It is relatively trivial to add other sorts of lists. The trick is to add the list to the lib
directory, and then to modify the big else if
in the fillGaps
function to support your new type of thing.