Package uk.co.rafilevy.MarkovModels
Class StringMarkovModel
- java.lang.Object
-
- uk.co.rafilevy.MarkovModels.MarkovModel<java.lang.String>
-
- uk.co.rafilevy.MarkovModels.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 stringstatic 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 regexjava.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 uk.co.rafilevy.MarkovModels.MarkovModel
fromSequences, generateSequence, generateSequence
-
-
-
-
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 sequencesregex
- the regex used to split the strings into actual state sequencesstartString
- the unique string not seen anywhere else in the sequences used internally indicate the start of a sentenceendString
- 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 sequencesregex
- 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 interfaceTextGenerativeModel
- Returns:
- a generated string sequence concatenated into a single string
-
-