2022-05-03 23:59:27 +02:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 56,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "8b07c9a5-e5cf-4cf9-a6d9-e784eb109fef",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"import re"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 57,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "fce94c21-6792-4938-bf2c-3f46ecf2f954",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', \n",
|
2022-05-04 01:30:25 +02:00
|
|
|
" 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', \n",
|
|
|
|
" 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', \n",
|
|
|
|
" 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Pennsylvania', 'Rhode Island', 'South Carolina', \n",
|
2022-05-03 23:59:27 +02:00
|
|
|
" 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 58,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "eb1815f2-1876-4437-833a-ff22de81685e",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"def counter(text_in, query):\n",
|
|
|
|
" pattern = re.compile(query)\n",
|
|
|
|
" return len(pattern.findall(text_in, re.IGNORECASE))"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 59,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "8729062d-87b8-4111-a216-8500334f54b6",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"def state_prediction(text_in):\n",
|
|
|
|
" state_dict = {}\n",
|
|
|
|
" for state in states:\n",
|
|
|
|
" state_dict[state.replace(\" \", \"_\")] = counter(text_in, state) \n",
|
2022-05-04 01:35:27 +02:00
|
|
|
" return max(state_dict, key=state_dict.get)"
|
2022-05-03 23:59:27 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 60,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "ea8069f7-de8e-454c-8eac-9fb7cc0df626",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"def jurisdiction(path_in, path_out): \n",
|
|
|
|
" with open(path_in, 'r', encoding='utf8') as file:\n",
|
2022-05-04 00:06:07 +02:00
|
|
|
" lines = file.readlines()\n",
|
2022-05-03 23:59:27 +02:00
|
|
|
" with open(path_out, 'wt')as file_out:\n",
|
|
|
|
" for i in lines:\n",
|
|
|
|
" file_out.write(\"jurisdiction=\"+str(state_prediction(i))+'\\n') \n",
|
|
|
|
" file_out.close()"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 61,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "ade45bfb-9eaa-4b2b-bba1-6cfcaf0a9ce6",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"jurisdiction('dev-0/in.tsv', 'dev-0/out.tsv')\n",
|
|
|
|
"jurisdiction('train/in.tsv', 'train/out.tsv')\n",
|
|
|
|
"jurisdiction('test-A/in.tsv', 'test-A/out.tsv')"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2022-05-04 01:35:27 +02:00
|
|
|
"execution_count": 62,
|
2022-05-03 23:59:27 +02:00
|
|
|
"id": "594a25a9-a0ce-4de9-82c8-df50a4ecac39",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stderr",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"[NbConvertApp] Converting notebook run.ipynb to script\n",
|
2022-05-04 01:35:27 +02:00
|
|
|
"[NbConvertApp] Writing 1605 bytes to run.py\n"
|
2022-05-03 23:59:27 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"!jupyter nbconvert --to script run.ipynb"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"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.9.7"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|