A terrible markov chain engine for generating tweets
-
Assuming a sentence has n words.
-
Two Arrays (Dictionaries)
- Contains
word[0]
with all possibleword[1]
. - Contains
word[1:n]
with all possibleword[x+1]
.
- Contains
-
Python allows arrays within arrays
{'Word[0]': ['Word[1]', 'Word[1]', 'Word[1]']}
{'Word[x]': ['Word[x+1]', 'Word[x+1]']}
- Array can be accessed recursively
-
Randomly select
word[0]
.- Known as the ‘key’
- Key is chosen at random to start the chain
-
Randomly select
word[1]
based onword[0]
. -
Randomly select
word[x]
until:word[x]
has noword[x+1]
.- Typically a word with a full stop.
-
[1] zirak (2013) http://blog.javascriptroom.com/2013/01/21/markov-chains/
-
[2] Vivin Paliath (2010) https://stackoverflow.com/questions/4081662/explain-markov-chain-algorithm-in-laymans-terms