Package uk.co.rafilevy.MarkovModels
Class StringBigramModel
- java.lang.Object
-
- uk.co.rafilevy.MarkovModels.MarkovModel<Pair<java.lang.String>>
-
- uk.co.rafilevy.MarkovModels.StringBigramModel
-
- All Implemented Interfaces:
TextGenerativeModel
public class StringBigramModel extends MarkovModel<Pair<java.lang.String>> implements TextGenerativeModel
An extension of a MarkovModel to be used specifically for text generation Very similar toStringMarkovModel
except works with transitions of sequences of consecutive string rather than single strings Will create sequences more closely related to original set but at higher risk of over-fitting
-
-
Method Summary
Modifier and Type Method Description static StringBigramModel
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 using a default start and end string pairstatic StringBigramModel
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 pair to another-
Methods inherited from class uk.co.rafilevy.MarkovModels.MarkovModel
fromSequences, generateSequence, generateSequence
-
-
-
-
Method Detail
-
fromStrings
public static StringBigramModel 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
StringBigramModel
used for generating string sequences according to the transition probabilities of string pairs calculated from the given collection of string sequences
-
fromStrings
public static StringBigramModel 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 using a default start and end string pair- Parameters:
strings
- the collection of string state sequencesregex
- the regex used to split the strings into actual state sequences- Returns:
- a
StringBigramModel
used for generating string sequences according to the transition probabilities of string pairs 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 pair to another- Specified by:
generateString
in interfaceTextGenerativeModel
- Returns:
- a generated string sequence concatenated into a single string
-
-