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

    Fields inherited from class net.andreinc.markovneat.MChain

    chain, random, states
  • 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.String generateText​(int approximateLength)
    Generates text starting with an arbitrary state from the chain.
    java.lang.String generateText​(MState<java.lang.String> state, int approximateLength)
    Generates random text starting with a supplied initial MState<String>.
    void train​(java.nio.file.Path path)
    Trains the chain using a txt file as the source.
    void train​(java.util.List<java.lang.String> lines)  

    Methods inherited from class net.andreinc.markovneat.MChain

    add, add, generate, generate, randomState, train, train, train

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public java.lang.String generateText​(MState<java.lang.String> state, int approximateLength)
      Generates random text starting with a supplied initial MState<String>.

      If the state doesn't exist in the chain an IllegalArgumentException is 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