{ "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 }