net.sf.turkey

Class Generator


public class Generator
extends java.lang.Object

The high-level generator interface. This is the class You use for text generation---it wraps all the dictionaries and settings. Just a single instance of this class exists (having more instances of it just does not make sense), You can get it by calling the getInstance() method.

Field Summary

static int
PARAGRAPHS_MAX
Maximum number of total paragraphs.
static int
PARAGRAPHS_MIN
Minimum number of total paragraphs.
static int
SENTENCES_MAX
Maximum number of sentences in a paragraph.
static int
SENTENCES_MIN
Minimum number of sentences in a paragraph.
protected ProbabilityTable
currentTable
The table used for text generation.
protected boolean
htmlOutput
Use HTML tags in the generated text?
protected static Generator
instance
The instance of Generator class.
protected int
paragraphsTotal
The total number of paragraphs.
protected static String[]
samples
The samples used for building the vocabulary.
protected int
sentencesPerPar
The number of sentences per paragraph.
protected Vector
tables
The list of available probability tables.

Constructor Summary

Generator()
Loads the text samples.

Method Summary

ProbabilityTable
getCurrentDictionary()
Vector
getDictionaryNames()
Returns the names of available dictionaries.
static Generator
getInstance()
Returns the Generator class instance.
int
getParagraphsTotal()
int
getSentencesPerPar()
String
getText()
Returns generated text.
boolean
isHTMLOutput()
void
selectDictionary(String name)
Selects dictionary by name, falls back to default dictionary if no dictionary with given name exists.
void
setHTMLOutput(boolean h)
void
setParagraphsTotal(int p)
Sets the total number of paragraphs in generated text.
void
setSentencesPerPar(int s)
Sets the number of sentences in generated paragraph.

Field Details

PARAGRAPHS_MAX

public static final int PARAGRAPHS_MAX
Maximum number of total paragraphs.
Field Value:
100

PARAGRAPHS_MIN

public static final int PARAGRAPHS_MIN
Minimum number of total paragraphs.
Field Value:
1

SENTENCES_MAX

public static final int SENTENCES_MAX
Maximum number of sentences in a paragraph.
Field Value:
20

SENTENCES_MIN

public static final int SENTENCES_MIN
Minimum number of sentences in a paragraph.
Field Value:
1

currentTable

protected ProbabilityTable currentTable
The table used for text generation.

htmlOutput

protected boolean htmlOutput
Use HTML tags in the generated text?

instance

protected static Generator instance
The instance of Generator class.

paragraphsTotal

protected int paragraphsTotal
The total number of paragraphs.

samples

protected static final String[] samples
The samples used for building the vocabulary. The parser in the ProbabilityTable class should chew up pretty much anything, but you can achieve best results by saving in the format illustrated by default Turkey samples --- plain text in UTF-8, one word per line, case does not matter. There's a simple Perl script in the samples/ directory that can do the dirty conversion work for you. I know this sample loading scheme is not an optimal solution, I'll try to come up with user-installed samples in the next version.

sentencesPerPar

protected int sentencesPerPar
The number of sentences per paragraph.

tables

protected Vector tables
The list of available probability tables.

Constructor Details

Generator

protected Generator()
Loads the text samples. This method is protected, to make sure nobody creates more instances of this class. If You want to get the Generator instance, use the getInstance() method.

Method Details

getCurrentDictionary

public ProbabilityTable getCurrentDictionary()

getDictionaryNames

public Vector getDictionaryNames()
Returns the names of available dictionaries.

getInstance

public static Generator getInstance()
Returns the Generator class instance.

getParagraphsTotal

public int getParagraphsTotal()

getSentencesPerPar

public int getSentencesPerPar()

getText

public String getText()
Returns generated text.

isHTMLOutput

public boolean isHTMLOutput()

selectDictionary

public void selectDictionary(String name)
Selects dictionary by name, falls back to default dictionary if no dictionary with given name exists.

setHTMLOutput

public void setHTMLOutput(boolean h)

setParagraphsTotal

public void setParagraphsTotal(int p)
Sets the total number of paragraphs in generated text. The number is kept between PARAGRAPHS_MIN and PARAGRAPHS_MAX.

setSentencesPerPar

public void setSentencesPerPar(int s)
Sets the number of sentences in generated paragraph. The number is kept between SENTENCES_MIN and SENTENCES_MAX.