{"id":414,"date":"2010-02-19T14:27:56","date_gmt":"2010-02-19T20:27:56","guid":{"rendered":"http:\/\/www.tamarziv.com\/itp\/?p=414"},"modified":"2010-02-20T08:26:45","modified_gmt":"2010-02-20T14:26:45","slug":"barney-is-down","status":"publish","type":"post","link":"https:\/\/www.tamarziv.com\/itp\/barney-is-down\/","title":{"rendered":"W4-Barney is dead"},"content":{"rendered":"<blockquote><p>I with you<br \/>\nYou mood me<br \/>\ndeath a drawn sleep,<br \/>\nthan a death big hug<br \/>\nand a than with me to some<br \/>\nleast you say you have me too <\/p><\/blockquote>\n<p><\/br><br \/>\n<\/br><\/p>\n<blockquote><p>I which you<br \/>\nYou which me<br \/>\nnearly a making persist<br \/>\nareas a either big hug<br \/>\nand a &#8220;down &#8220;down me to death<br \/>\nsleep, you say you every me too <\/p><\/blockquote>\n<p><\/br><br \/>\n<\/br><\/p>\n<blockquote><p>being when<br \/>\nfrom every<br \/>\nhaving weight amount,<br \/>\nsleep person loss mood<br \/>\nwhen Major other loss<br \/>\nnearly lose when with abuse Many <\/p><\/blockquote>\n<p><\/br><br \/>\n<\/br><\/p>\n<blockquote><p>\nI being they<br \/>\nwith twice can<br \/>\nplays, a think, colitis<br \/>\ngains a person lose when<br \/>\nwhen a noted being may and they<br \/>\nabate. that with make prior for with <\/p><\/blockquote>\n<p><\/br><br \/>\n<\/br><\/p>\n<p><strong>Program does:<\/strong> My program this week is based on alpha_replace and attempts to exploit the absurd innocence of <a href=\"http:\/\/www.stlyrics.com\/songs\/d\/disney6472\/iloveyoubarney511798.html\" target=\"new\">Barney<\/a>, and cross it over with a dictionary built out of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Diagnostic_and_Statistical_Manual_of_Mental_Disorders\" target=\"new\">DSM-IV<\/a> section regarding major depression. <\/p>\n<p><strong>Program gets:<\/strong> input from an OCR version of the DSM chapter, breaks it into dictionary entries according to the number of letters in each word as keys, each key is assigned a list of words of the set key&#8217;s length. The program also reads in a file <\/p>\n<p><strong>Program outputs:<\/strong> and replaces words from the original song which are more than 2 characters long with those from the dictionary (the word taken from the dictionary is one character longer than the source word) and prints out a morbid ditty as an output. Filtering is performed on the values in the dictionary to remove frequently used words such as &#8220;Major&#8221;, due to the capricious nature of the OCR translation, further filtering is needed to remove the OCR&#8217;s faulty translation and other characters and sections mentioned in the text that impair the poetic nature of the outcome, regular expressions would probably help here&#8230; <\/p>\n<p><strong>What is does not do:<\/strong> is manage to bring out enough of the barniesque into the end result, thus not really achieving it&#8217;s goal, it would take some more precision in the selection process on the string level, rather than just using a random method, in fact, most of the poems this code generate are useless at the moment, hopefully I&#8217;ll manage improving on that in the future. The biggest challenge in this however, was the attempt to exclude specific strings off the list of each key&#8217;s value, that was a partial success since I didn&#8217;t manage excluding substrings, only full words within the list. <\/p>\n<p><\/br><br \/>\n<\/br><\/p>\n<div class=\"codecolorer-container python default\" style=\"overflow:auto;white-space:nowrap;width:648px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"kw1\">import<\/span> <span class=\"kw3\">sys<\/span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># builds dictionary from source text, and replaces words from a different text which start with the same letter<\/span><br \/>\n<span class=\"kw1\">import<\/span> <span class=\"kw3\">random<\/span><br \/>\n<br \/>\nsource_len <span class=\"sy0\">=<\/span> <span class=\"kw2\">dict<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># python len_replace8.py major_dep.txt &lt; barney.txt <\/span><br \/>\nsource_file <span class=\"sy0\">=<\/span> <span class=\"kw3\">sys<\/span>.<span class=\"me1\">argv<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># first argument passed on command line, sys.argv[0] will be the name of the script file<\/span><br \/>\n<br \/>\nignoreList <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;)&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;Major&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">&quot;major&quot;<\/span><span class=\"br0\">&#93;<\/span><br \/>\nignoreIndex <span class=\"sy0\">=<\/span> <span class=\"kw2\">int<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\nignoreIndex <span class=\"sy0\">=<\/span> <span class=\"nu0\">0<\/span><br \/>\n<br \/>\n<br \/>\n<span class=\"co1\"># read each line from source file; split each line into words; store each<\/span><br \/>\n<span class=\"co1\"># word in the source_alpha dictionary, according to which letter it starts with<\/span><br \/>\n<span class=\"kw1\">for<\/span> line <span class=\"kw1\">in<\/span> <span class=\"kw2\">open<\/span><span class=\"br0\">&#40;<\/span>source_file<span class=\"br0\">&#41;<\/span>: &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; <span class=\"co1\"># reading lines from major_dep.txt<\/span><br \/>\n&nbsp; &nbsp; line <span class=\"sy0\">=<\/span> line.<span class=\"me1\">strip<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">for<\/span> thing <span class=\"kw1\">in<\/span> ignoreList:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> thing <span class=\"kw1\">not<\/span> <span class=\"kw1\">in<\/span> line:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; words <span class=\"sy0\">=<\/span> line.<span class=\"me1\">split<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot; &quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">for<\/span> word <span class=\"kw1\">in<\/span> words:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># loops through each of the words &nbsp; &nbsp; &nbsp; <\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"kw2\">len<\/span><span class=\"br0\">&#40;<\/span>word<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"nu0\">2<\/span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># check to make sure we have a large word<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lengthWord <span class=\"sy0\">=<\/span> <span class=\"kw2\">len<\/span><span class=\"br0\">&#40;<\/span>word<span class=\"br0\">&#41;<\/span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># get first letter of word<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># if we've already seen this number, append to list<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> lengthWord <span class=\"kw1\">in<\/span> source_len: &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_len<span class=\"br0\">&#91;<\/span>lengthWord<span class=\"br0\">&#93;<\/span>.<span class=\"me1\">append<\/span><span class=\"br0\">&#40;<\/span>word<span class=\"br0\">&#41;<\/span> <span class=\"co1\"># append word to the value of that letter<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">else<\/span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># looks like {'3':['the','big']...}<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_len<span class=\"br0\">&#91;<\/span>lengthWord<span class=\"br0\">&#93;<\/span> <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span>word<span class=\"br0\">&#93;<\/span> &nbsp; &nbsp; <span class=\"co1\"># specify that a new list is made<\/span><br \/>\n<br \/>\n<span class=\"co1\"># source_alpha will be a dictionary whose keys are strings and whose values<\/span><br \/>\n<span class=\"co1\"># are lists.<\/span><br \/>\n<span class=\"co1\"># uncomment this to see what the data structure created above looks like<\/span><br \/>\n<span class=\"co1\">#print source_alpha<\/span><br \/>\n<br \/>\n<span class=\"co1\"># read each line from standard input; split line into words; for each word,<\/span><br \/>\n<span class=\"co1\"># get a random word beginning with the same letter from source_alpha<\/span><br \/>\n<span class=\"kw1\">for<\/span> line <span class=\"kw1\">in<\/span> <span class=\"kw3\">sys<\/span>.<span class=\"me1\">stdin<\/span>:<br \/>\n&nbsp; line <span class=\"sy0\">=<\/span> line.<span class=\"me1\">strip<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; words <span class=\"sy0\">=<\/span> line.<span class=\"me1\">split<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot; &quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; output <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&quot;<\/span><br \/>\n&nbsp; <span class=\"kw1\">for<\/span> word <span class=\"kw1\">in<\/span> words:<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"kw2\">len<\/span><span class=\"br0\">&#40;<\/span>word<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"nu0\">0<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; lengthWord <span class=\"sy0\">=<\/span> <span class=\"kw2\">len<\/span><span class=\"br0\">&#40;<\/span>word<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> lengthWord <span class=\"kw1\">in<\/span> source_len:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> lengthWord <span class=\"sy0\">&gt;<\/span> <span class=\"nu0\">2<\/span>: &nbsp; <span class=\"co1\"># only replace words with more than 2 chars (preserve some of the original structure)<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source_words <span class=\"sy0\">=<\/span> source_len<span class=\"br0\">&#91;<\/span>lengthWord+<span class=\"nu0\">1<\/span><span class=\"br0\">&#93;<\/span> &nbsp;<span class=\"co1\"># output a value a char longer than the original<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output +<span class=\"sy0\">=<\/span> <span class=\"kw3\">random<\/span>.<span class=\"me1\">choice<\/span><span class=\"br0\">&#40;<\/span>source_words<span class=\"br0\">&#41;<\/span> &nbsp; &nbsp; <span class=\"co1\"># randomly choose a string from the value list<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">else<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output +<span class=\"sy0\">=<\/span> word<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; output +<span class=\"sy0\">=<\/span> <span class=\"st0\">&quot; &quot;<\/span><br \/>\n&nbsp; <span class=\"kw1\">print<\/span> output<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<blockquote><p>I with you<br \/>\nYou mood me<br \/>\ndeath a drawn sleep,<br \/>\nthan a death big hug<br \/>\nand a than with me to some<br \/>\nleast you say you have me too\n<\/p><\/blockquote>\n<p>My program this week is based on alpha_replace and attempts to exploit the absurd innocence of <a href=\"http:\/\/www.stlyrics.com\/songs\/d\/disney6472\/iloveyoubarney511798.html\" target=\"new\">Barney<\/a>, and cross it over with a dictionary built out of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Diagnostic_and_Statistical_Manual_of_Mental_Disorders\" target=\"new\">DSM-IV<\/a> section regarding major depression. <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-414","post","type-post","status-publish","format-standard","hentry","category-rwet","avhec_catgroup-all"],"_links":{"self":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/comments?post=414"}],"version-history":[{"count":19,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":433,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/posts\/414\/revisions\/433"}],"wp:attachment":[{"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tamarziv.com\/itp\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}