A library that helps with creation of Markov chains, of any type.
Find a file
2016-05-29 17:10:22 -07:00
src Fix testing and compilation failures 2016-05-29 15:58:04 -07:00
.gitignore Gitignore 2016-01-12 22:33:51 -08:00
LICENCE Create LICENCE 2016-02-14 20:59:45 -08:00
pom.xml Update version - the project has been mavenized 2016-05-29 17:10:22 -07:00
README.md Actually Write README.md 2016-02-14 21:38:36 -08:00

MarkovLib

A library that helps with creation of Markov chains, of any type. More info on Markov Chains can be found on their wiki page

Usage

First, you need to create a ChainManager of the type you want your chain to be. For example, if I want to generate sentences from other sentences, I'd want to use the String type when I create my ChainManager.

ChainManager<String> chainManager = new ChainManager<String>("__start__", "__end__");

In the above piece of code, start and end are aribtrary values that are used to denote the beginning and the end of a chain. They can be anything you want.

Now you're ready to train the ChainManager! To train it, you need to pass it an array of values of the type you specified before, in the order that you wish they are fed. It's important that you pass the entire array in one call, because each call starts apending to the start. Essentially, running

chainManager.train("a");
chainManager.train("b");

Will result in a structure looking like this:

__start__ --> a (50%)
__start__ --> b (50%)

On the other hand, running

chainManager.train("a", "b");

Will result in the following structure:

__start__ --> a (100%)
a --> b (100%)

When you want to generate a chain, use

ArrayList<String> output = chainManager.generateChain();

Note that the array list is of the same type as ChainManager.