{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "import re" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', \n", " 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', \n", " 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', \n", " 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', \n", " 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "def count_strings(input, str_):\n", " pattern = re.compile(str_)\n", " return len(pattern.findall(input, re.IGNORECASE))" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "def predict_state(text):\n", " # Predict state of jurisdiction\n", " state_dict = {}\n", " for state in states:\n", " state_dict[state.replace(\" \", \"_\")] = count_strings(text, state)\n", "\n", " return max(state_dict, key=state_dict.get)" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "with open('dev-0/in.tsv', 'r', encoding='utf8') as f:\n", " dev0_x = f.readlines()\n", "\n", "with open('dev-0/out.tsv', 'wt') as f:\n", " for x in dev0_x:\n", " f.write(\"jurisdiction=\"+str(predict_state(x))+'\\n')\n", "\n", "f.close()\n", "\n", "\n", "with open('train/in.tsv', 'r', encoding='utf8') as f:\n", " train_x = f.readlines()\n", "\n", "with open('train/out.tsv', 'wt') as f:\n", " for x in train_x:\n", " f.write(\"jurisdiction=\"+str(predict_state(x))+'\\n')\n", "\n", "f.close()\n", "\n", "\n", "with open('test-A/in.tsv', 'r', encoding='utf8') as f:\n", " testA_x = f.readlines()\n", "\n", "with open('test-A/out.tsv', 'wt') as f:\n", " for x in testA_x:\n", " f.write(\"jurisdiction=\"+str(predict_state(x))+'\\n')\n", "\n", "f.close()" ] } ], "metadata": { "interpreter": { "hash": "df93b008b708122b991044997d8941ca5d5845b048d54848454a010a3b0bd41a" }, "kernelspec": { "display_name": "Python 3.8.13 ('eks')", "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.8.13" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }