Package net.andreinc.markovneat
Class MChainText
java.lang.Object
net.andreinc.markovneat.MChain<java.lang.String>
net.andreinc.markovneat.MChainText
public class MChainText extends MChain<java.lang.String>
An extension of the
MChain class specialised in the generation of "English" text.-
Field Summary
-
Constructor Summary
Constructors Constructor Description MChainText()MChainText(int noStates)MChainText(int noStates, java.util.Random random) -
Method Summary
Modifier and Type Method Description java.lang.StringgenerateText(int approximateLength)Generates text starting with an arbitrary state from the chain.java.lang.StringgenerateText(MState<java.lang.String> state, int approximateLength)Generates random text starting with a supplied initialMState<String>.voidtrain(java.nio.file.Path path)Trains the chain using a txt file as the source.voidtrain(java.util.List<java.lang.String> lines)
-
Constructor Details
-
MChainText
public MChainText() -
MChainText
public MChainText(int noStates) -
MChainText
public MChainText(int noStates, java.util.Random random)
-
-
Method Details
-
train
public void train(java.nio.file.Path path)Trains the chain using a txt file as the source.Splits the text into words, removes quotes and trains the chain.
- Parameters:
path- The path to the source text file.
-
train
public void train(java.util.List<java.lang.String> lines) -
generateText
Generates random text starting with a supplied initialMState<String>.If the state doesn't exist in the chain an
IllegalArgumentExceptionis thrown.If the state starts with a "." a new random state will be arbitrary picked form the chain.
- Parameters:
approximateLength- The approximate length of the text. The generated output can be smaller or bigger than the desired size with a few characters.state- The initial state.- Returns:
- The arbitrary generated text.
-
generateText
public java.lang.String generateText(int approximateLength)Generates text starting with an arbitrary state from the chain.- Parameters:
approximateLength- The approximate length of the text. The generated output can be smaller or bigger than the desired size with a few characters.- Returns:
- Arbitrary text from the chain
-