From b6ed93e25e82102f5f981085c0562dafe7aa465a Mon Sep 17 00:00:00 2001 From: Kornelia Girejko Date: Wed, 4 May 2022 15:50:06 +0200 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 run.py diff --git a/run.py b/run.py new file mode 100644 index 0000000..4aa503a --- /dev/null +++ b/run.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + + +import re +from datetime import datetime +import csv + + +# In[9]: + + +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[84]: + + +rgx = re.compile(r'\b(' + '|'.join(states) + r')\b') +company_rgx = r"(([A-Z][A-za-z]+,?\s)+(Inc\.|LLC|Ltd\.|Company|Corporation|INC\.|LTD\.|COMPANY|CORPORATION))" + + +# In[93]: + + +def nda(path_in, path_out): + with open(path_in, 'r', encoding='utf-8') as in_file: + lines = in_file.readlines() + with open(path_out, 'w') as out_file: + for line in lines: + #line = line.replace('.', ' ').replace(',', ' ').lower() + #words = line.split() + jur = rgx.search(line) + #print(jur) + if jur: + out_file.write('jurisdiction=' + jur.group().replace(' ', '_')) + + + res = re.search(r'\d{4}-\d{2}-\d{2}',line) + #print(res) + if res: + date = datetime.strptime(res.group(), '%Y-%m-%d').date() + print(str(date)) + out_file.write('effective_date=' + date.group().replace(' ', '_')) + + #party_results = [] + #party = re.findall(company_rgx, line) + #party_score = len([w for w in party if w in party]) + #if party_score > 2: + # party_results.append(party[0]) + par = re.search(company_rgx,line) + #print(par) + if par: + out_file.write(' party=' + par.group().replace(','' ', '_')) + out_file.write('\n') + + + +# In[94]: + + +#pliki +nda('train/in.tsv', 'train/out.tsv') +nda('dev-0/in.tsv', 'dev-0/out.tsv') +nda('test-A/in.tsv', 'test-A/out.tsv') + + +# In[ ]: + + + +