Class Language.Modifier

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

public static class Language.Modifier extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    static final Language.Modifier
    For a language that has a 50% chance to repeat a single consonant.
    static final Language.Modifier
    For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them like å or ö, but not merged letters like æ and œ).
    static final Language.Modifier
    Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate for fixing a word that isn't pronounceable.
    static final Language.Modifier
    For a character who always lengthens 's' and 'z' sounds not starting a word.
    static final Language.Modifier
    Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ".
    static final Language.Modifier
    For a character who always pronounces 's', 'ss', and 'sh' as 'th'.
    static final Language.Modifier
    For a language that never repeats the same letter twice in a row.
    static final Language.Modifier
    Replaces any characters this can produce that aren't in ASCII or Latin-1 with Latin-script stand-ins; this will often use accented characters, but will only use those present in Latin-1 (which many fonts support).
    static final Language.Modifier
    Removes accented letters and the two non-English consonants from text generated with Language.NORSE.
    static final Language.Modifier
    Simple changes to merge "æ" into "ae", "œ" into "oe", and "ǽ" into "áe".
    static final Language.Modifier
    For a character who has a 20% chance to repeat a starting consonant or vowel.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
    Modifier(String pattern, String replacement)
     
    Modifier(String pattern, String replacement, double chance)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a Modifier that will replace the nth char in initial with the nth char in change.
    boolean
     
    int
     
    insertClosingConsonant(String insertion, double chance)
    Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant at the end of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted consonant to be likely to end every word of some sentences.
    insertClosingVowel(String insertion, double chance)
    Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the end of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely to end every word of some sentences.
    insertConsonant(String insertion, double chance)
    Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant (at any point in a word that had a consonant generated) with a probability of chance, so chance should be low (0.1 at most) unless you want the newly-inserted consonant to be likely to be present in every word of some sentences.
    insertOpeningConsonant(String insertion, double chance)
    Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant at the start of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted consonant to be likely to start every word of some sentences.
    insertOpeningVowel(String insertion, double chance)
    Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the start of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely to start every word of some sentences.
    insertVowel(String insertion, double chance)
    Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel generated) with a probability of chance, so chance should be low (0.1 at most) unless you want the newly-inserted vowel to be likely to be present in every word of some sentences.
    modify(com.github.tommyettinger.random.EnhancedRandom rng, StringBuilder sb)
     
    replacementTable(com.github.tommyettinger.ds.ObjectObjectOrderedMap<String,String> map)
    Creates a Modifier that will replace the nth String key in map with the nth value.
    Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs.
     
     
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • alterations

      public final Language.Alteration[] alterations
    • LISP

      public static final Language.Modifier LISP
      For a character who always pronounces 's', 'ss', and 'sh' as 'th'.
    • HISS

      public static final Language.Modifier HISS
      For a character who always lengthens 's' and 'z' sounds not starting a word.
    • STUTTER

      public static final Language.Modifier STUTTER
      For a character who has a 20% chance to repeat a starting consonant or vowel.
    • DOUBLE_VOWELS

      public static final Language.Modifier DOUBLE_VOWELS
      For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them like å or ö, but not merged letters like æ and œ).
    • DOUBLE_CONSONANTS

      public static final Language.Modifier DOUBLE_CONSONANTS
      For a language that has a 50% chance to repeat a single consonant.
    • NO_DOUBLES

      public static final Language.Modifier NO_DOUBLES
      For a language that never repeats the same letter twice in a row.
    • SIMPLIFY_NORSE

      public static final Language.Modifier SIMPLIFY_NORSE
      Removes accented letters and the two non-English consonants from text generated with Language.NORSE. Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr.
    • LIGATURES

      public static final Language.Modifier LIGATURES
      Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ".
    • SPLIT_LIGATURES

      public static final Language.Modifier SPLIT_LIGATURES
      Simple changes to merge "æ" into "ae", "œ" into "oe", and "ǽ" into "áe".
    • GENERAL_CLEANUP

      public static final Language.Modifier GENERAL_CLEANUP
      Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate for fixing a word that isn't pronounceable.
    • REDUCE_ACCENTS

      public static final Language.Modifier REDUCE_ACCENTS
      Replaces any characters this can produce that aren't in ASCII or Latin-1 with Latin-script stand-ins; this will often use accented characters, but will only use those present in Latin-1 (which many fonts support).
      The rationale for this Modifier is to allow users of Language who don't display with the wide-ranging fonts in the display module to still be able to display something reasonable for generated text.
  • Constructor Details

    • Modifier

      public Modifier()
    • Modifier

      public Modifier(String pattern, String replacement)
    • Modifier

      public Modifier(String pattern, String replacement, double chance)
    • Modifier

      public Modifier(Language.Alteration... alts)
  • Method Details

    • modify

      public StringBuilder modify(com.github.tommyettinger.random.EnhancedRandom rng, StringBuilder sb)
    • charReplacementTable

      public static Language.Modifier charReplacementTable(String initial, String change)
      Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and change to be the same length, but will use the lesser length if they are not equal-length. Because of the state of the text at the time modifiers are run, only lower-case letters need to be searched for.
      Parameters:
      initial - a String containing lower-case letters or other symbols to be swapped out of a text
      change - a String containing characters that will replace occurrences of characters in initial
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • replacementTable

      public static Language.Modifier replacementTable(com.github.tommyettinger.ds.ObjectObjectOrderedMap<String,String> map)
      Creates a Modifier that will replace the nth String key in map with the nth value. Because of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in this example to replace the repeated section with only the first vowel. The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced first, possibly making the later key not match), or if an earlier replacement causes a later one to become valid.
      Parameters:
      map - containing String keys to replace and String values to use instead; replacements happen in order
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • replacementTable

      public static Language.Modifier replacementTable(String... pairs)
      Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. This overload of replacementTable allows full regex syntax for search and replacement Strings, such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in this example to replace the repeated section with only the first vowel. The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced first, possibly making the later search not match), or if an earlier replacement causes a later one to become valid.
      Parameters:
      pairs - array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertVowel

      public static Language.Modifier insertVowel(String insertion, double chance)
      Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel generated) with a probability of chance, so chance should be low (0.1 at most) unless you want the newly-inserted vowel to be likely to be present in every word of some sentences.
      Parameters:
      insertion - the String to use as an additional vowel
      chance - the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertConsonant

      public static Language.Modifier insertConsonant(String insertion, double chance)
      Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant (at any point in a word that had a consonant generated) with a probability of chance, so chance should be low (0.1 at most) unless you want the newly-inserted consonant to be likely to be present in every word of some sentences.
      Parameters:
      insertion - the String to use as an additional consonant
      chance - the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertOpeningVowel

      public static Language.Modifier insertOpeningVowel(String insertion, double chance)
      Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the start of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, so this might not do anything.
      Parameters:
      insertion - the String to use as an additional opening vowel
      chance - the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertOpeningConsonant

      public static Language.Modifier insertOpeningConsonant(String insertion, double chance)
      Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant at the start of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted consonant to be likely to start every word of some sentences. Not all languages can start words with consonants, or do that very rarely, so this might not do anything.
      Parameters:
      insertion - the String to use as an additional opening consonant
      chance - the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertClosingVowel

      public static Language.Modifier insertClosingVowel(String insertion, double chance)
      Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the end of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely to end every word of some sentences. Not all languages can end words with vowels, or do that very rarely, so this might not do anything.
      Parameters:
      insertion - the String to use as an additional closing vowel
      chance - the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • insertClosingConsonant

      public static Language.Modifier insertClosingConsonant(String insertion, double chance)
      Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant at the end of a word with a probability of chance, so chance should be low (0.2 at most) unless you want the newly-inserted consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, or do that very rarely, so this might not do anything.
      Parameters:
      insertion - the String to use as an additional closing consonant
      chance - the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less
      Returns:
      a Modifier that can be added to a Language with its addModifiers() method
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • stringSerialize

      public String stringSerialize()
    • stringDeserialize

      public static Language.Modifier stringDeserialize(String data)