Class Language.SentenceForm

java.lang.Object
com.github.yellowstonegames.text.Language.SentenceForm
Enclosing class:
Language

public static class Language.SentenceForm extends Object
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 Details

    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
    • minWords

      public int minWords
    • maxWords

      public int maxWords
    • maxChars

      public int maxChars
    • midPunctuation

      public String[] midPunctuation
    • endPunctuation

      public String[] endPunctuation
    • midPunctuationFrequency

      public double midPunctuationFrequency
    • language

      public Language language
  • Constructor Details

    • SentenceForm

      public SentenceForm()
      Builds a SentenceForm with all default fields, using Language.FANTASY_NAME for a language, using between 1 and 9 words in a sentence, and otherwise defaulting to how SentenceForm(Language, int, int) behaves.
    • SentenceForm

      public SentenceForm(Language language, int minWords, int maxWords)
      Builds a SentenceForm with only a few fields specified. The rng will be made based on Language's static Language.srng field, 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 (midPunctuationFrequency is 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 words
      minWords - minimum words per sentence
      maxWords - 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 for rng, which will be made based on Language's static Language.srng field, 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 words
      minWords - minimum words per sentence
      maxWords - maximum words per sentence
      midPunctuation - 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 for rng, which will be made based on Language's static Language.srng field.
      Parameters:
      language - A Language to use to generate words
      minWords - minimum words per sentence
      maxWords - maximum words per sentence
      midPunctuation - 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
      maxChars - 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 for rng, which will be copied to get the EnhancedRandom used internally.
      Parameters:
      language - A Language to use to generate words
      rng - an EnhancedRandom that will be copied to get the random number generator this will use
      minWords - minimum words per sentence
      maxWords - maximum words per sentence
      midPunctuation - 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
      maxChars - the maximum number of chars to use in a sentence, or -1 for no hard limit
  • Method Details

    • sentence

      public String 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

      public String stringSerialize()
    • stringDeserialize

      public static Language.SentenceForm stringDeserialize(String ser)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object