Markov Tweet Generator Code, Path, & Potential
[snap url=”http://bionicteaching.com/trials/markov/” alt=”DS106 Markov Tweet Generator” w=”400″ h=”300″ link=”on”]
The following is how I adapted the Markov chain generator from Hay Kranen. Thanks to the comments1 I found below Hay’s post2 this Markov + Shakespeare version inspired me to figure out the “post-to-Twitter” option.3
Anyway, the much cleaner version is up and running. It now allows you to push the results to Twitter although I’m still adjusting this a bit. The code for the page I modified is below. It’s still slower than I’d like but it’ll do for now.
The fact that I can go from a conversation one day to a fairly finished product the next is the piece that amazes me about computers and the Internet. I cannot stress enough that I don’t know how to write PHP. I feel that’s a statement of empowerment. This project took about three hours of work. 95% of that was searching/research and breaking it and then fixing it.4 Someone who knew what they were doing could probably knock it out in ten minutes.
Now how is this more than just random #ds106 amusement? I think the generator works a little like this example about machine imagined artworks5. So there’s a chunk of human constructed meaning from machine assembled pieces. It doesn’t always work but that’s part of why I like having a human layer between generation and Twitter publishing (although I may still automate it when that makes sense time wise). This does generate interesting assignments and juxtaposes them in ways that are similar to the remix assignments idea but with an additional dose of randomness that I like. It also brings older conversations, student products, and links back into the conversation that’s occurring now.
The possibility of the built in @ convention of Twitter has a lot of possibility as well. That element of personalization and specificity could bring people back into the game/course/conversation in ways that reenergize both the participant and the community. There are lots of ways this might be attractive even absent the Markov element. I think there’s value in trying to pull people back into public conversations via methods like this. If participants in a class (MOOC-ish or otherwise) opted in, you could randomly (and judiciously) @ them to engage in conversations around different concepts, posts, products etc. It’d be a balance to avoid being boring and/or spammy but it might be the prompt needed to have a longer term engagement with a course/community.6
License (MIT / X11 license)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Order seems to be the level of chaotic magnitude in the combination from the source. Higher numbers seem to be less disorder.
Length is the number of characters in the returned string.
Text is the path to the text file containing your source data. I did use curl previously to pull directly from a website but found parsing out the html to be problematic.
$order = 6;
$length = 120;
$text = file_get_contents("ds106tweets.txt");
$markov_table = generate_markov_table($text, $order);
$markov = generate_markov_text($length, $markov_table, $order);
if (get_magic_quotes_gpc()) $markov = stripslashes($markov);
Markov Chain DS106 Tweet Text Generator
echo $onetwitter . $tweet . $ender;
1 Comments matter and help stitch together the Internet.
2 which is from 2008 I might add- long tail etc. etc.
3 Note to self and other clueless people, urlencode is just a bit easier way to clean up the text than trying to think through a str_replace. That’s a fairly awesome example of the fact that I have no idea what I’m doing. I only happened across that function (?) by chance on some random StackOverflow post and it was as if the world just fell into place.
4 I consider that testing.
6 You could get all meta-data and create profiles of interest to help algorithmically connect people with posts they might like etc. etc. but that starts to feel a bit different to me.