{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "19b83158", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/stefan/.venvs/dev/lib/python3.11/site-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (1.26.7) or chardet (5.2.0)/charset_normalizer (2.0.7) doesn't match a supported version!\n", " warnings.warn(\"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported \"\n" ] } ], "source": [ "import json\n", "import requests" ] }, { "cell_type": "code", "execution_count": 2, "id": "498c0877", "metadata": {}, "outputs": [], "source": [ "base_url = \"https://raw.githubusercontent.com/UniversalDependencies/UD_German-GSD\"\n", "commit = \"e5f625a0d438cb8b31d3d640a3edd21ff16359a0\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "21d82f00", "metadata": {}, "outputs": [], "source": [ "splits = [\"train\", \"dev\", \"test\"]" ] }, { "cell_type": "code", "execution_count": 4, "id": "b36162fb", "metadata": {}, "outputs": [], "source": [ "f_out = open(f\"UD_German-GSD_{commit[:7]}.jsonl\", \"wt\")\n", "\n", "for split in splits:\n", " current_url = f\"{base_url}/{commit}/de_gsd-ud-{split}.conllu\"\n", " r = requests.get(current_url)\n", "\n", " if not r:\n", " print(f\"Could not retrieve data for split {split}\")\n", " \n", " content = r.text\n", " \n", " current_sent_id = None\n", " current_text = None\n", " \n", " for line in content.split(\"\\n\"):\n", " if line.startswith(\"#\"):\n", " if line.startswith(\"# sent_id = \"):\n", " current_sent_id = line.split(\" = \")[-1]\n", " elif line.startswith(\"# text = \"):\n", " current_text = line.split(\" = \")[-1]\n", " else:\n", " if current_sent_id and current_text:\n", " f_out.write(json.dumps({\n", " \"sent_id\": current_sent_id,\n", " \"text\": current_text,\n", " \"split\": split\n", " }) + \"\\n\")\n", " \n", " current_sent_id = None\n", " current_text = None\n", " \n", "f_out.close()" ] } ], "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }