Common Computing

September 20, 2007

Random Text Generator

Filed under: Uncategorized — th @ 3:57 pm

I implemented a Java library at hackday#003 which generates random texts after it has been trained with an arbitrary text corpus. If you are interested in the implementation details take a look at this webpage.

This is how a so called MarkovChain is instantiated:

import at.knallgrau.randomtext.*;

MarkovChain sentenceChain = new at.knallgrau.randomtext.MarkovChain(2, new SentenceLimiter(5));
MarkovChain lengthChain = new MarkovChain(2, new LengthLimiter(1000));

This is how a MarkovChain is “trained”:

MarkovChain chain = new MarkovChain(2);
chain.update(”give me two glasses of wine.”);
chain.update(”give me three bottles of beer.”);
chain.update(”give me two glasses of beer.”);
chain.update(”give me three bottles of wine.”);

This is how random text is generated from a trained MarkovChain:

String text = chain.generateRandomText();

I’m going to make the source code available in the next couple of days I’ve made the source code available even though the source is quite ugly (the api could be more elegant too) since hackday is all about getting something ready for a demo in less than seven hours. ;) You can check it out from my subversion repository:

svn co http://svn.thammerl.interlinked.org/repos/projects/randomtextgenerator randomtextgenerator

Download randomtextgenerator-1.0.jar

1 Comment »

  1. Random Text Generator…

    The source code of my hackday#003 project (which was a random text generator implemented in java) is now available on my personal blog along with some sample code. –Thomas …

    Trackback by Knallgrau Hackday — September 25, 2007 @ 11:52 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress