dev-master
9999999-dev https://github.com/andreskrey/ShittyMarkovGeneratorA shitty implementation to generate Markov chains to create incoherent phrases.
by Andres Rey
markov
A shitty implementation to generate Markov chains to create incoherent phrases.
If you take a text, explode it, and then inspect the words, you'll see that some words appear more often next to some other words. Sometimes words appear next to each other rarely. If you explore that relations and assign a score to each relation, you can use this information to create phrases that will have a correct structure and, hopefully, some meaning. This exploration task is, in a super simplified way, Markov chains., (*1)
This project will create phrases based on the texts that you feed it. In a way, the bigger the text, the "smarter" the phrase it will generate., (*2)
When you feed a text to the Chainer function, it will explode all the words and create a dictionary, assigning a specific score to each word and the next one, based on repetition., (*3)
Then it will output a phrase based on that dictionary. You can select the chain size (lenght of the phrase), the topic (it will try to match the topic you define with a word in the dictionary and start the phrase from there) and the block size (the way the dictionary will be constructed)., (*4)
You can use it either by CLI or as a dependency. Download the project and use composer install
to generate the
autoloader., (*5)
Otherwise just run it by CLI., (*6)
php chainer.php -r /path/to/your/text
, (*7)
The example text can be anything. Just make sure it's long enough to create interesting phrases., (*8)
What I like about my project is that it doesn't select words randomly. The other projects I saw, selected the word from
the pool with a random function. In this project, words are selected by chances. When the dictionary is constructed, a score
is assigned to the following possible word. At the moment of selecting a new word, if there is more than one option,
those options will be selected by random, but those words that naturally have more chances to appear next to the
selected one will be selected more often. Check the createChances
function on the markovBot file to understand it better., (*9)
It also tries to end the phrase in a punctuation mark. This doesn't work perfectly, but given the right conditions, it
will give you a phrase that ends in !
, .
or ?
., (*10)
This project is heavily based on the markov-php project by heidilabs., (*11)
A shitty implementation to generate Markov chains to create incoherent phrases.
markov