marky

Marky is a library for creating Markov chains from arbitrary text input. It comes with a simple command line front end, named marky-file, which can be used to read text files and produce entertaining output.

The library is divided into several discrete components, allowing developers and advanced users to easily customize and extend its behavior. It currently supports a few scoring and selection methods, and temporary (hash map) or persistent (SQLite) storage of its state. For a description of Marky's internal structure, take a look at the documentation.

It's also pretty fast. In a Release build on my 3 year old laptop, the marky-file tool imports all of "My Antonia" and produces a chain in about 0.25 seconds. If the data is imported into a SQLite db (~3 seconds), it takes around 0.1 seconds to produce a chain from that. Here are some examples:

Direct Printing

apps$ time ./marky-file -p ../tests/data-my_antonia.txt
The windy springs and he used to the check.

real 0m0.255s
user 0m0.224s
sys 0m0.028s

apps$ time ./marky-file -p ../tests/data-my_antonia.txt -s springs
While we could not notice indicating that breathless, brilliant heat it had a royal house; the smell the best horse, and tried to do go back porch, resting against hot springs and the cornfields with open window.

real 0m0.255s
user 0m0.236s
sys 0m0.016s

SQLite Caching

Create DB:

apps$ time ./marky-file -i ../tests/data-my_antonia.txt

real 0m3.214s
user 0m2.692s
sys 0m0.500s

Produce from DB:

apps$ time ./marky-file -e
She was so joyous and glitter and velvety.

real 0m0.098s
user 0m0.084s
sys 0m0.012s

apps$ time ./marky-file -e
I was so deep under the years and sheet-draped garments on her propped my promise, of that had heard grandmother told me with Frances, after they could smell of its height, her hands.

real 0m0.104s
user 0m0.096s
sys 0m0.004s

apps$ time ./marky-file -e
On his sledge overturned, with you.

real 0m0.084s
user 0m0.080s
sys 0m0.000s

apps$ time ./marky-file -e -s you.
There, without you.

real 0m0.003s
user 0m0.000s
sys 0m0.000s