public class Thesaurus
extends java.lang.Object
implements java.io.Serializable
"By the light`adj` fire`noun` in my heart, I will vanquish thee!"
, which
has the keywords light`adj`
and fire`noun`
, and could produce
"By the shimmering inferno in my heart, I will vanquish thee!"
on one run, and
"By the gleaming conflagration in my heart, I will vanquish thee!"
on another. This can also generate some
plant names and basic descriptions of potions, as well as make some text sound like ORK
.
Modifier and Type | Field and Description |
---|---|
static OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
adjective |
java.util.ArrayList<FakeLanguageGen.Alteration> |
alterations |
static OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
categories |
FakeLanguageGen |
defaultLanguage |
protected GapShuffler<java.lang.String> |
flowerTermShuffler |
protected GapShuffler<java.lang.String> |
fruitTermShuffler |
static OrderedMap<java.lang.CharSequence,FakeLanguageGen> |
languages |
java.lang.String |
latestGenerated |
OrderedMap<java.lang.CharSequence,GapShuffler<java.lang.String>> |
mappings |
static OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
noun |
static OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> |
nouns |
static OrderedMap<java.lang.CharSequence,java.lang.Integer> |
numberAdjectives |
static OrderedMap<java.lang.CharSequence,java.lang.Integer> |
numbers |
protected GapShuffler<java.lang.String> |
nutTermShuffler |
static Thesaurus |
ORK
Thesaurus preset that changes all text to sound like this speaker: "Desaurus preset dat changez all text to sound
like dis speakah." You may be familiar with a certain sci-fi game that has orks who sound like this.
|
protected GapShuffler<java.lang.String> |
plantTermShuffler |
protected GapShuffler<java.lang.String> |
potionTermShuffler |
java.util.ArrayList<FakeLanguageGen> |
randomLanguages |
SilkRNG |
rng |
protected static regexodus.Pattern |
similarFinder |
protected GapShuffler<java.lang.String> |
vegetableTermShuffler |
protected static regexodus.Pattern |
wordMatch |
static Thesaurus |
ZOMBIE
Thesaurus preset that sharply reduces the used letters to only: a, b, g, h, m, n, r, and z.
|
Constructor and Description |
---|
Thesaurus()
Constructs a new Thesaurus with an unseeded RNG used to shuffle word order.
|
Thesaurus(IRNG rng)
Constructs a new Thesaurus, seeding its RNG (used to shuffle word order) with the next long from the given RNG.
|
Thesaurus(long shuffleSeed)
Constructs a new Thesaurus, seeding its RNG (used to shuffle word order) with shuffleSeed.
|
Thesaurus(java.lang.String shuffleSeed)
Constructs a new Thesaurus, seeding its RNG (used to shuffle word order) with shuffleSeed.
|
Modifier and Type | Method and Description |
---|---|
Thesaurus |
addArchivedCategories(java.lang.String archive)
Given an archive String saved by
archiveCategories() (probably from another version of SquidLib), this
makes the Thesaurus class act like it did in that archive, assuming the rng is seeded the same. |
Thesaurus |
addArchivedCategoriesAlternate(java.lang.String archive)
Given an archive String saved by
archiveCategoriesAlternate() (probably from another version of
SquidLib), this makes the Thesaurus class act like it did in that archive, assuming the rng is seeded
the same and uses the same algorithm/RandomnessSource. |
Thesaurus |
addCategory(java.lang.String keyword,
java.util.Collection<java.lang.String> synonyms)
Allows this Thesaurus to replace a specific keyword, typically containing multiple backtick characters
(
` ) so it can't be confused with a "real word," with one of the words in synonyms (chosen in shuffled
order). |
Thesaurus |
addFakeWords()
Adds a large list of words pre-generated by FakeLanguageGen and hand-picked for fitness, and makes them
accessible with a keyword based on the language.
|
Thesaurus |
addKnownCategories()
Adds several pre-made categories to this Thesaurus' known categories, but won't cause it to try to replace normal
words with synonyms (only categories, which contain backticks in the name).
|
Thesaurus |
addReplacement(java.lang.CharSequence before,
java.lang.String after) |
static java.lang.String |
archiveCategories()
Gets a stable (large) String that stores all categories this version of Thesaurus knows, as well as all of the
words each category includes.
|
static java.lang.String |
archiveCategoriesAlternate()
Gets a stable (large) String that stores all categories this version of Thesaurus knows, as well as all of the
words each category includes.
|
java.lang.String |
lookup(java.lang.String word) |
java.lang.String |
makeFlowerName()
Generates a random possible name for a flower or flowering plant, such as "tulip of Jirui" or "thorny lilac".
|
java.lang.String |
makeFlowerName(FakeLanguageGen language)
Generates a random possible name for a flower or flowering plant, such as "tulip of Jirui" or "thorny lilac",
with the FakeLanguageGen already available instead of randomly created.
|
java.lang.String |
makeFruitName()
Generates a random possible name for a fruit, such as "green lime-melon" or "Ung's date".
|
java.lang.String |
makeFruitName(FakeLanguageGen language)
Generates a random possible name for a fruit, such as "green lime-melon" or "Ung's date",
with the FakeLanguageGen already available instead of randomly created.
|
java.lang.String |
makeNationName()
Generates a random possible name for a nation, such as "Iond-Gouccief Alliance" or "The Last Drayo Commonwealth".
|
java.lang.String |
makeNationName(FakeLanguageGen language)
Generates a random possible name for a nation, such as "Iond-Gouccief Alliance" or "The Last Drayo Commonwealth",
with the FakeLanguageGen already available instead of randomly created.
|
java.lang.String |
makeNutName()
Generates a random possible name for a nut or bean, such as "nut of Gikoim" or "Pelyt's cashew".
|
java.lang.String |
makeNutName(FakeLanguageGen language)
Generates a random possible name for a nut or bean, such as "nut of Gikoim" or "Pelyt's cashew",
with the FakeLanguageGen already available instead of randomly created.
|
java.lang.String |
makePlantName()
Generates a random possible name for a plant or tree, such as "Ikesheha's maple" or "sugarleaf birch".
|
java.lang.String |
makePlantName(FakeLanguageGen language)
Generates a random possible name for a plant or tree, such as "Ikesheha's maple" or "sugarleaf birch",
with the FakeLanguageGen already available instead of randomly created.
|
java.lang.String |
makePotionDescription()
Generates a random possible description for a potion in a container, such as "a smoky glass flask containing a
few drops of an orange tonic", "a milk carton filled with a red fluid", "a shining silver bottle filled with an
effervescent violet potion", or "a wineskin filled with a black serum".
|
java.lang.String |
makeVegetableName()
Generates a random possible name for a vegetable, such as "miniature yam" or Iliakshe's spicy zucchini".
|
java.lang.String |
makeVegetableName(FakeLanguageGen language)
Generates a random possible name for a vegetable, such as "miniature yam" or Iliakshe's spicy zucchini".
|
static java.lang.String |
numberAdjective(int number)
Gets an English word that describes a numbered position in some sequence, if this knows it (such as "second" or
"eleventh").
|
java.lang.String |
numberAdjectiveInRange(int lowest,
int highest)
Gets an English word that describes a numbered position in some sequence, if this knows it (such as "second" or
"eleventh"), where the number is chosen randomly between lowest and highest, both inclusive.
|
static java.lang.String |
numberWord(int number)
Gets an English word for a given number, if this knows it.
|
java.lang.String |
numberWordInRange(int lowest,
int highest)
Gets an English word for a number, if this knows it, where the number is chosen randomly between lowest and
highest, both inclusive.
|
void |
printCategories(boolean listFormat)
Prints out all of the categories this knows and then all of the terms this knows, optionally using HTML list
formatting.
|
java.lang.String |
process(java.lang.CharSequence text)
Given a String, StringBuilder, or other CharSequence that should contain words this knows synonyms for, this
replaces each occurrence of such a known word with one of its synonyms, leaving unknown words untouched.
|
void |
refresh(int stateA,
int stateB)
Changes the sequences for all groups of synonyms this can produce, effectively turning this Thesaurus into a
different version that knows all the same synonyms and categories but will produce different results.
|
void |
refresh(long state)
Changes the sequences for all groups of synonyms this can produce, effectively turning this Thesaurus into a
different version that knows all the same synonyms and categories but will produce different results.
|
protected static final regexodus.Pattern wordMatch
protected static final regexodus.Pattern similarFinder
public OrderedMap<java.lang.CharSequence,GapShuffler<java.lang.String>> mappings
public java.util.ArrayList<FakeLanguageGen.Alteration> alterations
public SilkRNG rng
protected GapShuffler<java.lang.String> plantTermShuffler
protected GapShuffler<java.lang.String> fruitTermShuffler
protected GapShuffler<java.lang.String> nutTermShuffler
protected GapShuffler<java.lang.String> flowerTermShuffler
protected GapShuffler<java.lang.String> potionTermShuffler
protected GapShuffler<java.lang.String> vegetableTermShuffler
public FakeLanguageGen defaultLanguage
public transient java.util.ArrayList<FakeLanguageGen> randomLanguages
public transient java.lang.String latestGenerated
public static final OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> categories
public static final OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> adjective
public static final OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> noun
public static final OrderedMap<java.lang.String,java.util.ArrayList<java.lang.String>> nouns
public static final OrderedMap<java.lang.CharSequence,FakeLanguageGen> languages
public static final OrderedMap<java.lang.CharSequence,java.lang.Integer> numbers
public static final OrderedMap<java.lang.CharSequence,java.lang.Integer> numberAdjectives
public static Thesaurus ORK
public static Thesaurus ZOMBIE
public Thesaurus()
public Thesaurus(IRNG rng)
rng
- an RNG that will only be used to get one long (for seeding this class' RNG)public Thesaurus(long shuffleSeed)
shuffleSeed
- a long for seeding this class' RNGpublic Thesaurus(java.lang.String shuffleSeed)
shuffleSeed
- a String for seeding this class' RNGpublic void refresh(long state)
state
- any long; will be given to SilkRNG.setState(long)
public void refresh(int stateA, int stateB)
public Thesaurus addReplacement(java.lang.CharSequence before, java.lang.String after)
public Thesaurus addCategory(java.lang.String keyword, java.util.Collection<java.lang.String> synonyms)
`
) so it can't be confused with a "real word," with one of the words in synonyms (chosen in shuffled
order). The backtick is the only punctuation character that this class' word matcher considers part of a word,
both for this reason and because it is rarely used in English text.keyword
- a word (typically containing backticks, `
) that will be replaced by a word from synonymssynonyms
- a Collection of lower-case Strings with similar meaning and the same part of speechpublic void printCategories(boolean listFormat)
listFormat
- if true, this will format the output as an HTML list, otherwise it will be as plain linespublic Thesaurus addKnownCategories()
defaultLanguage
.
See makePlantName()
, makeFruitName()
, makeNutName()
, makeFlowerName()
,
makeVegetableName()
, and makePotionDescription()
for more info and examples.
public Thesaurus addArchivedCategories(java.lang.String archive)
archiveCategories()
(probably from another version of SquidLib), this
makes the Thesaurus class act like it did in that archive, assuming the rng
is seeded the same. This
modifies the mappings
field and the categories
, adjective
, noun
, and
nouns
static fields, so it can affect other Thesaurus objects produced later (it won't change
previously-made ones, probably).
addArchivedCategoriesAlternate(String)
). The files with the correct format for this end in
.squid.txt
. If you save the 3.0.0 .squid.txt
archive in a libGDX application's assets folder, you
can reload the 3.0.0 definitions into a Thesaurus called myThesaurus
with:
myThesaurus.addArchivedCategories(Gdx.files.internal("Thesaurus-3-0-0.squid.txt").readString("UTF-8"));
archive
- an archived String of categories produced by archiveCategories()
public Thesaurus addArchivedCategoriesAlternate(java.lang.String archive)
archiveCategoriesAlternate()
(probably from another version of
SquidLib), this makes the Thesaurus class act like it did in that archive, assuming the rng
is seeded
the same and uses the same algorithm/RandomnessSource. This modifies the mappings
field and the
categories
, adjective
, noun
, and nouns
static fields, so it can affect other
Thesaurus objects produced later (it won't change previously-made ones, probably).
.alt.txt
, while the other format uses .squid.txt
.
If you save the 3.0.0 archive in a libGDX application's assets folder, you can reload the 3.0.0 definitions into
a Thesaurus called myThesaurus
with:
myThesaurus.addArchivedCategoriesAlternate(Gdx.files.internal("Thesaurus-3-0-0.alt.txt").readString("UTF-8"));
archive
- an archived String of categories produced by archiveCategoriesAlternate()
public Thesaurus addFakeWords()
FakeLanguageGen
, just without `pre`
; for instance
"cherokee_romanized`pre`"
corresponds to FakeLanguageGen.CHEROKEE_ROMANIZED
. You can use these
same keywords with `gen`
instead of `pre`
to generate at runtime based on the current RNG state,
instead of using one of several pre-generated words, and doing that does not require addFakeWords() to be used.
public java.lang.String process(java.lang.CharSequence text)
text
- a CharSequence, such as a String, that contains words in the source languagepublic java.lang.String lookup(java.lang.String word)
public java.lang.String makeNationName()
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making nation names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the nation name, like "Drayo" in
"The Last Drayo Commonwealth". If more than one language was used in the nation name, as in "Thùdshù-Hyóttiálb
Hegemony", you will have two languages in randomLanguages, so here "Thùdshù" would be generated by the first
language, and "Hyóttiálb" by the second language. Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can. This also assigns the
latestGenerated
field to contain the part of the nation name without any larger titles; in the case of
"The Glorious Chô Empire", the latestGenerated field would be assigned "Chô" at the same time the longer name
would be returned. This field will be reassigned if this method is called again.public java.lang.String makeNationName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this. This assigns the
latestGenerated
field to contain the part of the nation name without any larger titles; in the case of
"The Glorious Chô Empire", the latestGenerated field would be assigned "Chô" at the same time the longer name
would be returned. This field will be reassigned if this method is called again.
language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makePlantName()
FakeLanguageGen.removeAccents(CharSequence)
, which returns a CharSequence that can be converted
to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the person or place name, like
"Drayo" in "The Last Drayo Commonwealth". Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can.public java.lang.String makePlantName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this.language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makeFruitName()
FakeLanguageGen.removeAccents(CharSequence)
, which returns a CharSequence that can be converted
to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the person or place name, like
"Drayo" in "The Last Drayo Commonwealth". Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can.public java.lang.String makeFruitName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this.language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makeNutName()
FakeLanguageGen.removeAccents(CharSequence)
, which returns a CharSequence that can be converted
to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the person or place name, like
"Drayo" in "The Last Drayo Commonwealth". Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can.public java.lang.String makeNutName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this.language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makeVegetableName()
FakeLanguageGen.removeAccents(CharSequence)
, which returns a CharSequence that can be converted
to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the person or place name, like
"Drayo" in "The Last Drayo Commonwealth". Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can.public java.lang.String makeVegetableName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this.language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makeFlowerName()
FakeLanguageGen.removeAccents(CharSequence)
, which returns a CharSequence that can be converted
to String if needed. Shortly after calling this method, but before
calling it again, you can retrieve the generated random languages, if any were used while making names, by
getting the FakeLanguageGen elements of this class' randomLanguages
field. Using one of these
FakeLanguageGen objects, you can produce many more words with a similar style to the person or place name, like
"Drayo" in "The Last Drayo Commonwealth". Calling this method replaces the current contents of
randomLanguages, so if you want to use those languages, get them while you can.public java.lang.String makeFlowerName(FakeLanguageGen language)
FakeLanguageGen.removeAccents(CharSequence)
, which
returns a CharSequence that can be converted to String if needed, or simply get an accent-less language by
calling FakeLanguageGen.removeAccents()
on the FakeLanguageGen you would give this.language
- a FakeLanguageGen that will be used to construct any non-English namespublic java.lang.String makePotionDescription()
public static java.lang.String numberWord(int number)
number
- the number to get a word forString.valueOf(number)
.public static java.lang.String numberAdjective(int number)
number
- the number to get a position adjective forString.valueOf(number)
followed by a two-char suffix from the last digit.public java.lang.String numberWordInRange(int lowest, int highest)
lowest
- the lower bound for numbers this can choose, inclusivehighest
- the upper bound for numbers this can choose, inclusivepublic java.lang.String numberAdjectiveInRange(int lowest, int highest)
lowest
- the lower bound for numbers this can choose, inclusivehighest
- the upper bound for numbers this can choose, inclusivepublic static java.lang.String archiveCategories()
addArchivedCategories(String)
to
load a set of categories stored from an earlier version of SquidLib.addArchivedCategories(String)
public static java.lang.String archiveCategoriesAlternate()
addArchivedCategoriesAlternate(String)
to load a set of categories stored from an earlier version of
SquidLib, but its intended purpose is to provide a simpler format for archival that doesn't use ObText
.
"\n"
(but
because various OS properties can affect line endings, "\r\n"
must also be handled). Items within the
line are separated by the non-breaking space character, Unicode 00A0. The first item on a line is the key, or the
category name. Remaining items are words the category knows. This may produce a trailing newline.addArchivedCategoriesAlternate(String)
Copyright © Eben Howard 2012–2022. All rights reserved.