From 6d1a5495369caf00cb12a7df54f3eb00a17034b7 Mon Sep 17 00:00:00 2001 From: Kornelia Girejko Date: Tue, 3 May 2022 20:59:50 +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 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 run.py diff --git a/run.py b/run.py new file mode 100644 index 0000000..94c2def --- /dev/null +++ b/run.py @@ -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') +