152 lines
3.7 KiB
Plaintext
152 lines
3.7 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from pathlib import Path\n",
|
||
|
"import json"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"this_dir_path = Path().resolve()\n",
|
||
|
"data_path = this_dir_path / \"Data\"\n",
|
||
|
"verb_path = data_path / \"PVC\" / \"Data\" / \"TXT\" / \"verb.txt\"\n",
|
||
|
"processed_past_verb_path = data_path / \"verbs_past_PVC.json\"\n",
|
||
|
"processed_present_verb_path = data_path / \"verbs_present_PVC.json\""
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"with open(verb_path, \"r\") as f:\n",
|
||
|
" lines = f.readlines()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"result: dict[str, list] = {}\n",
|
||
|
"for line in lines:\n",
|
||
|
" verb = line.split(\"@\")[0]\n",
|
||
|
" idx = line.split(\"@\")[1]\n",
|
||
|
" if isinstance(result.get(idx), list):\n",
|
||
|
" result[idx].append(verb)\n",
|
||
|
" else:\n",
|
||
|
" result[idx] = [verb]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"result_simple_past: dict[str, str] = {}\n",
|
||
|
"for line in lines:\n",
|
||
|
" if line.split(\"@\")[2:] == [\n",
|
||
|
" \"ACTIVE\",\n",
|
||
|
" \"SINGULAR\",\n",
|
||
|
" \"FIRST_PERSON\",\n",
|
||
|
" \"POSITIVE\",\n",
|
||
|
" \"م\",\n",
|
||
|
" \"PAST\",\n",
|
||
|
" \"INDICATIVE\",\n",
|
||
|
" \"SIMPLE\\n\",\n",
|
||
|
" ]:\n",
|
||
|
" result_simple_past[line.split(\"@\")[1]] = line.split(\"@\")[0]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"result_simple_past_list = {\n",
|
||
|
" key: value[:-1]\n",
|
||
|
" for key, value in sorted(result_simple_past.items(), key=lambda x: x[1])\n",
|
||
|
"}\n",
|
||
|
"with open(processed_past_verb_path, \"w\", encoding=\"utf-8\") as f:\n",
|
||
|
" json.dump(result_simple_past_list, f, ensure_ascii=False, indent=4)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"result_simple_present: dict[str, str] = {}\n",
|
||
|
"for line in lines:\n",
|
||
|
" if line.split(\"@\")[2:] == [\n",
|
||
|
" \"ACTIVE\",\n",
|
||
|
" \"SINGULAR\",\n",
|
||
|
" \"FIRST_PERSON\",\n",
|
||
|
" \"POSITIVE\",\n",
|
||
|
" \"م\",\n",
|
||
|
" \"PRESENT\",\n",
|
||
|
" \"INDICATIVE\",\n",
|
||
|
" \"SIMPLE\\n\",\n",
|
||
|
" ]:\n",
|
||
|
" result_simple_present[line.split(\"@\")[1]] = line.split(\"@\")[0]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"result_simple_present_list = {\n",
|
||
|
" key: value[:-1]\n",
|
||
|
" for key, value in sorted(result_simple_present.items(), key=lambda x: x[1])\n",
|
||
|
"}\n",
|
||
|
"with open(processed_present_verb_path, \"w\", encoding=\"utf-8\") as f:\n",
|
||
|
" json.dump(result_simple_present_list, f, ensure_ascii=False, indent=4)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": ".env",
|
||
|
"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.10.15"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|