63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# In[17]:
|
|
|
|
|
|
import re
|
|
|
|
|
|
# In[5]:
|
|
|
|
|
|
states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia',
|
|
'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland',
|
|
'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey',
|
|
'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina',
|
|
'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']
|
|
|
|
|
|
# In[6]:
|
|
|
|
|
|
def counter(text_in, query):
|
|
pattern = re.compile(query)
|
|
return len(pattern.findall(text_in, re.IGNORECASE))
|
|
|
|
|
|
# In[7]:
|
|
|
|
|
|
def state_prediction(text_in):
|
|
state_dict = {}
|
|
for state in states:
|
|
state_dict[state.replace(" ", "_")] = counter(text_in, state)
|
|
return max(state_dict, key=state_dict.get)
|
|
|
|
|
|
# In[20]:
|
|
|
|
|
|
def jurisdiction(path_in, path_out):
|
|
with open(path_in, 'r', encoding='utf8') as file:
|
|
lines = file.readlines()
|
|
with open(path_out, 'wt')as file_out:
|
|
for i in lines:
|
|
file_out.write("jurisdiction="+str(state_prediction(i))+'\n')
|
|
file_out.close()
|
|
|
|
|
|
# In[21]:
|
|
|
|
|
|
jurisdiction('dev-0/in.tsv', 'dev-0/out.tsv')
|
|
jurisdiction('train/in.tsv', 'train/out.tsv')
|
|
jurisdiction('test-A/in.tsv', 'test-A/out.tsv')
|
|
|
|
|
|
# In[ ]:
|
|
|
|
|
|
# get_ipython().system('jupyter nbconvert --to script run.ipynb')
|
|
|