{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f8d8640e-1504-42a0-9197-17be01d16ce9",
   "metadata": {},
   "source": [
    "# Creating Text-Fabric from Low-Fat-Tree data (version 0.1.1)\n",
    "\n",
    "This is the workbook associated to a test run to build LFT Text-Fabric using the XML import function of Text-Fabric."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2c5cab1-ebbe-4032-bc9c-3029b212d88e",
   "metadata": {},
   "source": [
    "Example code.\n",
    "\n",
    "Documentation: [tf.convert.xml](https://annotation.github.io/text-fabric/tf/convert/xml.html) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2ad1e9ba-b6d6-461b-88b6-8f70b5af1e82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Working in repository Read_from_lowfat/. in backend my_new_Jupyter_folder\n",
      "\n",
      "        Convert XML to TF.\n",
      "        There are also commands to check the XML and to load the TF.\n",
      "\n",
      "        python3 C:/Users/tonyj/my_new_Jupyter_folder/Read_from_lowfat [tasks/flags] [--help]\n",
      "\n",
      "        --help: show this text and exit\n",
      "\n",
      "        tasks:\n",
      "            a sequence of tasks:\n",
      "            check:\n",
      "                just reports on the elements in the source.\n",
      "            convert:\n",
      "                just converts XML to TF\n",
      "            load:\n",
      "                just loads the generated TF;\n",
      "\n",
      "        flags:\n",
      "            test:\n",
      "                run in test mode\n",
      "        \n",
      "Illegal argument `-f`\n",
      "Illegal argument `C:/Users/tonyj/AppData/Roaming/jupyter/runtime/kernel-0061e8fa-12fe-4856-a035-9fe8ffb4894a.json`\n"
     ]
    },
    {
     "ename": "SystemExit",
     "evalue": "-1",
     "output_type": "error",
     "traceback": [
      "An exception has occurred, use %tb to see the full traceback.\n",
      "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m -1\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from tf.convert.xml import XML\n",
    "\n",
    "dn = os.path.abspath('')\n",
    "\n",
    "TEST_SET = set(\n",
    "    \"\"\"\n",
    "    26-jude.xml\n",
    "    \"\"\".strip().split()\n",
    ")\n",
    "\n",
    "AUTHOR = \"Evangelists and apostles\"\n",
    "TITLE = \"Greek New Testament\"\n",
    "INSTITUTE = \"ETCBC (Eep Talstra Centre for Bible and Computer)\"\n",
    "\n",
    "GENERIC = dict(\n",
    "    author=AUTHOR,\n",
    "    title=TITLE,\n",
    "    institute=INSTITUTE,\n",
    "    language=\"nl\",\n",
    "    converters=\"Dirk Roorda et al. (Text-Fabric)\",\n",
    "    sourceFormat=\"XML (lowfat)\",\n",
    "    descriptionTf=\"Nestle 1904 edition\",\n",
    ")\n",
    "\n",
    "def task(self, check=False, convert=False, load=False, test=True):\n",
    "    return\n",
    "\n",
    "def transform(text):\n",
    "    print (text)\n",
    "    return text\n",
    "\n",
    "\n",
    "X = XML(\n",
    "    sourceVersion=\"input_xml\",\n",
    "    testSet=TEST_SET,\n",
    "    generic=GENERIC,\n",
    "    transform=transform,\n",
    "    tfVersion=\"0.1\",\n",
    ")\n",
    "\n",
    "#X.run(os.path.abspath(''))\n",
    "X.run(__file__)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "afeafc59-d786-40a1-9d66-31e6088754ac",
   "metadata": {},
   "outputs": [
    {
     "ename": "SystemExit",
     "evalue": "-1",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mSystemExit\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [16]\u001b[0m, in \u001b[0;36m<cell line: 42>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     31\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m text\n\u001b[0;32m     34\u001b[0m X \u001b[38;5;241m=\u001b[39m XML(\n\u001b[0;32m     35\u001b[0m     sourceVersion\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minput_xml\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     36\u001b[0m     testSet\u001b[38;5;241m=\u001b[39mTEST_SET,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m     39\u001b[0m     tfVersion\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0.1\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m     40\u001b[0m )\n\u001b[1;32m---> 42\u001b[0m \u001b[43mX\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mabspath\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32m~\\anaconda3\\lib\\site-packages\\tf\\convert\\xml.py:1026\u001b[0m, in \u001b[0;36mXML.run\u001b[1;34m(self, program)\u001b[0m\n\u001b[0;32m   1024\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m illegalArgs:\n\u001b[0;32m   1025\u001b[0m         console(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIllegal argument `\u001b[39m\u001b[38;5;132;01m{\u001b[39;00marg\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m`\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m-> 1026\u001b[0m     \u001b[43msys\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1028\u001b[0m tasks \u001b[38;5;241m=\u001b[39m {arg: \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m args \u001b[38;5;28;01mif\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m possibleTasks}\n\u001b[0;32m   1029\u001b[0m flags \u001b[38;5;241m=\u001b[39m {arg: \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;28;01mfor\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m args \u001b[38;5;28;01mif\u001b[39;00m arg \u001b[38;5;129;01min\u001b[39;00m possibleFlags}\n",
      "\u001b[1;31mSystemExit\u001b[0m: -1"
     ]
    }
   ],
   "source": [
    "%tb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5261545f-4e53-470e-8e89-fb31ffc91fa8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "python3: can't open file 'C:\\\\Users\\\\tonyj\\\\my_new_Jupyter_folder\\\\Read_from_lowfat\\\\Read_from_lowfat': [Errno 2] No such file or directory\n"
     ]
    }
   ],
   "source": [
    "! python3 Read_from_lowfat [tasks/flags] [--help]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3107c3e3-345b-40b3-9897-a306fc2114dc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}