Markov Chains and Ticket Updates

Tickets! The bane of every operators existence. "Here take this ticket", "There update that ticket", "Where is the ticket for that work".

I thought it might be fun to wire up a markov chain with some old ticket updates and some funny text and see what we got.

So first things first, data.

Check out my article here to see how to scrape comment data from Jira: https://matthewellsworth.com/interacting-with-the-jira-api/

For the fun of it I grabbed the Project Gutenberg bible from here: http://www.gutenberg.org/ebooks/10

I removed all the cover page text and used sed to remove all of the chapter/verse numbers and blank lines.

We have 2 data sources now jira and the bible, lets wire them all together using the markovify library https://github.com/jsvine/markovify

From here its simple, grab the examples paste them in and update the source files. Here is what I came out with and it seems to work pretty well.

#!/usr/bin/env python

import markovify

# Get raw text as string.
with open("./comment_data") as f:
    text_a = f.read()

with open("./full_bible.txt") as f:
    text_b = f.read()

# Build the model.

model_a = markovify.Text(text_a)
model_b = markovify.Text(text_b)


model_combo = markovify.combine([ model_a, model_b ], [ 2, .1 ])

# Print three randomly-generated sentences of no more than 140 characters
for i in range(10):
    print(model_combo.make_short_sentence(140))

Some of the better examples of generated text:

And the LORD hath redeemed us to use Self signed certificates.

Adding echo statement to allow for a burnt offering

And she spake to the certs cleaning up hostgroups for splunkd and salt-minion processes

Pretty silly, right? Next I think I may start playing around with NLTK (http://www.nltk.org/) to see if I can get more coherent sentences.

See you next time.