File size: 2,006 Bytes
c8edf13 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7b378ac1-1035-4f5d-9c16-68c14178389b",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"from ftfy import fix_encoding"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1a8017c7-f7a1-4b17-804b-c4d404511969",
"metadata": {},
"outputs": [],
"source": [
"# Download and unzip archive from: https://www.dfki.uni-kl.de/cybermapping/data/CO-Fun-1.0-anonymized.zip\n",
"base_path = Path(\"./prepared-data-and-code/NER/CRF/\")\n",
"\n",
"splits = {\n",
" \"train\": base_path / \"train_set.txt\",\n",
" \"dev\": base_path / \"dev_set.txt\",\n",
" \"test\": base_path / \"test_set.txt\",\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ab1deaef-adf3-4c4e-8da2-0bcc833615b3",
"metadata": {},
"outputs": [],
"source": [
"for split_name, split_file in splits.items():\n",
" with open(split_file, \"rt\") as f_p:\n",
" buffer = f_p.readlines()\n",
" buffer = \"[\" + \"\".join(buffer) + \"]\"\n",
" data = eval(buffer)\n",
"\n",
" with open(f\"{split_name}.tsv\", \"wt\") as f_out:\n",
" for sentence in data:\n",
" for line in sentence:\n",
" token, pos, ner = line\n",
" token = fix_encoding(token)\n",
" f_out.write(f\"{token}\\t{pos}\\t{ner}\\n\")\n",
" f_out.write(\"\\n\")"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|