{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import xml.etree.ElementTree as ET\n", "import os\n", "import csv\n", "from collections import OrderedDict" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "baseDir = '/Users/federicaspinelli/TEAMOVI/Parser/Data/DallOVI/datiniXML/'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "gat = []\n", "basepath_gat = baseDir + 'xmlgat'\n", "for entry in os.listdir(basepath_gat):\n", " if os.path.isfile(os.path.join(basepath_gat, entry)): # prolly redundant\n", " gg = entry.split('.')[1]\n", " if gg != '':\n", " gat.append([gg, entry])\n", "\n", "\n", "# NON HO AL MOMENTO A DISPOSIZIONE I 'nolemmi'\n", " \n", "#nolemmi = []\n", "#basepath_nolemmi = baseDir + 'DatiniXML_incompleto'\n", "#for entry in os.listdir(basepath_nolemmi):\n", "# if os.path.isfile(os.path.join(basepath_nolemmi, entry)):\n", "# nn = entry.split('.')[1]\n", "# if nn != '':\n", "# nolemmi.append([nn, entry])\n", "\n", "lemmi = []\n", "basepath_lemmi = baseDir + 'lemmi_txt'\n", "for entry in os.listdir(basepath_lemmi):\n", " if os.path.isfile(os.path.join(basepath_lemmi, entry)):\n", " ll = entry.split('.')[1]\n", " if ll != '':\n", " lemmi.append([ll, entry])\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Non mi è chiaro a cosa servano le **tre** celle seguenti -- in ogni caso, non ho a disposizione BiblioDatini.xml nella versione corrente dei dati OVI." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "xmlparse = ET.parse(baseDir + 'BiblioDatini.xml')\n", "root = xmlparse.getroot()\n", "biblio = root.findall(\"Biblio\")\n", "\n", "sigle = []\n", "for bib in biblio:\n", " sigla = bib.find(\"sigla\")\n", " sigle.append(sigla.text.lower())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "OVI_data = open(baseDir + 'OVI_Data.csv', 'w')\n", "csvwriter = csv.writer(OVI_data)\n", "\n", "params = [\"BiblioDatini\", \"lemmi\", \"xmlgat\"]\n", "\n", "csvwriter.writerow(params)\n", "\n", "for sigla in sigle:\n", " row = [sigla]\n", " no_lemma = \" \"\n", " lemma = \" \"\n", " gatto = \" \"\n", "# for x in range(len(nolemmi)):\n", "# if sigla in nolemmi[x][0]:\n", "# no_lemma = nolemmi[x][1]\n", " row.append(no_lemma)\n", " for x in range(len(lemmi)):\n", " if sigla == lemmi[x][0]:\n", " lemma = lemmi[x][1]\n", " row.append(lemma)\n", " for x in range(len(gat)):\n", " if sigla == gat[x][0]:\n", " gatto = gat[x][1]\n", " row.append(gatto)\n", " csvwriter.writerow(row)\n", "\n", "OVI_data.close()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#Cambiare percorsi file\n", "#xml_file_name = 'Ovi/BiblioDatini.xml'\n", "#tree = Xet.parse(xml_file_name)\n", "#root = tree.getroot() --> già definito\n", "#biblio = root.findall(\"Biblio\") --> già definito\n", "\n", "\n", "Datini_data = open(baseDir + 'Datini_Data.csv', 'w')\n", "csvwriter = csv.writer(Datini_data)\n", "\n", "elemList = []\n", "\n", "for elem in root.iter():\n", " elemList.append(elem.tag)\n", "\n", "\n", "elemList = list(set(elemList))\n", "\n", "elemList.remove(\"dataroot\")\n", "elemList.remove(\"Biblio\")\n", "\n", "param = elemList\n", "\n", "csvwriter.writerow(param)\n", "\n", "\n", "def cell(p, arr):\n", " if arr.find(p) is None:\n", " res = \" \"\n", " else:\n", " res = arr.find(p).text\n", " return res\n", "\n", "\n", "for scheda in biblio:\n", " aut = []\n", "\n", " for par in param:\n", " if par == \"star_note\":\n", " if scheda.find(\".//star_note\") is None:\n", " r = \" \"\n", " else:\n", " r = \"True\"\n", " else:\n", " r = cell(par, scheda)\n", " aut.append(r)\n", "\n", " csvwriter.writerow(aut)\n", "\n", "Datini_data.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Si riprende da qui" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import re\n", "\n", "\n", "iperlem_data = open(baseDir + 'lem_Data.csv', 'w')\n", "csvwriter = csv.writer(iperlem_data)\n", "\n", "params = [\"sigla\", \"file\", \"numero\", \"iperlemma\", \"lemma\", \"categoria grammaticale\", \"livello\"]\n", "csvwriter.writerow(params)\n", "\n", "def write_lines(lines, sig, file):\n", " for line in lines:\n", " row = [sig, file]\n", " lem = re.split('\\|', line)\n", " for l in lem:\n", " m = l.strip()\n", " row.append(m)\n", "# print(row)\n", " csvwriter.writerow(row)\n", "\n", "\n", "for x in range(len(lemmi)):\n", " sigla = lemmi[x][0]\n", " file_name = lemmi[x][1]\n", " #Cambia percorso\n", " f = open(baseDir + 'lemmi_txt/' + file_name, \"r\", encoding='latin-1')\n", " lines = f.readlines()\n", " write_lines(lines, sigla, file_name)\n", "\n", "\n", "f.close()\n", "\n", "iperlem_data.close()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "110829\n" ] } ], "source": [ "redundantLemmas = []\n", "\n", "def write_lines_here(lines, sig):\n", " toRet = []\n", " for line in lines:\n", " row = [sig]\n", " lem = re.split('\\|', line)\n", " for l in lem:\n", " m = l.strip()\n", " row.append(m)\n", " toRet.append(row)\n", " return toRet\n", "\n", "\n", "for x in range(len(lemmi)):\n", " sigla = lemmi[x][0]\n", " file_name = lemmi[x][1]\n", " #Cambia percorso\n", " f = open(baseDir + 'lemmi_txt/' + file_name, \"r\", encoding='latin-1')\n", " lines = f.readlines()\n", " redundantLemmas = redundantLemmas + write_lines_here(lines, sigla)\n", "\n", "\n", "f.close()\n", "\n", "print(len(redundantLemmas))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check di cosa viene fuori dalla lettura" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['l95', '1', 'pagare', 'v.', '']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "redundantLemmas[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Esporto il lemmario" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "90150\n", "7591\n" ] } ], "source": [ "preprefinal = list(filter(lambda row: 'IPERLEMMA' not in row[1], redundantLemmas))\n", "prefinal = list(map(lambda row: (row[2], row[3], row[4]), preprefinal))\n", "\n", "print(len(prefinal))\n", "\n", "final = list(set(prefinal))\n", "final.sort()\n", "\n", "print(len(final))\n", "\n", "\n", "# IPERLEMMI\n", "\n", "preprefinalIPER = list(filter(lambda row: 'IPERLEMMA' in row[1], redundantLemmas))\n", "prefinalIPER = list(map(lambda row: (row[2], row[3], row[4]), preprefinalIPER))\n", "\n", "finalIPER = list(set(prefinalIPER))\n", "finalIPER.sort()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lem_data_unique = open(baseDir + 'lem_unique.csv', 'w')\n", "csvwriter = csv.writer(lem_data_unique)\n", "\n", "csvwriter.writerow(['lemma', 'categoria grammaticale', 'note'])\n", "\n", "for line in final:\n", " csvwriter.writerow(line)\n", "\n", "lem_data_unique.close()\n", "\n", "\n", "# IPERLEMMI\n", "\n", "iperlem_data_unique = open(baseDir + 'iperlem_unique.csv', 'w')\n", "csvwriter = csv.writer(iperlem_data_unique)\n", "\n", "csvwriter.writerow(['iperlemma', 'categoria grammaticale', 'note'])\n", "\n", "for line in finalIPER:\n", " #print(line)\n", " csvwriter.writerow(line)\n", "\n", "iperlem_data_unique.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Categorie grammaticali ed export ordinato" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['agg.', 'agg./s.m.', 'antr.', 'avv.', 'n.g.', 'n.p.', 's.f.', 's.f./s.m.', 's.f.pl.', 's.i.', 's.m.', 's.m./s.f.', 's.m.pl.', 'v.']\n" ] } ], "source": [ "cat_gramm = set(map(lambda entry: entry[1], final))\n", "cat_gramm2 = list(cat_gramm)\n", "cat_gramm2.sort()\n", "\n", "print(cat_gramm2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "byType = OrderedDict()\n", "\n", "for type1 in cat_gramm2:\n", " byType[type1] = list(filter(lambda a: a[1]==type1, final))\n", "\n", "lem_data_byCat = open(baseDir + 'lem_unique_byCat.csv', 'w')\n", "csvwriter = csv.writer(lem_data_byCat)\n", "\n", "csvwriter.writerow(['lemma', 'categoria grammaticale', 'note'])\n", "\n", "for type1 in cat_gramm2:\n", " print(type1)\n", " for line in byType[type1]:\n", " csvwriter.writerow(line)\n", "\n", "lem_data_byCat.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Microprova di modifica + export di xml (modifico un attribute di un tag).\n", "\n", "Come prima cosa, provo a recuperare la lista dei lemmi di un singolo file, e a rintracciare quel lemma e il suo ID (numero d'ordine) nel lemmario." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'n': '6', 'type': '1'}\n", "lem\n", "Lemma: ['d16', '6', 'maggio', 's.m.', '']\n", "New ID: 4247\n", "\n", "{'n': '13', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '13', 'simona (donna di piero di paolo rinaldeschi)', 'antr.', '']\n", "New ID: 6666\n", "\n", "{'n': '7', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '7', 'famiglio', 's.m.', '']\n", "New ID: 2514\n", "\n", "{'n': '18', 'type': '2'}\n", "lem\n", "Lemma: ['d16', '18', 'oncia', 's.f.', '']\n", "New ID: 5069\n", "\n", "{'n': '20', 'type': '4'}\n", "lem\n", "Lemma: ['d16', '20', 'bottoncino', 's.m.', '']\n", "New ID: 1255\n", "\n", "{'n': '22', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '22', 'infilare', 'v.', '']\n", "New ID: 3786\n", "\n", "{'n': '9', 'type': '2'}\n", "lem\n", "Lemma: ['d16', '9', 'braccio', 's.m.', '']\n", "New ID: 1269\n", "\n", "{'n': '19', 'type': '4'}\n", "lem\n", "Lemma: ['d16', '19', 'frangia', 's.f.', '']\n", "New ID: 2907\n", "\n", "{'n': '8', 'type': '3'}\n", "lem\n", "Lemma: ['d16', '8', 'nero', 'agg./s.m.', '']\n", "New ID: 4860\n", "\n", "{'n': '15', 'type': '3'}\n", "lem\n", "Lemma: ['d16', '15', 'azzurro', 'agg./s.m.', '']\n", "New ID: 709\n", "\n", "{'n': '16', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '16', 'nannino (manovale)', 'antr.', '']\n", "New ID: 4807\n", "\n", "{'n': '12', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '12', 'san bartolomeo (chiesa e convento di)', 'n.g.', 'a prato (convento di carmelitani)']\n", "New ID: 6303\n", "\n", "{'n': '14', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '14', 'nanni di luca da santa chiara', 'antr.', '']\n", "New ID: 4789\n", "\n", "{'n': '11', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '11', 'garzone', 's.m.', '']\n", "New ID: 3021\n", "\n", "{'n': '21', 'type': '1'}\n", "lem\n", "Lemma: ['d16', '21', 'nona', 's.f.', '']\n", "New ID: 5025\n", "\n", "{'n': '10', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '10', 'domenica', 's.f.', '']\n", "New ID: 2369\n", "\n", "{'n': '3', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '3', 'sere', 's.m.', '']\n", "New ID: 6611\n", "\n", "{'n': '17', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '17', 'clemente di niccolò di piero', 'antr.', '']\n", "New ID: 1900\n", "\n", "{'n': '14', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '14', 'nanni di luca da santa chiara', 'antr.', '']\n", "New ID: 4789\n", "\n", "{'n': '1', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '1', 'margherita di domenico bandini', 'antr.', '']\n", "New ID: 4378\n", "\n", "{'n': '5', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '5', 'prato', 'n.g.', '']\n", "New ID: 5821\n", "\n", "{'n': '4', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '4', 'francesco di marco datini', 'antr.', '']\n", "New ID: 2864\n", "\n", "{'n': '5', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '5', 'prato', 'n.g.', '']\n", "New ID: 5821\n", "\n", "{'n': '2', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '2', 'firenze', 'n.g.', '']\n", "New ID: 2708\n", "\n", "{'n': '5', 'type': '0'}\n", "lem\n", "Lemma: ['d16', '5', 'prato', 'n.g.', '']\n", "New ID: 5821\n", "\n", "{'n': '6', 'type': '1'}\n", "lem\n", "Lemma: ['d16', '6', 'maggio', 's.m.', '']\n", "New ID: 4247\n", "\n" ] } ], "source": [ "ii = 2\n", "\n", "smalltree = ET.parse(baseDir + 'xmlgat/' + gat[ii][1])\n", "smallroot = smalltree.getroot()\n", "\n", "localLemNodes = smallroot.iter('lem')\n", "\n", "for node in localLemNodes:\n", " print(node.attrib)\n", " print(node.tag)\n", " #\n", " thisLemma = list(filter(lambda lem: lem[0]==gat[ii][0] and lem[1]==node.attrib['n'], redundantLemmas))[0]\n", " newID = final.index((thisLemma[2], thisLemma[3], thisLemma[4]))\n", " #\n", " print('Lemma: ', thisLemma)\n", " print('New ID: ', newID)\n", " print()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Qui faccio una prova di modifica del singolo file e di export in nuovo xml" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ii = 2\n", "\n", "smalltree = ET.parse(baseDir + 'xmlgat/' + gat[ii][1])\n", "smallroot = smalltree.getroot()\n", "\n", "for node in smallroot.iter('lem'):\n", " node.set('n', '100h')\n", " \n", "smalltree.write(baseDir + 'prova.xml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Infine provo un loop su tutti i file, li elaboro e li esporto in una nuova cartella (che va creata a mano) 'newxmlgat'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.l82.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.t05.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.q69.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.b96.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.b53.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e67.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.i45.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v34.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.s91.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.w53.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.t80.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.u08.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.67b.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.q98.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v47.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.o13.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v89.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.i28.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.w71.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.46a.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.n66.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.m32.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.g19.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.n28.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.q28.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.84c.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.x54.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.a87.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.y08.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.z31.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e16.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.j60.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.57c.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.z72.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.22a.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.j89.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e26.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e69.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.x06.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.c55.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v32.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.y21.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.t82.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.c76.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.d94.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.o67.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.z70.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.34a.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.n17.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.a18.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.m80.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.n49.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.68b.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.l23.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.b17.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.m61.xml'\n", "Parsing original xml file: xmlgat.z76.xml failed\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.u36.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.r37.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.76a.xml'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.c60.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e23.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v76.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.83c.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.d04.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.f34.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.42b.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.a31.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.w47.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.b60.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.u76.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.f53.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.t21.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.w61.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.t78.xml'\n", "Parsing original xml file: xmlgat.s73.xml failed\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.z50.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.r70.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.k68.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.h95.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.i94.xml'\n", "Parsing original xml file: xmlgat.s64.xml failed\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.l54.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.v14.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.q65.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.e35.xml'\n", "In Export:\n", "[Errno 2] No such file or directory: '/home/kora/Desktop/OVI_Data_Local/OVIaspo/DallOVI/datiniXML/newxmlgat/newxmlgat.p57.xml'\n" ] } ], "source": [ "for ii in range(len(gat)):\n", " try:\n", " smalltree = ET.parse(baseDir + 'xmlgat/' + gat[ii][1])\n", " smallroot = smalltree.getroot()\n", " #\n", " localLemNodes = smallroot.iter('lem')\n", " #\n", " for node in localLemNodes:\n", " try:\n", " thisLemma = list(filter(lambda lem: lem[0]==gat[ii][0] and lem[1]==node.attrib['n'], redundantLemmas))[0]\n", " newID = final.index((thisLemma[2], thisLemma[3], thisLemma[4]))\n", " #\n", " node.set('n', str(newID))\n", " except Exception as e:\n", " print('In looking for lemma:')\n", " print(e)\n", " try:\n", " smalltree.write(baseDir + 'newxmlgat/'+'newxmlgat.'+gat[ii][0]+'.xml')\n", " except Exception as e:\n", " print('In Export:')\n", " print(e)\n", " except:\n", " print('Parsing original xml file: ', gat[ii][1], ' failed' )" ] }, { "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.9.0" } }, "nbformat": 4, "nbformat_minor": 2 }