Prześlij pliki do ''
This commit is contained in:
parent
e5dd8a1bd8
commit
6d1a549536
53
run.py
Normal file
53
run.py
Normal file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# In[36]:
|
||||
|
||||
|
||||
import re
|
||||
|
||||
|
||||
# In[4]:
|
||||
|
||||
|
||||
states = ["Alaska", "Alabama", "Arkansas", "American Samoa", "Arizona", "California", "Colorado", "Connecticut", "District ", "of Columbia", "Delaware", "Florida", "Georgia", "Guam", "Hawaii", "Iowa", "Idaho", "Illinois", "Indiana", "Kansas", "Kentucky", "Louisiana", "Massachusetts", "Maryland", "Maine", "Michigan", "Minnesota", "Missouri", "Mississippi", "Montana", "North Carolina", "North Dakota", "Nebraska", "New Hampshire", "New Jersey", "New Mexico", "Nevada", "New York", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Virginia", "Virgin Islands", "Vermont", "Washington", "Wisconsin", "West Virginia", "Wyoming"]
|
||||
|
||||
|
||||
# In[23]:
|
||||
|
||||
|
||||
rgx = re.compile(r'\b(' + '|'.join(states) + r')\b')
|
||||
|
||||
|
||||
# In[41]:
|
||||
|
||||
|
||||
def nda(path_in, path_out):
|
||||
results = []
|
||||
with open(path_in, 'r', encoding='utf-8') as file:
|
||||
#removeAccents(path_in)
|
||||
for line in file.readlines():
|
||||
line = line.replace('.', ' ').replace(',', ' ').lower()
|
||||
words = line.split()
|
||||
jur = rgx.search(line)
|
||||
if jur:
|
||||
results.append('jurisdiction=' + jur.group().replace(' ', '_'))
|
||||
#else:
|
||||
# results.append('\n')
|
||||
date = re.findall(r'(\d+-\d+-\d+)',line)
|
||||
if date:
|
||||
results.append('effective_date=' + jur.group().replace(' ', '_'))
|
||||
results.append('\n')
|
||||
with open(path_out, 'w') as file:
|
||||
for r in results:
|
||||
file.write(r + '\n')
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
#pliki
|
||||
nda('dev-0/in.tsv', 'dev-0/out.tsv')
|
||||
nda('train/in.tsv', 'train/out.tsv')
|
||||
nda('test-A/in.tsv', 'test-A/out.tsv')
|
||||
|
Loading…
Reference in New Issue
Block a user