You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

766 lines
34 KiB
Plaintext

4 years ago
{
"cells": [
4 years ago
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tales to tell\n",
"\n",
"module: [graphviz](https://graphviz.readthedocs.io/en/stable/)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 2,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"from graphviz import Digraph"
]
},
4 years ago
{
"cell_type": "code",
4 years ago
"execution_count": 3,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"dot = Digraph()"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 4,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"# Add nodes 1 and 2\n",
"dot.node('1')\n",
"dot.node('2')\n",
"\n",
"# Add edge between 1 and 2\n",
"dot.edges(['12'])"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 5,
4 years ago
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"62pt\" height=\"116pt\"\n",
" viewBox=\"0.00 0.00 62.00 116.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-112 58,-112 58,4 -4,4\"/>\n",
"<!-- 1 -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"27\" cy=\"-90\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"27\" y=\"-86.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"27\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"27\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M27,-71.8314C27,-64.131 27,-54.9743 27,-46.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"30.5001,-46.4132 27,-36.4133 23.5001,-46.4133 30.5001,-46.4132\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
4 years ago
"<graphviz.dot.Digraph at 0x7f8c94ff4dd8>"
4 years ago
]
},
4 years ago
"execution_count": 5,
4 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot"
]
},
4 years ago
{
"cell_type": "code",
4 years ago
"execution_count": 6,
4 years ago
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"text = \"\"\"I have a tale to tell\n",
"Sometimes it gets so hard to hide it well\n",
"I was not ready for the fall\n",
"Too blind to see the writing on the wall\"\"\""
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 7,
4 years ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I\n",
"have\n",
"a\n",
"tale\n",
"to\n",
"tell\n",
"Sometimes\n",
"it\n",
"gets\n",
"so\n",
"hard\n",
"to\n",
"hide\n",
"it\n",
"well\n",
"I\n",
"was\n",
"not\n",
"ready\n",
"for\n",
"the\n",
"fall\n",
"Too\n",
"blind\n",
"to\n",
"see\n",
"the\n",
"writing\n",
"on\n",
"the\n",
"wall\n"
]
}
],
"source": [
"for word in text.split():\n",
" print (word)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://docs.python.org/3/library/itertools.html#recipes"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 8,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"from itertools import tee\n",
"def pairwise(iterable):\n",
" \"s -> (s0,s1), (s1,s2), (s2, s3), ...\"\n",
" a, b = tee(iterable)\n",
" next(b, None)\n",
" return zip(a, b)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 9,
4 years ago
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I have\n",
"have a\n",
"a tale\n",
"tale to\n",
"to tell\n",
"tell Sometimes\n",
"Sometimes it\n",
"it gets\n",
"gets so\n",
"so hard\n",
"hard to\n",
"to hide\n",
"hide it\n",
"it well\n",
"well I\n",
"I was\n",
"was not\n",
"not ready\n",
"ready for\n",
"for the\n",
"the fall\n",
"fall Too\n",
"Too blind\n",
"blind to\n",
"to see\n",
"see the\n",
"the writing\n",
"writing on\n",
"on the\n",
"the wall\n"
]
}
],
"source": [
"for w1, w2 in pairwise(text.split()):\n",
" print (w1, w2)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 10,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"for w1, w2 in pairwise(text.split()):\n",
" dot.edge(w1, w2)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 11,
4 years ago
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"603pt\" height=\"764pt\"\n",
" viewBox=\"0.00 0.00 603.00 764.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 760)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-760 599,-760 599,4 -4,4\"/>\n",
4 years ago
"<!-- 1 -->\n",
4 years ago
"<g id=\"node1\" class=\"node\">\n",
4 years ago
"<title>1</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"143\" cy=\"-738\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"143\" y=\"-734.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"143\" cy=\"-666\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"143\" y=\"-662.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M143,-719.8314C143,-712.131 143,-702.9743 143,-694.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"146.5001,-694.4132 143,-684.4133 139.5001,-694.4133 146.5001,-694.4132\"/>\n",
"</g>\n",
"<!-- I -->\n",
"<g id=\"node3\" class=\"node\">\n",
4 years ago
"<title>I</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"298\" cy=\"-738\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"298\" y=\"-734.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">I</text>\n",
"</g>\n",
"<!-- have -->\n",
4 years ago
"<g id=\"node4\" class=\"node\">\n",
4 years ago
"<title>have</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"220\" cy=\"-666\" rx=\"32.4942\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"220\" y=\"-662.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">have</text>\n",
"</g>\n",
"<!-- I&#45;&gt;have -->\n",
4 years ago
"<g id=\"edge2\" class=\"edge\">\n",
4 years ago
"<title>I&#45;&gt;have</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M281.8383,-723.0816C271.0767,-713.1477 256.7328,-699.9072 244.5692,-688.6793\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"246.6724,-685.8575 236.9504,-681.6465 241.9244,-691.0012 246.6724,-685.8575\"/>\n",
"</g>\n",
"<!-- was -->\n",
4 years ago
"<g id=\"node16\" class=\"node\">\n",
4 years ago
"<title>was</title>\n",
4 years ago
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"364\" cy=\"-666\" rx=\"28.6953\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"364\" y=\"-662.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">was</text>\n",
4 years ago
"</g>\n",
"<!-- I&#45;&gt;was -->\n",
4 years ago
"<g id=\"edge17\" class=\"edge\">\n",
4 years ago
"<title>I&#45;&gt;was</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M312.321,-722.3771C321.2292,-712.659 332.8452,-699.987 342.8075,-689.1191\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"345.5297,-691.3291 349.7069,-681.5924 340.3696,-686.599 345.5297,-691.3291\"/>\n",
4 years ago
"</g>\n",
"<!-- a -->\n",
4 years ago
"<g id=\"node5\" class=\"node\">\n",
4 years ago
"<title>a</title>\n",
4 years ago
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"211\" cy=\"-594\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"211\" y=\"-590.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">a</text>\n",
4 years ago
"</g>\n",
"<!-- have&#45;&gt;a -->\n",
4 years ago
"<g id=\"edge3\" class=\"edge\">\n",
4 years ago
"<title>have&#45;&gt;a</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M217.7289,-647.8314C216.7664,-640.131 215.6218,-630.9743 214.5521,-622.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"218.0151,-621.9019 213.3017,-612.4133 211.0691,-622.7702 218.0151,-621.9019\"/>\n",
4 years ago
"</g>\n",
"<!-- tale -->\n",
4 years ago
"<g id=\"node6\" class=\"node\">\n",
4 years ago
"<title>tale</title>\n",
4 years ago
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"141\" cy=\"-522\" rx=\"28.6953\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"141\" y=\"-518.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">tale</text>\n",
4 years ago
"</g>\n",
"<!-- a&#45;&gt;tale -->\n",
4 years ago
"<g id=\"edge4\" class=\"edge\">\n",
4 years ago
"<title>a&#45;&gt;tale</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M196.1548,-578.7307C186.6334,-568.9372 174.0931,-556.0387 163.3763,-545.0156\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"165.788,-542.4753 156.3077,-537.7451 160.769,-547.3548 165.788,-542.4753\"/>\n",
4 years ago
"</g>\n",
"<!-- to -->\n",
4 years ago
"<g id=\"node7\" class=\"node\">\n",
4 years ago
"<title>to</title>\n",
4 years ago
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"134\" cy=\"-450\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"134\" y=\"-446.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">to</text>\n",
4 years ago
"</g>\n",
"<!-- tale&#45;&gt;to -->\n",
4 years ago
"<g id=\"edge5\" class=\"edge\">\n",
4 years ago
"<title>tale&#45;&gt;to</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M139.2336,-503.8314C138.485,-496.131 137.5947,-486.9743 136.7627,-478.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"140.2415,-478.0276 135.7902,-468.4133 133.2744,-478.7051 140.2415,-478.0276\"/>\n",
4 years ago
"</g>\n",
"<!-- tell -->\n",
4 years ago
"<g id=\"node8\" class=\"node\">\n",
4 years ago
"<title>tell</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"157\" cy=\"-378\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"157\" y=\"-374.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">tell</text>\n",
"</g>\n",
"<!-- to&#45;&gt;tell -->\n",
4 years ago
"<g id=\"edge6\" class=\"edge\">\n",
4 years ago
"<title>to&#45;&gt;tell</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M139.6854,-432.2022C142.2563,-424.1541 145.3534,-414.4588 148.2132,-405.5067\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"151.5913,-406.4334 151.3003,-395.8425 144.9232,-404.3033 151.5913,-406.4334\"/>\n",
4 years ago
"</g>\n",
"<!-- hide -->\n",
4 years ago
"<g id=\"node14\" class=\"node\">\n",
4 years ago
"<title>hide</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"97\" cy=\"-306\" rx=\"30.5947\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"97\" y=\"-302.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">hide</text>\n",
"</g>\n",
"<!-- to&#45;&gt;hide -->\n",
4 years ago
"<g id=\"edge13\" class=\"edge\">\n",
4 years ago
"<title>to&#45;&gt;hide</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M129.3887,-432.0535C123.074,-407.4774 111.6717,-363.1008 104.2195,-334.0974\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"107.5479,-332.9871 101.6694,-324.1727 100.7682,-334.7291 107.5479,-332.9871\"/>\n",
4 years ago
"</g>\n",
"<!-- see -->\n",
4 years ago
"<g id=\"node24\" class=\"node\">\n",
4 years ago
"<title>see</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"238\" cy=\"-378\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"238\" y=\"-374.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">see</text>\n",
"</g>\n",
"<!-- to&#45;&gt;see -->\n",
4 years ago
"<g id=\"edge26\" class=\"edge\">\n",
4 years ago
"<title>to&#45;&gt;see</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M153.0752,-436.7941C169.2013,-425.6298 192.5041,-409.4971 210.6221,-396.9539\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"212.816,-399.692 219.0457,-391.1222 208.8315,-393.9367 212.816,-399.692\"/>\n",
4 years ago
"</g>\n",
"<!-- Sometimes -->\n",
4 years ago
"<g id=\"node9\" class=\"node\">\n",
4 years ago
"<title>Sometimes</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"208\" cy=\"-306\" rx=\"62.2891\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"208\" y=\"-302.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">Sometimes</text>\n",
"</g>\n",
"<!-- tell&#45;&gt;Sometimes -->\n",
4 years ago
"<g id=\"edge7\" class=\"edge\">\n",
4 years ago
"<title>tell&#45;&gt;Sometimes</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M168.5727,-361.6621C174.7554,-352.9336 182.5138,-341.9805 189.5092,-332.1047\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"192.4773,-333.9695 195.4014,-323.7862 186.7651,-329.9234 192.4773,-333.9695\"/>\n",
"</g>\n",
"<!-- it -->\n",
4 years ago
"<g id=\"node10\" class=\"node\">\n",
4 years ago
"<title>it</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"204\" cy=\"-234\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"204\" y=\"-230.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">it</text>\n",
"</g>\n",
"<!-- Sometimes&#45;&gt;it -->\n",
4 years ago
"<g id=\"edge8\" class=\"edge\">\n",
4 years ago
"<title>Sometimes&#45;&gt;it</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M206.9906,-287.8314C206.5628,-280.131 206.0541,-270.9743 205.5787,-262.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"209.0724,-262.2037 205.023,-252.4133 202.0831,-262.592 209.0724,-262.2037\"/>\n",
"</g>\n",
"<!-- gets -->\n",
4 years ago
"<g id=\"node11\" class=\"node\">\n",
4 years ago
"<title>gets</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"194\" cy=\"-162\" rx=\"30.5947\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"194\" y=\"-158.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">gets</text>\n",
"</g>\n",
"<!-- it&#45;&gt;gets -->\n",
4 years ago
"<g id=\"edge9\" class=\"edge\">\n",
4 years ago
"<title>it&#45;&gt;gets</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M201.4766,-215.8314C200.4071,-208.131 199.1353,-198.9743 197.9468,-190.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"201.3999,-189.8367 196.5574,-180.4133 194.4664,-190.7997 201.3999,-189.8367\"/>\n",
"</g>\n",
"<!-- well -->\n",
4 years ago
"<g id=\"node15\" class=\"node\">\n",
4 years ago
"<title>well</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"287\" cy=\"-162\" rx=\"29.795\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"287\" y=\"-158.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">well</text>\n",
"</g>\n",
"<!-- it&#45;&gt;well -->\n",
4 years ago
"<g id=\"edge15\" class=\"edge\">\n",
4 years ago
"<title>it&#45;&gt;well</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M220.7963,-219.4297C232.6429,-209.1531 248.7123,-195.2134 262.0525,-183.6412\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"264.6834,-185.9924 269.9438,-176.7957 260.0964,-180.7047 264.6834,-185.9924\"/>\n",
"</g>\n",
"<!-- so -->\n",
4 years ago
"<g id=\"node12\" class=\"node\">\n",
4 years ago
"<title>so</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"186\" cy=\"-90\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"186\" y=\"-86.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">so</text>\n",
"</g>\n",
"<!-- gets&#45;&gt;so -->\n",
4 years ago
"<g id=\"edge10\" class=\"edge\">\n",
4 years ago
"<title>gets&#45;&gt;so</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M191.9813,-143.8314C191.1257,-136.131 190.1083,-126.9743 189.1574,-118.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"192.6289,-117.9656 188.0459,-108.4133 185.6717,-118.7386 192.6289,-117.9656\"/>\n",
"</g>\n",
"<!-- hard -->\n",
4 years ago
"<g id=\"node13\" class=\"node\">\n",
4 years ago
"<title>hard</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"101\" cy=\"-18\" rx=\"32.4942\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"101\" y=\"-14.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">hard</text>\n",
"</g>\n",
"<!-- so&#45;&gt;hard -->\n",
4 years ago
"<g id=\"edge11\" class=\"edge\">\n",
4 years ago
"<title>so&#45;&gt;hard</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M169.2067,-75.7751C157.0734,-65.4975 140.4625,-51.4271 126.6713,-39.7451\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"128.8249,-36.9824 118.9322,-33.1896 124.3004,-42.3238 128.8249,-36.9824\"/>\n",
"</g>\n",
"<!-- hard&#45;&gt;to -->\n",
4 years ago
"<g id=\"edge12\" class=\"edge\">\n",
4 years ago
"<title>hard&#45;&gt;to</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M78.4193,-31.3041C63.7176,-40.9698 45.0932,-55.2578 33,-72 8.0535,-106.5367 0,-119.3959 0,-162 0,-306 0,-306 0,-306 0,-366.227 63.5963,-411.8141 103.1644,-434.3488\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"101.7259,-437.5526 112.1724,-439.3198 105.108,-431.4238 101.7259,-437.5526\"/>\n",
4 years ago
"</g>\n",
"<!-- hide&#45;&gt;it -->\n",
4 years ago
"<g id=\"edge14\" class=\"edge\">\n",
4 years ago
"<title>hide&#45;&gt;it</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M117.1259,-292.4574C133.8494,-281.2041 157.8169,-265.0765 176.3429,-252.6104\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"178.3425,-255.4835 184.6851,-246.997 174.4345,-249.6759 178.3425,-255.4835\"/>\n",
"</g>\n",
"<!-- well&#45;&gt;I -->\n",
4 years ago
"<g id=\"edge16\" class=\"edge\">\n",
4 years ago
"<title>well&#45;&gt;I</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M288.5527,-180.1898C291.5849,-217.3334 298,-304.5925 298,-378 298,-594 298,-594 298,-594 298,-634.124 298,-680.5369 298,-709.5823\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"294.5001,-709.8146 298,-719.8146 301.5001,-709.8147 294.5001,-709.8146\"/>\n",
"</g>\n",
"<!-- not -->\n",
4 years ago
"<g id=\"node17\" class=\"node\">\n",
4 years ago
"<title>not</title>\n",
4 years ago
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"368\" cy=\"-594\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"368\" y=\"-590.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">not</text>\n",
4 years ago
"</g>\n",
"<!-- was&#45;&gt;not -->\n",
4 years ago
"<g id=\"edge18\" class=\"edge\">\n",
4 years ago
"<title>was&#45;&gt;not</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M365.0094,-647.8314C365.4372,-640.131 365.9459,-630.9743 366.4213,-622.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"369.9169,-622.592 366.977,-612.4133 362.9276,-622.2037 369.9169,-622.592\"/>\n",
4 years ago
"</g>\n",
"<!-- ready -->\n",
4 years ago
"<g id=\"node18\" class=\"node\">\n",
4 years ago
"<title>ready</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"373\" cy=\"-522\" rx=\"37.0935\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"373\" y=\"-518.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">ready</text>\n",
"</g>\n",
"<!-- not&#45;&gt;ready -->\n",
4 years ago
"<g id=\"edge19\" class=\"edge\">\n",
4 years ago
"<title>not&#45;&gt;ready</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M369.2617,-575.8314C369.7965,-568.131 370.4323,-558.9743 371.0266,-550.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"374.52,-550.6317 371.7213,-540.4133 367.5368,-550.1467 374.52,-550.6317\"/>\n",
4 years ago
"</g>\n",
"<!-- for -->\n",
4 years ago
"<g id=\"node19\" class=\"node\">\n",
4 years ago
"<title>for</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"376\" cy=\"-450\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"376\" y=\"-446.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">for</text>\n",
"</g>\n",
"<!-- ready&#45;&gt;for -->\n",
4 years ago
"<g id=\"edge20\" class=\"edge\">\n",
4 years ago
"<title>ready&#45;&gt;for</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M373.757,-503.8314C374.0779,-496.131 374.4594,-486.9743 374.816,-478.4166\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"378.3133,-478.5503 375.2328,-468.4133 371.3194,-478.2589 378.3133,-478.5503\"/>\n",
"</g>\n",
"<!-- the -->\n",
4 years ago
"<g id=\"node20\" class=\"node\">\n",
4 years ago
"<title>the</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"400\" cy=\"-306\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"400\" y=\"-302.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">the</text>\n",
"</g>\n",
"<!-- for&#45;&gt;the -->\n",
4 years ago
"<g id=\"edge21\" class=\"edge\">\n",
4 years ago
"<title>for&#45;&gt;the</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M378.9911,-432.0535C383.0871,-407.4774 390.4832,-363.1008 395.3171,-334.0974\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"398.7795,-334.6121 396.9712,-324.1727 391.8748,-333.4612 398.7795,-334.6121\"/>\n",
"</g>\n",
"<!-- fall -->\n",
4 years ago
"<g id=\"node21\" class=\"node\">\n",
4 years ago
"<title>fall</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"568\" cy=\"-234\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"568\" y=\"-230.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">fall</text>\n",
"</g>\n",
"<!-- the&#45;&gt;fall -->\n",
4 years ago
"<g id=\"edge22\" class=\"edge\">\n",
4 years ago
"<title>the&#45;&gt;fall</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M423.5947,-296.9677C450.1808,-286.6473 494.5713,-268.9839 532,-252 533.7658,-251.1987 535.5718,-250.3597 537.3885,-249.5004\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"538.9549,-252.6307 546.4251,-245.1176 535.9001,-246.3324 538.9549,-252.6307\"/>\n",
"</g>\n",
"<!-- writing -->\n",
4 years ago
"<g id=\"node25\" class=\"node\">\n",
4 years ago
"<title>writing</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"479\" cy=\"-234\" rx=\"44.393\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"479\" y=\"-230.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">writing</text>\n",
"</g>\n",
"<!-- the&#45;&gt;writing -->\n",
4 years ago
"<g id=\"edge28\" class=\"edge\">\n",
4 years ago
"<title>the&#45;&gt;writing</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M415.9868,-291.4297C426.6384,-281.722 440.8765,-268.7455 453.1235,-257.5837\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"455.7929,-259.8863 460.8262,-250.5634 451.0777,-254.7127 455.7929,-259.8863\"/>\n",
"</g>\n",
"<!-- wall -->\n",
4 years ago
"<g id=\"node27\" class=\"node\">\n",
4 years ago
"<title>wall</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"349\" cy=\"-234\" rx=\"29.795\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"349\" y=\"-230.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">wall</text>\n",
"</g>\n",
"<!-- the&#45;&gt;wall -->\n",
4 years ago
"<g id=\"edge31\" class=\"edge\">\n",
4 years ago
"<title>the&#45;&gt;wall</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M388.4273,-289.6621C382.0628,-280.6768 374.0285,-269.3343 366.8756,-259.2362\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"369.5171,-256.9101 360.8808,-250.7729 363.8049,-260.9562 369.5171,-256.9101\"/>\n",
"</g>\n",
"<!-- Too -->\n",
4 years ago
"<g id=\"node22\" class=\"node\">\n",
4 years ago
"<title>Too</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"545\" cy=\"-162\" rx=\"27.0966\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"545\" y=\"-158.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">Too</text>\n",
"</g>\n",
"<!-- fall&#45;&gt;Too -->\n",
4 years ago
"<g id=\"edge23\" class=\"edge\">\n",
4 years ago
"<title>fall&#45;&gt;Too</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M562.3146,-216.2022C559.7437,-208.1541 556.6466,-198.4588 553.7868,-189.5067\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"557.0768,-188.3033 550.6997,-179.8425 550.4087,-190.4334 557.0768,-188.3033\"/>\n",
"</g>\n",
"<!-- blind -->\n",
4 years ago
"<g id=\"node23\" class=\"node\">\n",
4 years ago
"<title>blind</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"76\" cy=\"-90\" rx=\"34.394\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"76\" y=\"-86.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">blind</text>\n",
"</g>\n",
"<!-- Too&#45;&gt;blind -->\n",
4 years ago
"<g id=\"edge24\" class=\"edge\">\n",
4 years ago
"<title>Too&#45;&gt;blind</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M519.1989,-155.454C503.5925,-151.6799 483.2478,-147.0864 465,-144 326.062,-120.5002 288.7296,-132.7004 150,-108 139.149,-106.068 127.5185,-103.4857 116.7666,-100.8814\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"117.3305,-97.4151 106.7814,-98.3983 115.6411,-104.2082 117.3305,-97.4151\"/>\n",
"</g>\n",
"<!-- blind&#45;&gt;to -->\n",
4 years ago
"<g id=\"edge25\" class=\"edge\">\n",
4 years ago
"<title>blind&#45;&gt;to</title>\n",
4 years ago
"<path fill=\"none\" stroke=\"#000000\" d=\"M68.1264,-107.7865C56.9959,-134.5941 38,-187.201 38,-234 38,-306 38,-306 38,-306 38,-357.0833 80.3418,-403.828 108.785,-429.4661\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"106.5619,-432.1716 116.3921,-436.1237 111.172,-426.904 106.5619,-432.1716\"/>\n",
4 years ago
"</g>\n",
"<!-- see&#45;&gt;the -->\n",
4 years ago
"<g id=\"edge27\" class=\"edge\">\n",
4 years ago
"<title>see&#45;&gt;the</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M260.5254,-367.9887C288.4956,-355.5575 336.3843,-334.2736 368.1162,-320.1706\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"369.6887,-323.3019 377.4054,-316.0421 366.8457,-316.9052 369.6887,-323.3019\"/>\n",
"</g>\n",
"<!-- on -->\n",
4 years ago
"<g id=\"node26\" class=\"node\">\n",
4 years ago
"<title>on</title>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"429\" cy=\"-162\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"429\" y=\"-158.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">on</text>\n",
"</g>\n",
"<!-- writing&#45;&gt;on -->\n",
4 years ago
"<g id=\"edge29\" class=\"edge\">\n",
4 years ago
"<title>writing&#45;&gt;on</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M466.8964,-216.5708C460.7891,-207.7763 453.2678,-196.9457 446.54,-187.2577\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"449.2267,-184.9902 440.6479,-178.7729 443.4771,-188.983 449.2267,-184.9902\"/>\n",
"</g>\n",
"<!-- on&#45;&gt;the -->\n",
4 years ago
"<g id=\"edge30\" class=\"edge\">\n",
4 years ago
"<title>on&#45;&gt;the</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M425.3402,-180.1727C420.3665,-204.8697 411.4269,-249.2595 405.605,-278.1684\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"402.1575,-277.5593 403.6142,-288.0535 409.0197,-278.9413 402.1575,-277.5593\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
4 years ago
"<graphviz.dot.Digraph at 0x7f8c94ff4dd8>"
4 years ago
]
},
4 years ago
"execution_count": 11,
4 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 12,
4 years ago
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'tale.pdf'"
]
},
4 years ago
"execution_count": 12,
4 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot.render(\"tale\")"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 13,
4 years ago
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0mdot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrender\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mfilename\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mdirectory\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mview\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mcleanup\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mrenderer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mformatter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mquiet\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0mquiet_view\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Save the source to file and render with the Graphviz engine.\n",
"\n",
"Args:\n",
" filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``)\n",
" directory: (Sub)directory for source saving and rendering.\n",
" view (bool): Open the rendered result with the default application.\n",
" cleanup (bool): Delete the source file after rendering.\n",
" format: The output format used for rendering (``'pdf'``, ``'png'``, etc.).\n",
" renderer: The output renderer used for rendering (``'cairo'``, ``'gd'``, ...).\n",
" formatter: The output formatter used for rendering (``'cairo'``, ``'gd'``, ...).\n",
" quiet (bool): Suppress ``stderr`` output from the layout subprocess.\n",
" quiet_view (bool): Suppress ``stderr`` output from the viewer process\n",
" (implies ``view=True``, ineffective on Windows).\n",
"Returns:\n",
" The (possibly relative) path of the rendered file.\n",
"Raises:\n",
" ValueError: If ``format``, ``renderer``, or ``formatter`` are not known.\n",
" graphviz.RequiredArgumentError: If ``formatter`` is given but ``renderer`` is None.\n",
" graphviz.ExecutableNotFound: If the Graphviz executable is not found.\n",
" subprocess.CalledProcessError: If the exit status is non-zero.\n",
" RuntimeError: If viewer opening is requested but not supported.\n",
"\n",
"The layout command is started from the directory of ``filepath``, so that\n",
"references to external files (e.g. ``[image=...]``) can be given as paths\n",
"relative to the DOT source file.\n",
"\u001b[0;31mFile:\u001b[0m /opt/tljh/user/lib/python3.7/site-packages/graphviz/files.py\n",
"\u001b[0;31mType:\u001b[0m method\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dot.render?"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 14,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"# Example of using the graph as a generator ??"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 15,
4 years ago
"metadata": {},
4 years ago
"outputs": [
{
"data": {
"text/plain": [
"'tale.png'"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot.render(\"tale\", format=\"png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](tale.png)"
]
4 years ago
},
4 years ago
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}