Mangled source
The structure channeled
O O O mourning, I walk my parlor floor,
At him here, and Beneath the vernal moon-o-oh, I walk my parlor floor,
When the hours of day appeared, And the long-disused, dismantled youth,
friends! friends! friends! Until I find release;
I sit upon the sands alone; fleeing all discreet,
in me, me, me, me, me.
O O O mourning, I walk my parlor floor,
At him here, and Beneath the vernal moon-o-oh, I walk my parlor floor,
From all that curses yonder bound! And long-dismantled youth,
friends! friends! friends! before I get dismissed;
I sit upon the sands alone; fleeing all a void,
in me, me, me, me, me.
O O O mourning, I walk my parlor floor,
At him here, and Beneath the vernal moon-o-oh, I walk my parlor floor,
From all that curses yonder! She battled underneath,
friends! friends! friends! I shall not be too soon;
I sit upon the sands alone, before I am released,
of me, me, me, me, me.
ha ha hammer, ha ha ha ha hammer ha, I walk my parlor floor,
ha ha hammer, ha ha ha ha hammer ha, I walk my parlor floor,
ha ha hammer, ha ha ha ha hammer ha, I walk my parlor floor,
ha ha hammer, ha ha ha ha hammer ha, I walk my parlor floor,
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | # Anon class is used to get rid of poem titles, authors and comments import sys # builds dictionary from source text, and replaces words from a different text which start with the same letter import random import re # use regular expressions import markov #source_file = sys.argv[1] # first argument passed on command line, sys.argv[0] will be the name of the script file # Break the text into lines # filter out unwanted content # globals I_Lines = dict() dict_lines = dict() linecount = 255 oh_list = list() no_list = list() bamp_list = list() hurry_list = list() before_I = list() def clean_text(raw_text): # create a dict of markoved text clean_text = "" n = 2 mark2 = markov.MarkovGenerator(n, 14000) #create a markov object for line in raw_text: # reading lines from txt line = line.strip() line = re.sub(r".+[A-Z]+(\.|\."|\?)$",'', line) # get rid of titles line = re.sub(r"^\s*(\S+|\S\b\S)$", '', line) # get rid of short lines line = re.sub(r"(\:|\?|\?")$|^\(|\)$|\]$", '', line) # get rid of questions and colons etc. line = re.sub(r"^\(.+\).{,1}$", '', line) # get rid of bracketed lines line = re.sub(r"^.{,2}\.$", '', line) # get rid of numbering line = re.sub(r"^I'm\b", '', line) # get rid of numbering line = re.sub(r"\b\*\b", '', line) # get rid of * templine = line if re.search(r'\b[Bb]efore I\b.+$', templine): offset = line.find(" before") if offset != -1: before_I.append(templine[offset+1:]) tempword = line.split(" ") for i in tempword: # get lists for oh-no if re.search(r'\b\w[aeiou]\b', i): no_list.append(i) if re.search(r'\b\w[aeiou]\w\w\b', i): bamp_list.append(i) if re.search(r"\b[aeiou]\w\b", i): oh_list.append(i) if re.search(r'\b\w+[!]', i): hurry_list.append(i) if not line.strip(): # get rid of empty lines continue else: mark2.feed(line) for i in range(linecount): #sort by length makeMarkovs = mark2.generate() temp_line = makeMarkovs words = temp_line.split(" ") counter = len(words) if counter in dict_lines: # set keys and values dict_lines[counter].append(temp_line) # append word to the value of that number else: # looks like {'3':['the','big']...} dict_lines[counter] = [temp_line] return dict_lines def i_text(clean_text): # Dict of lines starting with I I_lines = "" n = 2 mark = markov.MarkovGenerator(n, 14000) #create a markov object for line in clean_text: # reading lines from txt #mark.feed(line) line = line.strip() line = re.sub(r".+[A-Z]+(\.|\."|\?)$",'', line) # get rid of titles line = re.sub(r"^\s*(\S+|\S\b\S)$", '', line) # get rid of short lines line = re.sub(r"(\:|\?|\?")$|^\(|\)$|\]$", '', line) # get rid of questions and colons etc. line = re.sub(r"^\(.+\).{,1}$", '', line) # get rid of bracketed lines line = re.sub(r"^.{,2}\.$", '', line) # get rid of numbering line = re.sub(r"^I'm\b", '', line) # get rid of numbering line = re.sub(r"\b\*\b", '', line) # get rid of * if re.search(r'^I\b\s\b.+', line): mark.feed(line) for i in range(linecount): # create a dict off the markov results makeMarkovs = mark.generate() temp_line = makeMarkovs words = temp_line.split(" ") counter = len(words) if counter in I_Lines: I_Lines[counter].append(temp_line) # append word to the value of that number else: # looks like {'3':['the','big']...} I_Lines[counter] = [temp_line] return I_Lines # return def get_lines_from_file(filename): raw_text = open(filename) return raw_text #run the functions lines_from_file = get_lines_from_file("WBP-III_edit.txt") I_lines_from_file = get_lines_from_file("WBP-III_edit.txt") clean = clean_text(lines_from_file) i_sentences = i_text(I_lines_from_file) # debugging station: #print dict_lines #print I_Lines #print no #print oh #print before_I #print twenty #print four_hours_to_go #print hurry_list # variables four_hours_to_go = "" twenty = "" to_go = random.choice(dict_lines[3]) to_go_words = to_go.split(" ") twenty = to_go_words[0] offset = len(twenty) four_hours_to_go = to_go[offset:6] bamp = random.choice(bamp_list) ba = bamp[0:2] # more variables I_wanna_be_sedated = random.choice(I_Lines[5]) Twenty_twenty_twenty_four_hours_to_go = twenty+" "+twenty+" "+twenty+" "+four_hours_to_go Nothin_to_do = random.choice(dict_lines[3]) no_where_to_go = random.choice(dict_lines[4]) Just_get_me_to_the_airport = random.choice(dict_lines[6]) put_me_on_a_plane = random.choice(dict_lines[5]) hurry = random.choice(hurry_list) before_I_go_insane = random.choice(before_I) I_cant_control_my_fingers = random.choice(I_Lines[6]) I_cant_control_my_brain = random.choice(I_Lines[6]) oh = random.choice(oh_list) no = random.choice(no_list) Just_put_me_in_a_wheelchair = random.choice(dict_lines[6]) get_me_to_the_show = random.choice(dict_lines[5]) I_gotta_go = random.choice(I_Lines[4]) I_cant_control_my_toes = random.choice(I_Lines[6]) Ba_ba_bamp_ba = ba+" "+ba+" "+bamp+" "+ba ba_ba_ba_bamp_ba = ba+" "+ba+" "+ba+" "+bamp+" "+ba # Hey ho let's go ! print Twenty_twenty_twenty_four_hours_to_go +" "+ I_wanna_be_sedated print Nothin_to_do + " and " + no_where_to_go +"-o-oh "+ I_wanna_be_sedated print Just_get_me_to_the_airport +" " + put_me_on_a_plane print hurry+" "+hurry+" "+hurry + " " + before_I_go_insane print I_cant_control_my_fingers + " " + I_cant_control_my_brain print oh + " " + no + " " + no + " " + no + " " + no + " " + no print "\n" print Twenty_twenty_twenty_four_hours_to_go +" "+ I_wanna_be_sedated print Nothin_to_do + " and " + no_where_to_go +"-o-oh "+ I_wanna_be_sedated print Just_put_me_in_a_wheelchair + " and " + put_me_on_a_plane print hurry+" "+hurry+" "+hurry + " " + before_I_go_insane print I_cant_control_my_fingers + " " + I_cant_control_my_brain print oh + " " + no + " " + no + " " + no + " " + no + " " + no print "\n" print Twenty_twenty_twenty_four_hours_to_go +" "+ I_wanna_be_sedated print Nothin_to_do + " and " + no_where_to_go +"-o-oh "+ I_wanna_be_sedated print Just_put_me_in_a_wheelchair + " " + get_me_to_the_show print hurry+" "+hurry+" "+hurry + " " + I_gotta_go print I_cant_control_my_fingers + " " + I_cant_control_my_toes print oh + " " + no + " " + no + " " + no + " " + no + " " + no print "\n" print Ba_ba_bamp_ba + " " + ba_ba_ba_bamp_ba +" "+ I_wanna_be_sedated print Ba_ba_bamp_ba + " " + ba_ba_ba_bamp_ba +" "+ I_wanna_be_sedated print Ba_ba_bamp_ba + " " + ba_ba_ba_bamp_ba +" "+ I_wanna_be_sedated print Ba_ba_bamp_ba + " " + ba_ba_ba_bamp_ba +" "+ I_wanna_be_sedated |