Boonkov is a smart and easy-to-use Markov chain generator and compiler.
const { toNgram, fromNgram } = require("boonkov");
const sentences = [
"This is the example input string",
"This is another example string",
];
const nOrder = 1;
// Sets up the N-Gram to be used by the algorithm.
const { nGram, beginnings } = toNgram(sentences, nOrder);
// This takes the results from the generator and utilises them.
const result = fromNgram(nGram, beginnings);
console.log(result);The toNgram function takes two parameters:
inputAn array containing the strings you want to make up your lexicon.nOrdernumber above 0 describing the depth of the algorithm. (Lower number for wackier generations)
It returns an object containing an nGram object with your N-Gram in and an array beginnings full of sentence starters.
the fromNgram function takes two parameters:
nGramA Markov chain N-Gram which you can generate using thetoNgramfunction.beginningsAn array of words that start the algorithm which you can generate using thetoNgramfunction.
It returns a string that is your Markov generated text.