Skip to content

Instantly share code, notes, and snippets.

@samplereality
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samplereality/9783636 to your computer and use it in GitHub Desktop.
Save samplereality/9783636 to your computer and use it in GitHub Desktop.
Markov Chains using Moby-Dick
var rita = require('rita');
var fs = require('fs');
rm = new rita.RiMarkov(2), file = 'moby-dick.txt';
rm.minSentenceLength = 5;
rm.maxSentenceLength = 20;
fs.readFile(__dirname + '/' + file, function(e, data) {
if (e) throw e;
loadMarkov(data.toString());
});
function loadMarkov(text) {
rm.loadText(text);
var sentenceOne = rm.generateSentences(1);
var whale = sentenceOne;
console.log(whale);
}
@samplereality
Copy link
Author

Also download the Moby-Dick text file and save it in the same directory: https://www.dropbox.com/s/xtduz02rivpcpev/moby-dick.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment