Datasets:

Modalities:
Text
Formats:
json
Libraries:
Datasets
pandas
License:
File size: 2,953 Bytes
b1c5f6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
 "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
}