net.sf.turkey

Class ProbabilityTable


public class ProbabilityTable
extends java.lang.Object

Text analyzer and generator. This class is able to analyze given sample of text and generate some text based on the sample's characteristics. The real work gets done in this class.

Field Summary

static int
PREFIX_LENGTH
The prefix length.
protected int
avgWordLength
Average word length of the analyzed text.
protected String
name
The name of the table.
protected Random
rnd
Random seed generator.
protected Map
table
Probability table.

Constructor Summary

ProbabilityTable(InputStream in, String n)
Builds the probability table from an input stream.

Method Summary

protected void
analyzeString(String s)
Collects character characteristics of a single string.
String
dump()
Returns string representation of the probability table.
Character
getNext(String prefix)
Returns character that is likely to follow given prefix.
String
getSentence()
Generates a sentence.
String
getWord()
Generates a word.
String
toString()

Field Details

PREFIX_LENGTH

public static final int PREFIX_LENGTH
The prefix length. Larger values mean better (less random) output, best are values around 3.
Field Value:
3

avgWordLength

protected int avgWordLength
Average word length of the analyzed text.

name

protected String name
The name of the table.

rnd

protected Random rnd
Random seed generator.

table

protected Map table
Probability table. Contains strings and their probable suffixes.

Constructor Details

ProbabilityTable

public ProbabilityTable(InputStream in,
                        String n)
            throws IOException
Builds the probability table from an input stream.

Method Details

analyzeString

protected void analyzeString(String s)
Collects character characteristics of a single string.

dump

public String dump()
Returns string representation of the probability table.

getNext

public Character getNext(String prefix)
            throws UnknownPrefix
Returns character that is likely to follow given prefix.

getSentence

public String getSentence()
Generates a sentence.

getWord

public String getWord()
Generates a word.

toString

public String toString()