jurisdiction regex

This commit is contained in:
Kacper Dudzic 2022-04-22 22:25:21 +02:00
parent c2c7bf069b
commit 453ef7eb27
3 changed files with 319 additions and 0 deletions

83
dev-0/out.tsv Normal file
View File

@ -0,0 +1,83 @@
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=Delaware
jurisdiction=New_Jersey
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=Massachusetts
jurisdiction=Minnesota
jurisdiction=California
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=Iowa
jurisdiction=California
jurisdiction=Virginia
jurisdiction=North_Carolina
jurisdiction=Arizona
jurisdiction=Indiana
jurisdiction=New_Jersey
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Georgia
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=California
jurisdiction=Minnesota
jurisdiction=California
jurisdiction=Kentucky
jurisdiction=Minnesota
jurisdiction=Ohio
jurisdiction=Massachusetts
jurisdiction=California
jurisdiction=Minnesota
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Illinois
jurisdiction=Minnesota
jurisdiction=Texas
jurisdiction=New_Jersey
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=Georgia
jurisdiction=Delaware
jurisdiction=Oregon
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Massachusetts
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Illinois
jurisdiction=Idaho
jurisdiction=Washington
jurisdiction=California
jurisdiction=New_York
jurisdiction=California
jurisdiction=Utah
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=Virginia
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Illinois
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Texas
jurisdiction=California
jurisdiction=Washington
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=New_York
jurisdiction=Washington
jurisdiction=Illinois
1 jurisdiction=New_York
2 jurisdiction=New_York
3 jurisdiction=Delaware
4 jurisdiction=Delaware
5 jurisdiction=Delaware
6 jurisdiction=Washington
7 jurisdiction=Delaware
8 jurisdiction=New_Jersey
9 jurisdiction=New_York
10 jurisdiction=Delaware
11 jurisdiction=Delaware
12 jurisdiction=Delaware
13 jurisdiction=Delaware
14 jurisdiction=New_York
15 jurisdiction=Massachusetts
16 jurisdiction=Minnesota
17 jurisdiction=California
18 jurisdiction=New_York
19 jurisdiction=Delaware
20 jurisdiction=Iowa
21 jurisdiction=California
22 jurisdiction=Virginia
23 jurisdiction=North_Carolina
24 jurisdiction=Arizona
25 jurisdiction=Indiana
26 jurisdiction=New_Jersey
27 jurisdiction=California
28 jurisdiction=Delaware
29 jurisdiction=Georgia
30 jurisdiction=Delaware
31 jurisdiction=New_York
32 jurisdiction=California
33 jurisdiction=Minnesota
34 jurisdiction=California
35 jurisdiction=Kentucky
36 jurisdiction=Minnesota
37 jurisdiction=Ohio
38 jurisdiction=Massachusetts
39 jurisdiction=California
40 jurisdiction=Minnesota
41 jurisdiction=California
42 jurisdiction=Delaware
43 jurisdiction=Illinois
44 jurisdiction=Minnesota
45 jurisdiction=Texas
46 jurisdiction=New_Jersey
47 jurisdiction=Delaware
48 jurisdiction=Washington
49 jurisdiction=Georgia
50 jurisdiction=Delaware
51 jurisdiction=Oregon
52 jurisdiction=Delaware
53 jurisdiction=Delaware
54 jurisdiction=Delaware
55 jurisdiction=Massachusetts
56 jurisdiction=California
57 jurisdiction=Delaware
58 jurisdiction=Delaware
59 jurisdiction=Illinois
60 jurisdiction=Idaho
61 jurisdiction=Washington
62 jurisdiction=California
63 jurisdiction=New_York
64 jurisdiction=California
65 jurisdiction=Utah
66 jurisdiction=Delaware
67 jurisdiction=Washington
68 jurisdiction=Virginia
69 jurisdiction=New_York
70 jurisdiction=New_York
71 jurisdiction=Illinois
72 jurisdiction=California
73 jurisdiction=Delaware
74 jurisdiction=Texas
75 jurisdiction=California
76 jurisdiction=Washington
77 jurisdiction=Delaware
78 jurisdiction=Washington
79 jurisdiction=New_York
80 jurisdiction=Washington
81 jurisdiction=Illinois

33
run.py Normal file
View File

@ -0,0 +1,33 @@
import re
import sys
filename = sys.argv[1]
with open(filename, encoding='utf-8') as f_in, open('out.tsv', 'w', encoding='utf-8') as f_out:
for line in f_in:
cols = line.split('\t')
clean_col = re.sub(r'(\\n)|(\\f)|(\\t)|(\\)', ' ', cols[-1])
clean_col = re.sub('[^A-Za-z ]', ' ', clean_col)
clean_col = re.sub(' +', ' ', clean_col)
stateof2words = re.search('[sS]tate of [A-Z]\w+( \w+)?', clean_col)
if stateof2words:
stateof2words = stateof2words.group().split()
if stateof2words[2] in ['New', 'South', 'West', 'Rhode', 'North']:
f_out.write('jurisdiction=' + stateof2words[2] + '_' + stateof2words[3] + '\n')
else:
f_out.write('jurisdiction=' + stateof2words[2] + '\n')
else:
found = False
for word in ['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']:
if word in clean_col:
f_out.write('jurisdiction=' + word + '\n')
found = True
break
if not found:
f_out.write('\n')

203
test-A/out.tsv Normal file
View File

@ -0,0 +1,203 @@
jurisdiction=Ohio
jurisdiction=Delaware
jurisdiction=Louisiana
jurisdiction=New_York
jurisdiction=Nevada
jurisdiction=Colorado
jurisdiction=Colorado
jurisdiction=California
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=California
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=California
jurisdiction=Washington
jurisdiction=Victoria
jurisdiction=Florida
jurisdiction=Delaware
jurisdiction=Florida
jurisdiction=New_York
jurisdiction=California
jurisdiction=Florida
jurisdiction=New_York
jurisdiction=Washington
jurisdiction=Texas
jurisdiction=Delaware
jurisdiction=Georgia
jurisdiction=Washington
jurisdiction=Delaware
jurisdiction=Nevada
jurisdiction=California
jurisdiction=California
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=New York
jurisdiction=Delaware
jurisdiction=Florida
jurisdiction=California
jurisdiction=Virginia
jurisdiction=Pennsylvania
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=California
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=New_Jersey
jurisdiction=California
jurisdiction=Texas
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=Pennsylvania
jurisdiction=California
jurisdiction=Georgia
jurisdiction=Delaware
jurisdiction=Delaware
jurisdiction=Massachusetts
jurisdiction=Connecticut
jurisdiction=California
jurisdiction=Texas
jurisdiction=Delaware
jurisdiction=Virginia
jurisdiction=Delaware
jurisdiction=Washington
jurisdiction=Minnesota
jurisdiction=Oregon
jurisdiction=Texas
jurisdiction=Colorado
jurisdiction=Colorado
jurisdiction=Nevada
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=Illinois
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Florida
jurisdiction=Virginia
jurisdiction=New_York
jurisdiction=Nevada
jurisdiction=Delaware
jurisdiction=New_Jersey
jurisdiction=North_Carolina
jurisdiction=Minnesota
jurisdiction=Connecticut
jurisdiction=North_Carolina
jurisdiction=Kansas
jurisdiction=Florida
jurisdiction=Washington
jurisdiction=Oregon
jurisdiction=New_York
jurisdiction=Georgia
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=Colorado
jurisdiction=California
jurisdiction=Tennessee
jurisdiction=Ohio
jurisdiction=Minnesota
jurisdiction=Delaware
jurisdiction=California
jurisdiction=Connecticut
jurisdiction=Maryland
jurisdiction=Delaware
jurisdiction=Utah
jurisdiction=California
jurisdiction=Utah
jurisdiction=Colorado
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=California
jurisdiction=New_York
jurisdiction=Virginia
jurisdiction=Delaware
jurisdiction=Texas
jurisdiction=Massachusetts
jurisdiction=Colorado
jurisdiction=New_York
jurisdiction=Michigan
jurisdiction=Pennsylvania
jurisdiction=Japan
jurisdiction=New_Jersey
jurisdiction=New_York
jurisdiction=Minnesota
jurisdiction=Ohio
jurisdiction=Oregon
jurisdiction=New_Jersey
jurisdiction=Florida
jurisdiction=Oregon
jurisdiction=Massachusetts
jurisdiction=Ohio
jurisdiction=Minnesota
jurisdiction=Maryland
jurisdiction=Indiana
jurisdiction=California
jurisdiction=Virginia
jurisdiction=Tennessee
jurisdiction=Delaware
jurisdiction=Maryland
jurisdiction=Pennsylvania
jurisdiction=Ohio
jurisdiction=California
jurisdiction=New_Jersey
jurisdiction=Colorado
jurisdiction=Indiana
jurisdiction=Virginia
jurisdiction=Minnesota
jurisdiction=New York
jurisdiction=Delaware
jurisdiction=New_York
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Louisiana
jurisdiction=Georgia
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Oregon
jurisdiction=Nevada
jurisdiction=California
jurisdiction=North_Carolina
jurisdiction=California
jurisdiction=Georgia
jurisdiction=California
jurisdiction=New_York
jurisdiction=New_York
jurisdiction=Indiana
jurisdiction=Georgia
jurisdiction=New_Jersey
jurisdiction=Minnesota
jurisdiction=North_Carolina
jurisdiction=Georgia
jurisdiction=Kentucky
jurisdiction=Nevada
jurisdiction=Missouri
jurisdiction=Colorado
jurisdiction=Connecticut
jurisdiction=Delaware
jurisdiction=North_Carolina
jurisdiction=California
jurisdiction=Georgia
jurisdiction=California
jurisdiction=New_York
jurisdiction=Pennsylvania
jurisdiction=California
jurisdiction=Maryland
jurisdiction=California
jurisdiction=Delaware
jurisdiction=Pennsylvania
jurisdiction=New_York
jurisdiction=Delaware
jurisdiction=Virginia
jurisdiction=Delaware
jurisdiction=Nevada
jurisdiction=Nevada
jurisdiction=Delaware
jurisdiction=California
jurisdiction=Colorado
1 jurisdiction=Ohio
2 jurisdiction=Delaware
3 jurisdiction=Louisiana
4 jurisdiction=New_York
5 jurisdiction=Nevada
6 jurisdiction=Colorado
7 jurisdiction=Colorado
8 jurisdiction=California
9 jurisdiction=Delaware
10 jurisdiction=New_York
11 jurisdiction=California
12 jurisdiction=Delaware
13 jurisdiction=New_York
14 jurisdiction=New_York
15 jurisdiction=Delaware
16 jurisdiction=California
17 jurisdiction=Washington
18 jurisdiction=Victoria
19 jurisdiction=Florida
20 jurisdiction=Delaware
21 jurisdiction=Florida
22 jurisdiction=New_York
23 jurisdiction=California
24 jurisdiction=Florida
25 jurisdiction=New_York
26 jurisdiction=Washington
27 jurisdiction=Texas
28 jurisdiction=Delaware
29 jurisdiction=Georgia
30 jurisdiction=Washington
31 jurisdiction=Delaware
32 jurisdiction=Nevada
33 jurisdiction=California
34 jurisdiction=California
35 jurisdiction=New_York
36 jurisdiction=New_York
37 jurisdiction=New York
38 jurisdiction=Delaware
39 jurisdiction=Florida
40 jurisdiction=California
41 jurisdiction=Virginia
42 jurisdiction=Pennsylvania
43 jurisdiction=Delaware
44 jurisdiction=Washington
45 jurisdiction=California
46 jurisdiction=California
47 jurisdiction=Delaware
48 jurisdiction=Delaware
49 jurisdiction=New_Jersey
50 jurisdiction=California
51 jurisdiction=Texas
52 jurisdiction=Delaware
53 jurisdiction=Washington
54 jurisdiction=New_York
55 jurisdiction=Delaware
56 jurisdiction=New_York
57 jurisdiction=Pennsylvania
58 jurisdiction=California
59 jurisdiction=Georgia
60 jurisdiction=Delaware
61 jurisdiction=Delaware
62 jurisdiction=Massachusetts
63 jurisdiction=Connecticut
64 jurisdiction=California
65 jurisdiction=Texas
66 jurisdiction=Delaware
67 jurisdiction=Virginia
68 jurisdiction=Delaware
69 jurisdiction=Washington
70 jurisdiction=Minnesota
71 jurisdiction=Oregon
72 jurisdiction=Texas
73 jurisdiction=Colorado
74 jurisdiction=Colorado
75 jurisdiction=Nevada
76 jurisdiction=New_York
77 jurisdiction=Delaware
78 jurisdiction=Illinois
79 jurisdiction=New_York
80 jurisdiction=New_York
81 jurisdiction=Florida
82 jurisdiction=Virginia
83 jurisdiction=New_York
84 jurisdiction=Nevada
85 jurisdiction=Delaware
86 jurisdiction=New_Jersey
87 jurisdiction=North_Carolina
88 jurisdiction=Minnesota
89 jurisdiction=Connecticut
90 jurisdiction=North_Carolina
91 jurisdiction=Kansas
92 jurisdiction=Florida
93 jurisdiction=Washington
94 jurisdiction=Oregon
95 jurisdiction=New_York
96 jurisdiction=Georgia
97 jurisdiction=Delaware
98 jurisdiction=New_York
99 jurisdiction=Colorado
100 jurisdiction=California
101 jurisdiction=Tennessee
102 jurisdiction=Ohio
103 jurisdiction=Minnesota
104 jurisdiction=Delaware
105 jurisdiction=California
106 jurisdiction=Connecticut
107 jurisdiction=Maryland
108 jurisdiction=Delaware
109 jurisdiction=Utah
110 jurisdiction=California
111 jurisdiction=Utah
112 jurisdiction=Colorado
113 jurisdiction=New_York
114 jurisdiction=Delaware
115 jurisdiction=California
116 jurisdiction=New_York
117 jurisdiction=Virginia
118 jurisdiction=Delaware
119 jurisdiction=Texas
120 jurisdiction=Massachusetts
121 jurisdiction=Colorado
122 jurisdiction=New_York
123 jurisdiction=Michigan
124 jurisdiction=Pennsylvania
125 jurisdiction=Japan
126 jurisdiction=New_Jersey
127 jurisdiction=New_York
128 jurisdiction=Minnesota
129 jurisdiction=Ohio
130 jurisdiction=Oregon
131 jurisdiction=New_Jersey
132 jurisdiction=Florida
133 jurisdiction=Oregon
134 jurisdiction=Massachusetts
135 jurisdiction=Ohio
136 jurisdiction=Minnesota
137 jurisdiction=Maryland
138 jurisdiction=Indiana
139 jurisdiction=California
140 jurisdiction=Virginia
141 jurisdiction=Tennessee
142 jurisdiction=Delaware
143 jurisdiction=Maryland
144 jurisdiction=Pennsylvania
145 jurisdiction=Ohio
146 jurisdiction=California
147 jurisdiction=New_Jersey
148 jurisdiction=Colorado
149 jurisdiction=Indiana
150 jurisdiction=Virginia
151 jurisdiction=Minnesota
152 jurisdiction=New York
153 jurisdiction=Delaware
154 jurisdiction=New_York
155 jurisdiction=California
156 jurisdiction=Delaware
157 jurisdiction=Louisiana
158 jurisdiction=Georgia
159 jurisdiction=New_York
160 jurisdiction=New_York
161 jurisdiction=Oregon
162 jurisdiction=Nevada
163 jurisdiction=California
164 jurisdiction=North_Carolina
165 jurisdiction=California
166 jurisdiction=Georgia
167 jurisdiction=California
168 jurisdiction=New_York
169 jurisdiction=New_York
170 jurisdiction=Indiana
171 jurisdiction=Georgia
172 jurisdiction=New_Jersey
173 jurisdiction=Minnesota
174 jurisdiction=North_Carolina
175 jurisdiction=Georgia
176 jurisdiction=Kentucky
177 jurisdiction=Nevada
178 jurisdiction=Missouri
179 jurisdiction=Colorado
180 jurisdiction=Connecticut
181 jurisdiction=Delaware
182 jurisdiction=North_Carolina
183 jurisdiction=California
184 jurisdiction=Georgia
185 jurisdiction=California
186 jurisdiction=New_York
187 jurisdiction=Pennsylvania
188 jurisdiction=California
189 jurisdiction=Maryland
190 jurisdiction=California
191 jurisdiction=Delaware
192 jurisdiction=Pennsylvania
193 jurisdiction=New_York
194 jurisdiction=Delaware
195 jurisdiction=Virginia
196 jurisdiction=Delaware
197 jurisdiction=Nevada
198 jurisdiction=Nevada
199 jurisdiction=Delaware
200 jurisdiction=California
201 jurisdiction=Colorado