diff --git a/data/unl.ru/ipynb.zip b/data/unl.ru/ipynb.zip new file mode 100644 index 0000000000000000000000000000000000000000..50ef204501677d7752102bca5f65ba68a02e4120 Binary files /dev/null and b/data/unl.ru/ipynb.zip differ diff --git a/scripts/batch_unlizeToNotebook.sh b/scripts/batch_unlizeToNotebook.sh new file mode 100644 index 0000000000000000000000000000000000000000..caa4dcb4f60d3d5e22b8e3d1f6873b3b6b62d98b --- /dev/null +++ b/scripts/batch_unlizeToNotebook.sh @@ -0,0 +1,6 @@ +#!/bin/bash +for filepath in unl/*; do + echo "$filepath" + python unlizeToNotebook.py "$filepath" "$(basename "$filepath" .xml).ipynb" + done + diff --git a/scripts/unlizeToNotebook.py b/scripts/unlizeToNotebook.py index a14eb98e30848def4106eec945ba48a4f5e011b1..df30aff42724dc43acdbb23c6cfcc7f2eb3a34d1 100755 --- a/scripts/unlizeToNotebook.py +++ b/scripts/unlizeToNotebook.py @@ -2,7 +2,7 @@ import nbformat as nbf from nbformat.v4 import new_code_cell -import nbconvert as nbc +#from nbconvert.preprocessors import ExecutePreprocessor import click from lxml import etree, objectify from unlizeXml import remove_namespace, unlize, nestedBody2Str @@ -32,6 +32,10 @@ def unlizeXmlNb(input, output, template, lang, dry_run): addCell(nb, unl) else: addCell(nb, getText(node, 'unl')) + # We execute the notebook + #resources = {} + #exec_nb, resources = ExecutePreprocessor(timeout=-1).preprocess(nb, resources) + # Save with open(output, 'w') as f: nbf.write(nb, f) diff --git a/scripts/unlizeXmlNbSample.ipynb b/scripts/unlizeXmlNbSample.ipynb index 7eb293f008be3f57c196020bd3cfbe630b822efb..5d32deb279c3326ea72d84b21218883fa5b0e22a 100644 --- a/scripts/unlizeXmlNbSample.ipynb +++ b/scripts/unlizeXmlNbSample.ipynb @@ -11,12 +11,12 @@ "import re\n", "import requests\n", "from subprocess import Popen, PIPE, STDOUT\n", - "from IPython.core.display import SVG" + "from IPython.display import SVG, display, HTML" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -72,7 +72,13 @@ " regex = re.compile('<svg.*svg>',re.MULTILINE|re.DOTALL)\n", " svg = regex.search(html).group()\n", " return(svg)\n", - " \n", + "\n", + "def svg_to_fixed_width_html_image(svg, width=\"100%\"):\n", + " html_template='<img width=\"{}\">{}</img>'\n", + " text = html_template.format(width, svg)\n", + " return HTML(text)\n", + "\n", + "\n", "def displayUnl(unldata) :\n", "# We generate protoSVG because whent there are several sentences, \n", "# a string composed of several concatenated SVG is produced (not a valid SVG).\n", @@ -88,7 +94,7 @@ " try:\n", " #svg = unl2dotWeb(unl)\n", " svg = unl2dot(unl, \"unl2rdf-app-1.0-SNAPSHOT-jar-with-dependencies.jar\")\n", - " display(SVG(svg))\n", + " display(svg_to_fixed_width_html_image(svg))\n", " except Exception as e :\n", " print(e)" ]