Class StringMarkovModel

  • All Implemented Interfaces:
    TextGenerativeModel

    public class StringMarkovModel
    extends MarkovModel<java.lang.String>
    implements TextGenerativeModel
    An extension of a MarkovModel to be used specifically for text generation State sequences are supplied as strings rather than lists and can be decoded by using a regex to split the string into a sequence Sequences are then generated as normal and turned into strings by concatenating them with a " " in between Useful for generating texts in the style of other text corpora
    • Method Summary

      Modifier and Type Method Description
      static StringMarkovModel fromStrings​(java.util.Collection<java.lang.String> strings, java.lang.String regex)
      A static factory method to create a model given a collection of string state sequences to be split into sequences with a given regex with a default start and end string
      static StringMarkovModel fromStrings​(java.util.Collection<java.lang.String> strings, java.lang.String regex, java.lang.String startString, java.lang.String endString)
      A static factory method to create a model given a collection of string state sequences to be split into sequences with a given regex
      java.lang.String generateString()
      Generates a random string sequence using the model's probabilities of transitioning from a given string to another
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • fromStrings

        public static StringMarkovModel fromStrings​(java.util.Collection<java.lang.String> strings,
                                                    java.lang.String regex,
                                                    java.lang.String startString,
                                                    java.lang.String endString)
        A static factory method to create a model given a collection of string state sequences to be split into sequences with a given regex
        Parameters:
        strings - the collection of string state sequences
        regex - the regex used to split the strings into actual state sequences
        startString - the unique string not seen anywhere else in the sequences used internally indicate the start of a sentence
        endString - the unique string not seen anywhere else in the sequences used to indicate the start of a sentence
        Returns:
        a StringMarkovModel used for generating string sequences according to the transition probabilities calculated from the given collection of string sequences
      • fromStrings

        public static StringMarkovModel fromStrings​(java.util.Collection<java.lang.String> strings,
                                                    java.lang.String regex)
        A static factory method to create a model given a collection of string state sequences to be split into sequences with a given regex with a default start and end string
        Parameters:
        strings - the collection of string state sequences
        regex - the regex used to split the strings into actual state sequences
        Returns:
        a StringMarkovModel used for generating string sequences according to the transition probabilities calculated from the given collection of string sequences
      • generateString

        public java.lang.String generateString()
        Generates a random string sequence using the model's probabilities of transitioning from a given string to another
        Specified by:
        generateString in interface TextGenerativeModel
        Returns:
        a generated string sequence concatenated into a single string