data: add export notebook
Browse files- Export.ipynb +107 -0
Export.ipynb
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "19b83158",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"name": "stderr",
|
| 11 |
+
"output_type": "stream",
|
| 12 |
+
"text": [
|
| 13 |
+
"/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",
|
| 14 |
+
" warnings.warn(\"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported \"\n"
|
| 15 |
+
]
|
| 16 |
+
}
|
| 17 |
+
],
|
| 18 |
+
"source": [
|
| 19 |
+
"import json\n",
|
| 20 |
+
"import requests"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": 2,
|
| 26 |
+
"id": "498c0877",
|
| 27 |
+
"metadata": {},
|
| 28 |
+
"outputs": [],
|
| 29 |
+
"source": [
|
| 30 |
+
"base_url = \"https://raw.githubusercontent.com/UniversalDependencies/UD_German-GSD\"\n",
|
| 31 |
+
"commit = \"e5f625a0d438cb8b31d3d640a3edd21ff16359a0\""
|
| 32 |
+
]
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"cell_type": "code",
|
| 36 |
+
"execution_count": 3,
|
| 37 |
+
"id": "21d82f00",
|
| 38 |
+
"metadata": {},
|
| 39 |
+
"outputs": [],
|
| 40 |
+
"source": [
|
| 41 |
+
"splits = [\"train\", \"dev\", \"test\"]"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"cell_type": "code",
|
| 46 |
+
"execution_count": 4,
|
| 47 |
+
"id": "b36162fb",
|
| 48 |
+
"metadata": {},
|
| 49 |
+
"outputs": [],
|
| 50 |
+
"source": [
|
| 51 |
+
"f_out = open(f\"UD_German-GSD_{commit[:7]}.jsonl\", \"wt\")\n",
|
| 52 |
+
"\n",
|
| 53 |
+
"for split in splits:\n",
|
| 54 |
+
" current_url = f\"{base_url}/{commit}/de_gsd-ud-{split}.conllu\"\n",
|
| 55 |
+
" r = requests.get(current_url)\n",
|
| 56 |
+
"\n",
|
| 57 |
+
" if not r:\n",
|
| 58 |
+
" print(f\"Could not retrieve data for split {split}\")\n",
|
| 59 |
+
" \n",
|
| 60 |
+
" content = r.text\n",
|
| 61 |
+
" \n",
|
| 62 |
+
" current_sent_id = None\n",
|
| 63 |
+
" current_text = None\n",
|
| 64 |
+
" \n",
|
| 65 |
+
" for line in content.split(\"\\n\"):\n",
|
| 66 |
+
" if line.startswith(\"#\"):\n",
|
| 67 |
+
" if line.startswith(\"# sent_id = \"):\n",
|
| 68 |
+
" current_sent_id = line.split(\" = \")[-1]\n",
|
| 69 |
+
" elif line.startswith(\"# text = \"):\n",
|
| 70 |
+
" current_text = line.split(\" = \")[-1]\n",
|
| 71 |
+
" else:\n",
|
| 72 |
+
" if current_sent_id and current_text:\n",
|
| 73 |
+
" f_out.write(json.dumps({\n",
|
| 74 |
+
" \"sent_id\": current_sent_id,\n",
|
| 75 |
+
" \"text\": current_text,\n",
|
| 76 |
+
" \"split\": split\n",
|
| 77 |
+
" }) + \"\\n\")\n",
|
| 78 |
+
" \n",
|
| 79 |
+
" current_sent_id = None\n",
|
| 80 |
+
" current_text = None\n",
|
| 81 |
+
" \n",
|
| 82 |
+
"f_out.close()"
|
| 83 |
+
]
|
| 84 |
+
}
|
| 85 |
+
],
|
| 86 |
+
"metadata": {
|
| 87 |
+
"kernelspec": {
|
| 88 |
+
"display_name": "Python 3 (ipykernel)",
|
| 89 |
+
"language": "python",
|
| 90 |
+
"name": "python3"
|
| 91 |
+
},
|
| 92 |
+
"language_info": {
|
| 93 |
+
"codemirror_mode": {
|
| 94 |
+
"name": "ipython",
|
| 95 |
+
"version": 3
|
| 96 |
+
},
|
| 97 |
+
"file_extension": ".py",
|
| 98 |
+
"mimetype": "text/x-python",
|
| 99 |
+
"name": "python",
|
| 100 |
+
"nbconvert_exporter": "python",
|
| 101 |
+
"pygments_lexer": "ipython3",
|
| 102 |
+
"version": "3.11.4"
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
"nbformat": 4,
|
| 106 |
+
"nbformat_minor": 5
|
| 107 |
+
}
|