document.write("<div class=\"pastie\">\n");
document.write("  <link href=\"http://pastie.org/stylesheets/embed.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  <link href=\"http://pastie.org/stylesheets/clean.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n");
document.write("  \n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("\n");
document.write("	\n");
document.write("	<div class=\"allcode\">\n");
document.write("		<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");
document.write("		<tr>\n");
document.write("			<td>\n");
document.write("				\n");
document.write("				<pre class=\"textmate-source-numbers\">1\n");
document.write("2\n");
document.write("3\n");
document.write("4\n");
document.write("5\n");
document.write("6\n");
document.write("7\n");
document.write("8\n");
document.write("9\n");
document.write("10\n");
document.write("11\n");
document.write("12\n");
document.write("13\n");
document.write("14\n");
document.write("15\n");
document.write("16\n");
document.write("17\n");
document.write("18\n");
document.write("19\n");
document.write("20\n");
document.write("21\n");
document.write("22\n");
document.write("23\n");
document.write("24\n");
document.write("25\n");
document.write("26\n");
document.write("27\n");
document.write("28\n");
document.write("29\n");
document.write("30\n");
document.write("31\n");
document.write("32\n");
document.write("33\n");
document.write("34\n");
document.write("35\n");
document.write("36\n");
document.write("37\n");
document.write("38\n");
document.write("39\n");
document.write("40\n");
document.write("41\n");
document.write("42\n");
document.write("43\n");
document.write("44\n");
document.write("45\n");
document.write("46\n");
document.write("47\n");
document.write("48\n");
document.write("49\n");
document.write("50\n");
document.write("51\n");
document.write("52\n");
document.write("53\n");
document.write("<\/pre>\n");
document.write("			<\/td>\n");
document.write("		<td>\n");
document.write("		<pre class=\"textmate-source\"><pre class=\"sunburst\"><span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>#open the bookmarks file (after running it through HTML Tidy<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># first, to transform it into XML)<\/span>\n");
document.write("<span class=\'meta meta_require meta_require_ruby\'><span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>require<\/span> <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;rexml/document&quot;<\/span><\/span>\n");
document.write("file <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>File<\/span>.<span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>new<\/span>( <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;delicious.xhtml&quot;<\/span> )\n");
document.write("doc <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>REXML<\/span>::<span class=\'support support_class support_class_ruby\'>Document<\/span>.<span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>new<\/span> file\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>#create a 2D array: an array of an array<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># of the tags used for each bookmark.<\/span>\n");
document.write("tag_sets <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>Array<\/span>.<span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>new<\/span>()\n");
document.write("doc.elements.each(<span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\'//a\'<\/span>) {|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>e<\/span>| tag_sets.push(e.attributes[<span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\'tags\'<\/span>].split(<span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\',\'<\/span>)) } \n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># I added this following line because I had too many bookmarks,<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># making the graph too big and complicated: -&gt;<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>#      tag_sets = tag_sets.slice(0..10)<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># now flatten the 2D array, and get a 1D array<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># of all the tags used - .uniq gets rid of duplicates<\/span>\n");
document.write("tag_list <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> tag_sets.flatten.uniq         \n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'>#get the relationships<\/span>\n");
document.write("relationships <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>Array<\/span>.<span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>new<\/span>()\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># now iterate through the tag list,<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># and for each tag, look for that in each of the bookmarks.<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># If it\'s found, record a relationship with the other tags of<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># that bookmark<\/span>\n");
document.write("\n");
document.write("tag_list.each <span class=\'keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby\'>do <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>tag<\/span>|\n");
document.write("\n");
document.write(" tag_sets.each <span class=\'keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby\'>do <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>tag_set<\/span>|\n");
document.write("\n");
document.write("   <span class=\'keyword keyword_control keyword_control_ruby\'>if<\/span> tag_set.include? tag\n");
document.write("     tag_set.each <span class=\'keyword keyword_control keyword_control_start-block keyword_control_start-block_ruby\'>do <\/span>|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>related_tag<\/span>|\n");
document.write("     relationships.push([tag, related_tag]) <span class=\'keyword keyword_control keyword_control_ruby\'>if<\/span> tag<span class=\'keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby\'>!=<\/span>related_tag\n");
document.write("     <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("   <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write(" <span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write("<span class=\'keyword keyword_control keyword_control_ruby\'>end<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># relationships is now a 2D array of arrays each<\/span>\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># containing two tags<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># put it into the .dot syntax<\/span>\n");
document.write("\n");
document.write("graph <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;digraph x { <span class=\'constant constant_character constant_character_escape constant_character_escape_ruby\'>\\r<\/span><span class=\'constant constant_character constant_character_escape constant_character_escape_ruby\'>\\n<\/span>&quot;<\/span><span class=\'keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby\'>+<\/span>relationships.uniq.collect{|<span class=\'variable variable_other variable_other_block variable_other_block_ruby\'>r<\/span>|<span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\'&quot;\'<\/span><span class=\'keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby\'>+<\/span>r.join(<span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\'&quot; -&gt; &quot;\'<\/span>)<span class=\'keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby\'>+<\/span><span class=\'string string_quoted string_quoted_single string_quoted_single_ruby\'>\'&quot;;\'<\/span>}.join(<span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;<span class=\'constant constant_character constant_character_escape constant_character_escape_ruby\'>\\r<\/span>&quot;<\/span>)<span class=\'keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby\'>+<\/span><span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;}&quot;<\/span>\n");
document.write("\n");
document.write("<span class=\'comment comment_line comment_line_number-sign comment_line_number-sign_ruby\'># now  write it all into the .dot file<\/span>\n");
document.write("\n");
document.write("file <span class=\'keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby\'>=<\/span> <span class=\'support support_class support_class_ruby\'>File<\/span>.<span class=\'keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby\'>new<\/span>(<span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;delicious_graph.dot&quot;<\/span>, <span class=\'string string_quoted string_quoted_double string_quoted_double_ruby\'>&quot;w&quot;<\/span>)\n");
document.write("file.write(graph)\n");
document.write("file.close()\n");
document.write("<\/pre><\/pre>\n");
document.write("		<\/td>\n");
document.write("		<\/tr>\n");
document.write("		<\/table>\n");
document.write("	\n");
document.write("	<\/div>\n");
document.write("\n");
document.write("\n");
document.write("  \n");
document.write("  \n");
document.write("  <div class=\"credit\">\n");
document.write("    <div class=\"buttons\">\n");
document.write("      <a href=\"http://pastie.org/pastes/987002.txt\">\n");
document.write("      <img src=\"http://pastie.org/images/view.png\" height=\"20\" width=\"67\" /><\/a>\n");
document.write("    <\/div>\n");
document.write("  \n");
document.write("    <a href=\"http://pastie.org/987002\">Pastie #987002<\/a> linked directly from <a href=\"http://pastie.org/\">Pastie<\/a>.\n");
document.write("  <\/div><\/div>");

