Section: Two algorithms that generateprobabilistic text(new Assignment)

Probabilistic Text Generation with a List<Character

Warmup: Create three characters of random text when the randomly selected initial nGram is "the".Use the "random"list indexes of 2, 1, and 0.

"We see the same over there, where three of these were not the same as these three over here."

Firstcreate the list of all characters that follow "the"

followerso-> [' ', 'r', 's', ' ', 's']At randomly selected index 2, append 's'

The new seed becomes "hes"(remove first char, add char just printed)

followerso-> [ ______] At randomly selected index 1, append ____?

The new seed becomes "____" (remove first char, add char just printed)

followerso-> [______]At randomly selected index 0, append ____?

The random text: "s _ _ "

TODO in teams of 2: Using the same text as above, create a random string of length 4 when the randomly selected nGram is "he". This time use"random"list indexes3, 2, 1, 0.

The random text? "_ _ _ _"

Compare answers. They all should actually be the same four characters

Probabilistic Text Generation with a hash map

When using a map, first create all possible mappings. The keys are every possible nGram of the given length. The valuesare an ArrayList<Character>() that contains every char that follows that nGram key. This uses more memory but is faster because we can get the list of following characters O(1) rather than scanning the entire text for each characterprinted.For example, using the input text of"Alice likes icy olives", the following table contains all mappings where there nGram length of 2. The value mapped to each of these nGramsis the list of all characters that follow that nGram in the input text.

Example text: "Alice likes icy olives"

Key / Value: ArrayList<Character>()
"Al" / ['i']
"li" / ['c', 'k', 'v'] 'k' and 'v' were added later
"ic" / ['e', 'y']
"ce" / [' ']
"e " / ['l']
" l" / ['i']
"li" / "li" is already a key, add follower 'k' to the list already mapped to the key "li"
"ik" / ['e']
"ke" / ['s']
"es" / [' ']
"s " / [i]
" i" / [c]
"ic" / "ic" is already a key, add follower 'k' to the list already mapped to the key "ic"
"cy" / [' ']
"y " / ['o']
" o" / ['l']
"ol" / ['o']
"li" / "li" is already a key, add follower 'v' to the list already mapped to the key "li"
"ve" / ['s'] Stop one possible seed short to avoid a StringIndexOutOfBoundException

TODO in teams of 2: Using the input text "the true try the truths", first complete a table ofhash mapkeys and values when the nGram length is 2. Begin at the first possible nGram and stop one character short (nothing follows "s."). The first twonGrams and their first found followers are shown. The first keywill always be the first nGram lengthcharacters in the input.

the true try the truths.

Key / Value: ArrayList<Character>()
"th" / ['e',
"he" / ['',

TODO in teams of 2:Using the mappings above, walk through generating 4 probabilistic characters with an initial nGram randomly chosen (you pick it)using 4 random indexes in the range of 0..list.size()-1 that you select.

The random text? "_ _ _ _"

Compare answers. They are probably different