Class Language.SentenceForm
java.lang.Object
com.github.yellowstonegames.text.Language.SentenceForm
- Enclosing class:
Language
A simple way to bundle a Language with the arguments that would be passed to it when calling
Language.sentence(EnhancedRandom, int, int, String[], String[], double, int) or one of its overloads.
A common use for this is to allow repeated generation of similar sentences, such as those said by the same
character or similar characters in the same circumstances. You can call sentence() on this to produce
another String sentence with the parameters it was given at construction. The parameters to
SentenceForm(Language, EnhancedRandom, int, int, String[], String[], double, int) are stored in fields of
the same name, and all fields in this class are public and modifiable.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBuilds a SentenceForm with all default fields, usingLanguage.FANTASY_NAMEfor a language, using between 1 and 9 words in a sentence, and otherwise defaulting to howSentenceForm(Language, int, int)behaves.SentenceForm(Language language, int minWords, int maxWords) Builds a SentenceForm with only a few fields specified.SentenceForm(Language language, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency) Builds a SentenceForm with all fields specified except forrng, which will be made based on Language's staticLanguage.srngfield, and maxChars, which means the sentence length will be limited only by maxWords and the length of words produced.SentenceForm(Language language, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency, int maxChars) Builds a SentenceForm with all fields specified except forrng, which will be made based on Language's staticLanguage.srngfield.SentenceForm(Language language, com.github.tommyettinger.random.EnhancedRandom rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency, int maxChars) Builds a SentenceForm with all fields specified; each value is referenced directly except forrng, which will be copied to get the EnhancedRandom used internally. -
Method Summary
Modifier and TypeMethodDescriptionbooleansentence()Generates a pseudo-random sentence using the configured Language, punctuation, min/max word length, and maximum char length.static Language.SentenceFormstringDeserialize(String ser) toString()
-
Field Details
-
rng
public com.github.tommyettinger.random.EnhancedRandom rng -
minWords
public int minWords -
maxWords
public int maxWords -
maxChars
public int maxChars -
midPunctuation
-
endPunctuation
-
midPunctuationFrequency
public double midPunctuationFrequency -
language
-
-
Constructor Details
-
SentenceForm
public SentenceForm()Builds a SentenceForm with all default fields, usingLanguage.FANTASY_NAMEfor a language, using between 1 and 9 words in a sentence, and otherwise defaulting to howSentenceForm(Language, int, int)behaves. -
SentenceForm
Builds a SentenceForm with only a few fields specified. Therngwill be made based on Language's staticLanguage.srngfield, maxChars will be -1 so the sentence length will be limited only by maxWords and the length of words produced, and the between-word and end-of-sentence punctuation will be set to reasonable defaults. This places either a comma or a semicolon after a word in the middle of a sentence about 18% of the time (midPunctuationFrequencyis 0.18), and can end a sentence in a period, exclamation mark, question mark, or ellipsis (the "..." punctuation).- Parameters:
language- A Language to use to generate wordsminWords- minimum words per sentencemaxWords- maximum words per sentence
-
SentenceForm
public SentenceForm(Language language, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency) Builds a SentenceForm with all fields specified except forrng, which will be made based on Language's staticLanguage.srngfield, and maxChars, which means the sentence length will be limited only by maxWords and the length of words produced.- Parameters:
language- A Language to use to generate wordsminWords- minimum words per sentencemaxWords- maximum words per sentencemidPunctuation- an array of Strings that can be used immediately after words in the middle of sentences, like "," or ";"endPunctuation- an array of Strings that can end a sentence, like ".", "?", or "..."midPunctuationFrequency- the probability that two words will be separated by a String from midPunctuation, between 0.0 and 1.0
-
SentenceForm
public SentenceForm(Language language, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency, int maxChars) Builds a SentenceForm with all fields specified except forrng, which will be made based on Language's staticLanguage.srngfield.- Parameters:
language- A Language to use to generate wordsminWords- minimum words per sentencemaxWords- maximum words per sentencemidPunctuation- an array of Strings that can be used immediately after words in the middle of sentences, like "," or ";"endPunctuation- an array of Strings that can end a sentence, like ".", "?", or "..."midPunctuationFrequency- the probability that two words will be separated by a String from midPunctuation, between 0.0 and 1.0maxChars- the maximum number of chars to use in a sentence, or -1 for no hard limit
-
SentenceForm
public SentenceForm(Language language, com.github.tommyettinger.random.EnhancedRandom rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, double midPunctuationFrequency, int maxChars) Builds a SentenceForm with all fields specified; each value is referenced directly except forrng, which will be copied to get the EnhancedRandom used internally.- Parameters:
language- A Language to use to generate wordsrng- an EnhancedRandom that will be copied to get the random number generator this will useminWords- minimum words per sentencemaxWords- maximum words per sentencemidPunctuation- an array of Strings that can be used immediately after words in the middle of sentences, like "," or ";"endPunctuation- an array of Strings that can end a sentence, like ".", "?", or "..."midPunctuationFrequency- the probability that two words will be separated by a String from midPunctuation, between 0.0 and 1.0maxChars- the maximum number of chars to use in a sentence, or -1 for no hard limit
-
-
Method Details
-
sentence
Generates a pseudo-random sentence using the configured Language, punctuation, min/max word length, and maximum char length.- Returns:
- a new String of a random sentence using the configuration this knows
-
stringSerialize
-
stringDeserialize
-
equals
-
toString
-