diff --git a/Graphviz.ipynb b/Graphviz.ipynb
index 2973c26..34ea2c6 100644
--- a/Graphviz.ipynb
+++ b/Graphviz.ipynb
@@ -1,13 +1,36 @@
{
"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Tales to tell\n",
+ "\n",
+ "module: [graphviz](https://graphviz.readthedocs.io/en/stable/)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "https://pygraphviz.github.io/documentation/pygraphviz-1.6/"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from graphviz import Digraph"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
- "from graphviz import Digraph\n",
- "# Create Digraph object\n",
"dot = Digraph()"
]
},
@@ -78,6 +101,607 @@
"dot"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "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",
+ "execution_count": 2,
+ "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",
+ "execution_count": 7,
+ "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",
+ "execution_count": 8,
+ "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",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for w1, w2 in pairwise(text.split()):\n",
+ " dot.edge(w1, w2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "dot"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'tale.pdf'"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "dot.render(\"tale\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "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",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Example of using the graph as a generator ??"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
{
"cell_type": "code",
"execution_count": null,