Anton Boltachka commited on
Commit
90f0980
1 Parent(s): 56b7edf

Add application file

Browse files
Files changed (1) hide show
  1. app.py +565 -0
app.py ADDED
@@ -0,0 +1,565 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #$git clone https://huggingface.co/spaces/aboltachka/rr_detector
2
+
3
+ #####################
4
+ # IMPORT PACKAGES
5
+ #####################
6
+
7
+ import gradio as gr
8
+ import pandas as pd
9
+ import re
10
+ import os
11
+ dirname = os.path.dirname(__file__)
12
+
13
+ #####################
14
+ # ALGORITHM SETUP
15
+ #####################
16
+
17
+ group_control = [('control',0,re.compile(r'\bminimum wage\b')),
18
+ ('control',1,re.compile(r'\bcrime[a-zA-Z]{0,7}\b')),
19
+ ('control',2,re.compile(r'\bimmigra[a-zA-Z]{0,4}\b')),
20
+ ('control',3,re.compile(r'\bmigra[a-zA-Z]{0,4}\b')),
21
+ ('control',4,re.compile(r'\bsingle mother[a-zA-Z]{0,1}\b')),
22
+ ('control',5,re.compile(r'\blone mother[a-zA-Z]{0,1}\b')),
23
+ ('control',6,re.compile(r'\bone parent[a-zA-Z]{0,3}\b')),
24
+ ('control',7,re.compile(r'\blone parent[a-zA-Z]{0,3}\b')),
25
+ ('control',8,re.compile(r'\bsingle parent[a-zA-Z]{0,3}\b')), #change from {0,1} to {0,3} for parenting
26
+ ('control',9,re.compile(r'\bsingle headed\b')),
27
+ ('control',10,re.compile(r'\blone headed\b')),
28
+ ('control',11,re.compile(r'\bsingle headed\b')),
29
+ ('control',12,re.compile(r'\blone headed\b')),
30
+ ('control',13,re.compile(r'\bdoctor\b')),
31
+ ('control',14,re.compile(r'\bphysician\b')),
32
+ ('control',15,re.compile(r'\bself-employed\b')),
33
+ ('control',16,re.compile(r'\bentrepreneur\b')),]
34
+
35
+ group_issue = [('issue',0,re.compile(r'\bdiscriminat[a-zA-Z]{0,5}\b')), # changed from {0,4} to {0,5}, e/g Discriminatively
36
+ ('issue',1,re.compile(r'\bprejudi[a-zA-Z]{0,4}\b')), # changed from {0,3} to {0,4}, e/g Prejudicing
37
+ ('issue',2,re.compile(r'\brac[a-zA-Z]{0,3} bias[a-zA-Z]{0,3}\b')),
38
+ ('issue',3,re.compile(r'\brac[a-zA-Z]{0,3} disparit[a-zA-Z]{0,3}\b')),
39
+ ('issue',4,re.compile(r'\brac[a-zA-Z]{0,3} stereotyp[a-zA-Z]{0,3}\b')),
40
+ ('issue',5,re.compile(r'\breconstruction[a-zA-Z]{0,1}\b')),
41
+ ('issue',6,re.compile(r'\bdesegregat[a-zA-Z]{0,3}\b')),
42
+ ('issue',7,re.compile(r'\bjim crow\b')),
43
+ ('issue',8,re.compile(r'\blynch[a-zA-Z]{0,5}\b')), # changed from {0,3} to {0,5}, e/g lynchings
44
+ ('issue',9,re.compile(r'\bwhitecapping\b')),
45
+ ('issue',10,re.compile(r'\bcivil rights\b')),
46
+ ('issue',11,re.compile(r'\brace riot[a-zA-Z]{0,3}\b')),
47
+ ('issue',12,re.compile(r'\bemancipat[a-zA-Z]{0,3}\b')),
48
+ ('issue',13,re.compile(r'\bslave[a-zA-Z]{0,2}\b')),
49
+ ('issue',14,re.compile(r'\brace relation[a-zA-Z]{0,1}\b')),
50
+ ('issue',15,re.compile(r'\bstatistical discrimination[a-zA-Z]{0,1}\b')),
51
+ ('issue',16,re.compile(r'\banimus\b')),
52
+ ('issue',17,re.compile(r'\banimosit[a-zA-Z]{0,3}\b')),
53
+ ('issue',18,re.compile(r'\bsegregat[a-zA-Z]{0,3}\b')),
54
+ ('issue',19,re.compile(r'\brac[a-zA-Z]{0,3} identit[a-zA-Z]{0,3}\b')),
55
+ ('issue',21,re.compile(r'\beugenics\b')),
56
+ ('issue',22,re.compile(r'\brac[a-zA-Z]{0,3} profiling\b')),
57
+ ('issue',23,re.compile(r'\baffirmative action[a-zA-Z]{0,1}\b')),
58
+ ('issue',24,re.compile(r'\btipping point\b')),
59
+ ('issue',25,re.compile(r'\bblack-white\b')),
60
+ ('issue',26,re.compile(r'\brac[a-zA-Z]{0,3} gap[a-zA-Z]{0,1}\b')),
61
+ ('issue',27,re.compile(r'\brac[a-zA-Z]{0,3} differen[a-zA-Z]{0,4}\b')),
62
+ ('issue',28,re.compile(r'\brac[a-zA-Z]{0,3} composition[a-zA-Z]{0,1}\b')),
63
+ ('issue',29,re.compile(r'\brac[a-zA-Z]{0,3} integration[a-zA-Z]{0,1}\b')),
64
+ ('issue',30,re.compile(r'\brac[a-zA-Z]{0,3} interact[a-zA-Z]{0,4}\b')),
65
+ ('issue',31,re.compile(r'\brac[a-zA-Z]{0,3} inequalit[a-zA-Z]{0,3}\b')),
66
+ ('issue',33,re.compile(r'\bnegro-white\b')),
67
+ ('issue',34,re.compile(r'\banti-discrimination\b')),
68
+ ('issue',35,re.compile(r'\bantidiscrimination\b')),
69
+ ('issue',37,re.compile(r'\bethnic bias[a-zA-Z]{0,3}\b')),
70
+ ('issue',38,re.compile(r'\bethnic disparit[a-zA-Z]{0,3}\b')),
71
+ ('issue',39,re.compile(r'\bethnic stereotyp[a-zA-Z]{0,3}\b')),
72
+ ('issue',40,re.compile(r'\bethnic gap[a-zA-Z]{0,1}\b')),
73
+ ('issue',41,re.compile(r'\bethnic differen[a-zA-Z]{0,4}\b')),
74
+ ('issue',42,re.compile(r'\bethnic composition[a-zA-Z]{0,1}\b')),
75
+ ('issue',43,re.compile(r'\bethnic integration[a-zA-Z]{0,1}\b')),
76
+ ('issue',44,re.compile(r'\bethnic interact[a-zA-Z]{0,4}\b')),
77
+ ('issue',45,re.compile(r'\bethnic inequalit[a-zA-Z]{0,3}\b')),
78
+ ('issue',46,re.compile(r'\bpostbellum\b')),
79
+ ('issue',47,re.compile(r'\bdisadvantage\b')),
80
+ ('issue',48,re.compile(r'\bdisadvantaged\b')),
81
+ ('issue',49,re.compile(r'\battitude[a-zA-Z]{0,1}\b')),
82
+ ('issue',50,re.compile(r'\bgap[a-zA-Z]{0,1}\b')),
83
+ ('issue',51,re.compile(r'\bapartheid\b')),
84
+ ('issue',52,re.compile(r'\brepresentation\b')),
85
+ ('issue',53,re.compile(r'\bantisemitism\b')),
86
+ ('issue',54,re.compile(r'\banti-semitic\b')),
87
+ ('issue',55,re.compile(r'\banti-black\b')),
88
+ ('issue',56,re.compile(r'\bidentity\b')),
89
+ ('issue',57,re.compile(r'\bidentities\b')),
90
+ ('issue',58,re.compile(r'\bsouthern farm\b')),
91
+ ('issue',59,re.compile(r'\bracial heterogene[a-zA-Z]{0,5}\b')),
92
+ ('issue',60,re.compile(r'\bethnic heterogene[a-zA-Z]{0,5}\b')),
93
+ ('issue',61,re.compile(r'\bacting white\b')),
94
+ ('issue',62,re.compile(r'\baffirmative-action[a-zA-Z]{0,1}\b')),
95
+ ('issue',63,re.compile(r'\bhatred\b')),
96
+ ('issue',64,re.compile(r'\bsocial activis[a-zA-Z]{0,1}\b')),
97
+ ('issue',65,re.compile(r'\bsocial-activis[a-zA-Z]{0,1}\b')),
98
+ ('issue',66,re.compile(r'\bethnic fragmentation[a-zA-Z]{0,1}\b')),
99
+ ('issue',67,re.compile(r'\bethnic-fragmentation[a-zA-Z]{0,1}\b')),
100
+ ('issue',68,re.compile(r'\bsocial fragmentation[a-zA-Z]{0,1}\b')),
101
+ ('issue',69,re.compile(r'\bsocial-fragmentation[a-zA-Z]{0,1}\b')),
102
+ ('issue',70,re.compile(r'\bracial fragmentation[a-zA-Z]{0,1}\b')),
103
+ ('issue',71,re.compile(r'\bracial-fragmentation[a-zA-Z]{0,1}\b')),
104
+ ('issue',72,re.compile(r'\bethnic division[a-zA-Z]{0,1}\b')),
105
+ ('issue',73,re.compile(r'\bethnic-division[a-zA-Z]{0,1}\b')),
106
+ ('issue',74,re.compile(r'\bsocial division[a-zA-Z]{0,1}\b')),
107
+ ('issue',75,re.compile(r'\bsocial-division[a-zA-Z]{0,1}\b')),
108
+ ('issue',76,re.compile(r'\bracial division[a-zA-Z]{0,1}\b')),
109
+ ('issue',77,re.compile(r'\bracial-division[a-zA-Z]{0,1}\b')),
110
+ ('issue',78,re.compile(r'\bethnic exclusion[a-zA-Z]{0,1}\b')),
111
+ ('issue',79,re.compile(r'\bethnic-exclusion[a-zA-Z]{0,1}\b')),
112
+ ('issue',80,re.compile(r'\bsocial exclusion[a-zA-Z]{0,1}\b')),
113
+ ('issue',81,re.compile(r'\bsocial-exclusion[a-zA-Z]{0,1}\b')),
114
+ ('issue',82,re.compile(r'\bracial exclusion[a-zA-Z]{0,1}\b')),
115
+ ('issue',83,re.compile(r'\bracial-exclusion[a-zA-Z]{0,1}\b')),
116
+ ('issue',84,re.compile(r'\bethnic diversity\b')),
117
+ ('issue',85,re.compile(r'\bethnic-diversity\b')),
118
+ ('issue',86,re.compile(r'\bsocial diversity\b')),
119
+ ('issue',87,re.compile(r'\bsocial-diversity\b')),
120
+ ('issue',88,re.compile(r'\bracial diversity\b')),
121
+ ('issue',89,re.compile(r'\bracial-diversity\b')),
122
+ ('issue',90,re.compile(r'\bthe great migration\b')),
123
+ ('issue',91,re.compile(r'\bblack youth[a-zA-Z]{0,1}\b')),
124
+ ('issue',92,re.compile(r'\bblack‐white\b')),
125
+ ('issue',93,re.compile(r'\b-group bias\b')),
126
+ ('issue',94,re.compile(r'\btuskegee\b')),
127
+ ('issue',95,re.compile(r'\bingroup\b')),
128
+ ('issue',96,re.compile(r'\bin-group\b')),
129
+ ('issue',97,re.compile(r'\boutgroup\b')),
130
+ ('issue',98,re.compile(r'\bout-group\b')),
131
+ ('issue',99,re.compile(r'\binter-group\b')),
132
+ ('issue',100,re.compile(r'\bintergroup\b')),
133
+ ('issue',101,re.compile(r'\binequality\b')),
134
+ ('issue',102,re.compile(r'\bstratification\b')),
135
+ ('issue',103,re.compile(r'\bimplicit bias[a-zA-Z]{0,2}\b')),
136
+ ('issue',104,re.compile(r'\bblack vot[a-zA-Z]{0,3}\b')),
137
+ ('issue',105,re.compile(r'\bpolitical disenfranchisement\b')),
138
+ ('issue',106,re.compile(r'\binstitutional discrimination\b')),
139
+ ('issue',107,re.compile(r'\bstructural discrimination\b')),
140
+ ('issue',108,re.compile(r'\binstitutional racism\b')),
141
+ ('issue',109,re.compile(r'\bsystemic racism\b')),
142
+ ('issue',110,re.compile(r'\bdifferential\b')),
143
+ ('issue',111,re.compile(r'\b-differential\b')),
144
+ ('issue',112,re.compile(r'\bunderrepresent[a-zA-Z]{0,3}\b')),
145
+ ('issue',113,re.compile(r'\bexploitation\b')),
146
+ ('issue',114,re.compile(r'\boppress[a-zA-Z]{0,3}\b')),
147
+ ('issue',115, re.compile(r'\bschool[a-zA-Z]{0,3}\b')),
148
+ ('issue',116, re.compile(r'\beducat[a-zA-Z]{0,5}\b')),
149
+ ('issue',117, re.compile(r'\bdevelopment\b')),
150
+ ('issue',118, re.compile(r'\bpoverty\b')),
151
+ ('issue',119, re.compile(r'\bliving standard\b')),
152
+ ('issue',120, re.compile(r'\bwelfare\b'))]
153
+
154
+ group_ethnicity = [('ethnicity',0,re.compile(r'\brac[a-zA-Z]{0,3}\b')),
155
+ ('ethnicity',1,re.compile(r'\bafrican-american[a-zA-Z]{0,1}\b')),
156
+ ('ethnicity',2,re.compile(r'\bafrican american[a-zA-Z]{0,1}\b')),
157
+ ('ethnicity',3,re.compile(r'\bperson[a-zA-Z]{0,1} of color[a-zA-Z]{0,1}\b')),
158
+ ('ethnicity',4,re.compile(r'\bethnic[a-zA-Z]{0,4}\b')),
159
+ ('ethnicity',5,re.compile(r'\bhispanic[a-zA-Z]{0,1}\b')),
160
+ ('ethnicity',6,re.compile(r'\blatino[a-zA-Z]{0,1}\b')),
161
+ ('ethnicity',7,re.compile(r'\bblack[a-zA-Z]{0,1}\b')),
162
+ #('ethnicity',8,re.compile(r'\bwhite[s]{0,1}\b')),
163
+ ('ethnicity',11,re.compile(r'\bnegro[a-zA-Z]{0,2}\b')),
164
+ ('ethnicity',15,re.compile(r'\bsouth asian[a-zA-Z]{0,1}\b')),
165
+ ('ethnicity',17,re.compile(r'\bunderrepresented minorit[a-zA-Z]{0,3}\b')),
166
+ ('ethnicity',18,re.compile(r'\bethnic minorit[a-zA-Z]{0,3}\b')),
167
+ ('ethnicity',21,re.compile(r'\bblack-american[a-zA-Z]{0,1}\b')),
168
+ ('ethnicity',22,re.compile(r'\bindian-american[a-zA-Z]{0,1}\b')),
169
+ ('ethnicity',23,re.compile(r'\bjapanese-american[a-zA-Z]{0,1}\b')),
170
+ ('ethnicity',24,re.compile(r'\bchinese-american[a-zA-Z]{0,1}\b')),
171
+ ('ethnicity',25,re.compile(r'\bmexican-american[a-zA-Z]{0,1}\b')),
172
+ ('ethnicity',26,re.compile(r'\bhispanic-american[a-zA-Z]{0,1}\b')),
173
+ ('ethnicity',27,re.compile(r'\blatino-american[a-zA-Z]{0,1}\b')),
174
+ ('ethnicity',28,re.compile(r'\bnative-american[a-zA-Z]{0,1}\b')),
175
+ ('ethnicity',29,re.compile(r'\bamerican-indian[a-zA-Z]{0,1}\b')),
176
+ ('ethnicity',30,re.compile(r'\borientals\b')),
177
+ ('ethnicity',32,re.compile(r'\bkorean-american[a-zA-Z]{0,1}\b')),
178
+ ('ethnicity',34,re.compile(r'\bvietnamese-american[a-zA-Z]{0,1}\b')),
179
+ ('ethnicity',35,re.compile(r'\bnon-white[a-zA-Z]{0,1}\b')),
180
+ ('ethnicity',36,re.compile(r'\bcolored[a-zA-Z]{0,1}\b')),
181
+ ('ethnicity',37,re.compile(r'\bcaste[a-zA-Z]{0,1}\b')),
182
+ ('ethnicity',38,re.compile(r'\bdisadvantaged minor[a-zA-Z]{0,5}\b')),
183
+ ('ethnicity',39,re.compile(r'\badvantaged-group[a-zA-Z]{0,1}\b')),
184
+ ('ethnicity',40,re.compile(r'\badvantaged group[a-zA-Z]{0,1}\b')),
185
+ ('ethnicity',41,re.compile(r'\bdominant group[a-zA-Z]{0,1}\b')),
186
+ ('ethnicity',42,re.compile(r'\bdominant-group[a-zA-Z]{0,1}\b')),
187
+ ('ethnicity',43,re.compile(r'\bnon-western[a-zA-Z]{0,1}\b')),
188
+ ('ethnicity',44,re.compile(r'\bblack american[a-zA-Z]{0,1}\b')),
189
+ ('ethnicity',45,re.compile(r'\bindian american[a-zA-Z]{0,1}\b')),
190
+ ('ethnicity',46,re.compile(r'\bjapanese american[a-zA-Z]{0,1}\b')),
191
+ ('ethnicity',47,re.compile(r'\bchinese american[a-zA-Z]{0,1}\b')),
192
+ ('ethnicity',48,re.compile(r'\bmexican american[a-zA-Z]{0,1}\b')),
193
+ ('ethnicity',49,re.compile(r'\bhispanic american[a-zA-Z]{0,1}\b')),
194
+ ('ethnicity',50,re.compile(r'\blatino american[a-zA-Z]{0,1}\b')),
195
+ ('ethnicity',51,re.compile(r'\bnative american[a-zA-Z]{0,1}\b')),
196
+ ('ethnicity',52,re.compile(r'\bamerican indian[a-zA-Z]{0,1}\b')),
197
+ ('ethnicity',55,re.compile(r'\bnative[a-zA-Z]{0,1}\b')),
198
+ ('ethnicity',56,re.compile(r'\bcaucasian[a-zA-Z]{0,1}\b')),
199
+ ('ethnicity',57,re.compile(r'\bjew[a-zA-Z]{0,3}\b')),
200
+ ('ethnicity',58,re.compile(r'\bhebrew[a-zA-Z]{0,1}\b')),
201
+ ('ethnicity',59,re.compile(r'\byiddish\b')),
202
+ ('ethnicity',60,re.compile(r'\bmuslim[a-zA-Z]{0,1}\b')),
203
+ ('ethnicity',61,re.compile(r'\bislam[a-zA-Z]{0,2}\b')),
204
+ ('ethnicity',62,re.compile(r'\bgay\b')),
205
+ ('ethnicity',63,re.compile(r'\bqueer\b')),
206
+ ('ethnicity',64,re.compile(r'\bhomosexual\b')),
207
+ ('ethnicity',65,re.compile(r'\bhomo-sexual\b')),
208
+ ('ethnicity',66,re.compile(r'\blesbian\b')),
209
+ ('ethnicity',67,re.compile(r'\bpeople of colo[a-zA-Z]{0,1}r\b')),
210
+ ('ethnicity',68,re.compile(r'\bpeople-of-colo[a-zA-Z]{0,1}r\b')),
211
+ ('ethnicity',69,re.compile(r'\barab\b')),
212
+ # aboriginal indigenous
213
+ ('ethnicity',70,re.compile(r'\baboriginal\b')),
214
+ ('ethnicity',71,re.compile(r'\bindigenous\b')),
215
+ # tribes
216
+ ('ethnicity',72,re.compile(r'\bnavajo[a-zA-Z]{0,3}\b')),
217
+ ('ethnicity',73,re.compile(r'\bcherokee[a-zA-Z]{0,3}\b')),
218
+ ('ethnicity',74,re.compile(r'\bcherokeean[a-zA-Z]{0,3}\b')),
219
+ ('ethnicity',75,re.compile(r'\bsioux\b')),
220
+ ('ethnicity',76,re.compile(r'\bsiouan\b')),
221
+ ('ethnicity',77,re.compile(r'\bchippewa[a-zA-Z]{0,3}\b')),
222
+ ('ethnicity',78,re.compile(r'\bchoctaw[a-zA-Z]{0,3}\b'))]
223
+
224
+ group_blackball = [('blackball',0, re.compile(r'\bblack.{0,3}market[a-zA-Z- ]{0,3}\b')),
225
+ ('blackball',1, re.compile(r'\bblack.{0,3}economy\b')),
226
+ ('blackball',2, re.compile(r'\bblack.{0,3}box.{0,3}\b')),
227
+ ('blackball',3, re.compile(r'\bblack.{0,3}card[a-zA-Z]{0,1}\b')),
228
+ ('blackball',4, re.compile(r'\bblack.{0,3}scholes\b')),
229
+ ('blackball',5, re.compile(r'\barms.{0,3}rac.{0,3}\b')),
230
+ ('blackball',6, re.compile(r'\bpatent.{0,3}rac.{0,3}\b')),
231
+ ('blackball',7, re.compile(r'\brat.{0,3}.{0,3}rac.{0,3}\b')),
232
+ ('blackball',8, re.compile(r'\bpriority.{0,3}rac.{0,3}\b')),
233
+ ('blackball',9, re.compile(r'\belectoral.{0,3}rac.{0,3}\b')),
234
+ ('blackball',10, re.compile(r'\brd.{0,3}rac.{0,3}\b')),
235
+ ('blackball',11, re.compile(r'\bwhite.{0,3}collar\b')),
236
+ ('blackball',12, re.compile(r'\bwhite.{0,3}noise\b')),
237
+ ('blackball',13, re.compile(r'\brace[s]{0,1} between\b')),
238
+ ('blackball',14, re.compile(r'\brac.*prize.{0,3}\b')),
239
+ ('blackball',15, re.compile(r'\bprize.*rac.{0,3}\b')),
240
+ ('blackball',16, re.compile(r'\brac.*winner{0,3}\b')),
241
+ ('blackball',17, re.compile(r'\bwinner.*rac.{0,3}\b')),
242
+ ('blackball',18, re.compile(r'\bhorse.*rac.{0,3}\b')),
243
+ ('blackball',19, re.compile(r'\brac.*horse.{0,3}\b')),
244
+ ('blackball',20, re.compile(r'\brival\b')),
245
+ ('blackball',21, re.compile(r'\br d.{0,3}rac.{0,3}\b')),
246
+ ('blackball',22, re.compile(r'\bblack swan\b'))]
247
+
248
+
249
+ search_regexs_groups = [group_control,group_issue,group_ethnicity,group_blackball]
250
+
251
+ group_main_american = [1,2,3,5,6,7,11,21,25,26,27,28,29,36,44,48,49,50,51,52,67,68,]
252
+ group_minor = [15,22,23,24,30,32,34,45,46,47,55,56,]
253
+ group_religious = [57,58,59,60,61,69,]
254
+ group_sexual = [62,63,64,65,66]
255
+ group_abstract = [0,4,17,18,35,36,37,38,39,40,41,42,43,70,71]
256
+ group_tribal = [72,73,74,75,76,77,78]
257
+ group_0 = group_abstract
258
+ group_1 = group_abstract + group_main_american
259
+ group_2 = group_abstract + group_main_american + group_tribal + group_minor + group_religious
260
+ group_3 = group_abstract + group_main_american + group_tribal + group_minor + group_religious + group_sexual
261
+ groups = [('0',group_0),('1',group_1),('2',group_2),('3',group_3),]
262
+ blackball_list = list(range(22))
263
+
264
+ #####################
265
+ # ALGORITHM FUNCTION
266
+ #####################
267
+
268
+ def rr_detector(title_raw, abstract_raw):
269
+ title = title_raw.lower()
270
+ abstract = abstract_raw.lower()
271
+ result_dict = {}
272
+ for g in search_regexs_groups:
273
+ gname = g[0][0]
274
+ any_ = 0
275
+ any_ex_last = 0
276
+ group_data = {}
277
+ for group, code, search_regex in g:
278
+ abstract_matches = search_regex.findall(abstract)
279
+ abstract_count = len(abstract_matches)
280
+
281
+ abstract_last_matches = search_regex.findall(abstract.split('. ')[-1])
282
+ abstract_last_count = len(abstract_last_matches)
283
+
284
+ title_matches = search_regex.findall(title)
285
+ title_count = len(title_matches)
286
+
287
+ any_ += abstract_count + title_count
288
+ any_ex_last += abstract_count + title_count - abstract_last_count
289
+
290
+ group_data['_'.join([group, str(code), 't', 'c'])] = title_count
291
+ group_data['_'.join([group, str(code), 'at', 'c'])] = abstract_count + title_count
292
+ group_data['_'.join([group, str(code), 'at_ex_last', 'c'])] = abstract_count + title_count - abstract_last_count
293
+ group_data['_'.join([group, str(code), 'at', 'm'])] = int(abstract_count + title_count > 0)
294
+ group_data['_'.join([group, str(code), 'at', 'match'])] = ';'.join(title_matches + abstract_matches)
295
+ group_data['_'.join([gname, 's', 'at', 'm'])] = int(any_ > 0)
296
+ group_data['_'.join([gname, 's', 'at', 'c'])] = any_
297
+ group_data['_'.join([gname, 's', 'at_ex_last', 'm'])] = int(any_ex_last > 0)
298
+ group_data['_'.join([gname, 's', 'at_ex_last', 'c'])] = any_ex_last
299
+
300
+ result_dict.update(group_data)
301
+ #result_dict[gname] = group_data
302
+
303
+ results = {}
304
+ results['blackballed'] = 0
305
+ for gname, gvalue in result_dict.items():
306
+ if 'blackball' in gname and '_at_c' in gname and 's' not in gname:
307
+ if gvalue > 0 and results.get('blackballed', 0) != 1:
308
+ results['blackballed'] = 1
309
+ result_dict.update(results)
310
+
311
+ results = {}
312
+ for e, l in groups:
313
+ results[f'group_{int(e)}'] = 0
314
+ for i in l:
315
+ if result_dict[f'ethnicity_{int(i)}_at_ex_last_c'] > 0 and results.get(f'group_{int(e)}', 0) != 1:
316
+ results[f'group_{int(e)}'] = 1
317
+ result_dict.update(results)
318
+
319
+ results = {}
320
+ for e,l in groups:
321
+ results[f'match_{int(e)}'] = 0
322
+ for i in l:
323
+ if result_dict[f'ethnicity_{int(i)}_t_c'] > 0:
324
+ if result_dict[f'group_{int(e)}']*result_dict['issue_s_at_m'] + 1 > 0 and results.get(f'match_{int(e)}', 0) != 1:
325
+ results[f'match_{int(e)}'] = 1
326
+ result_dict.update(results)
327
+
328
+ results = {}
329
+ for e,l in groups:
330
+ results[f'match_{int(e)}'] = (1-result_dict['blackballed'])*result_dict[f'match_{int(e)}']
331
+ result_dict.update(results)
332
+
333
+ #DETAILES ANALYSIS
334
+ #Extract keywords (issue words)
335
+ results_issue = []
336
+ for gname, gvalue in result_dict.items():
337
+ if 'issue_' in gname and 'at_match' in gname:
338
+ results_issue.append(gvalue)
339
+ unique_issue = set()
340
+ for item in results_issue:
341
+ unique_issue.update(item.split(';'))
342
+ issue_count = {} #<-- dictionary with unique issue keywords
343
+ for term in unique_issue:
344
+ count = 0
345
+ for item in results_issue:
346
+ count += item.count(term)
347
+ issue_count[term] = count
348
+ if '' in issue_count:
349
+ del issue_count['']
350
+
351
+ #Extract group (ethnic words)
352
+ results_group = []
353
+ for gname, gvalue in result_dict.items():
354
+ if 'ethnicity_' in gname and 'at_match' in gname:
355
+ results_group.append(gvalue)
356
+ unique_group = set()
357
+ for item in results_group:
358
+ unique_group.update(item.split(';'))
359
+ group_count = {} #<-- dictionary with unique group keywords
360
+ for term in unique_group:
361
+ count = 0
362
+ for item in results_group:
363
+ count += item.count(term)
364
+ group_count[term] = count
365
+ if '' in group_count:
366
+ del group_count['']
367
+
368
+ #Extract blackball
369
+ results_blackball = []
370
+ for gname, gvalue in result_dict.items():
371
+ if 'blackball_' in gname and 'at_match' in gname:
372
+ results_blackball.append(gvalue)
373
+ unique_blackball = set()
374
+ for item in results_blackball:
375
+ unique_blackball.update(item.split(';'))
376
+ blackball_count = {} #<-- dictionary with blackball keywords
377
+ for term in unique_blackball:
378
+ count = 0
379
+ for item in results_blackball:
380
+ count += item.count(term)
381
+ blackball_count[term] = count
382
+ if '' in blackball_count:
383
+ del blackball_count['']
384
+
385
+ #Append dictionaries into a data frame for Detailed statistics
386
+ df_issue = pd.DataFrame(list(issue_count.items()), columns=['term', 'freq'])
387
+ df_issue['type'] = 'issue'
388
+ df_issue = df_issue[['type', 'term', 'freq']]
389
+
390
+ df_group = pd.DataFrame(list(group_count.items()), columns=['term', 'freq'])
391
+ df_group['type'] = 'group'
392
+ df_group = df_group[['type', 'term', 'freq']]
393
+
394
+ df_blackball = pd.DataFrame(list(blackball_count.items()), columns=['term', 'freq'])
395
+ df_blackball['type'] = 'blackball'
396
+ df_blackball = df_blackball[['type', 'term', 'freq']]
397
+
398
+ df_details = pd.concat([df_group, df_issue, df_blackball], ignore_index=True)
399
+
400
+ #TEXT ANALYSIS
401
+ #Dictionary with issue, topic, and blackball keywords
402
+ keywords_dict = {"issue": [], "group": [], "blackball": []}
403
+ keywords_dict["issue"].extend(issue_count.keys())
404
+ keywords_dict["group"].extend(group_count.keys())
405
+ keywords_dict["blackball"].extend(blackball_count.keys())
406
+
407
+ combined_text = f"TITLE: {title_raw}. \nABSTRACT: {abstract_raw}"
408
+
409
+ text_analysis = []
410
+ for word in combined_text.split():
411
+ if word.lower() in [item.lower() for sublist in keywords_dict.values() for item in sublist]:
412
+ for key, words in keywords_dict.items():
413
+ if word.lower() in [item.lower() for item in words]:
414
+ text_analysis.append((word, key))
415
+ break
416
+ else:
417
+ text_analysis.append((word, None))
418
+
419
+ #FORM THE MAIN OUTPUT
420
+ #Output
421
+ if result_dict['match_1'] == 1:
422
+ #Result
423
+ output_image = os.path.join(dirname, 'images/yes.png')
424
+ #Explanation
425
+ unique_group_str = ', '.join(unique_group)
426
+ unique_issue_str = ', '.join(unique_issue)
427
+ answer = "This paper can be considered race-related, as it mentions at least one group keyword and one topic keywords in title or abstract. Furthermore, it does not mention group keywords in last sentence of abstract, and the algorithm does not identify any blackball phrases in the title and abstract provided."
428
+
429
+ else:
430
+ if len(unique_blackball) > 0:
431
+ #Result
432
+ output_image = os.path.join(dirname, 'images/no.png')
433
+ #Explanation
434
+ unique_blackball_str = ', '.join(unique_blackball)
435
+ answer = "This paper cannot be considered race-related, as it includes blackball phrases, such as: " + unique_blackball_str + "."
436
+
437
+
438
+ else:
439
+ #Result
440
+ output_image = os.path.join(dirname, 'images/no.png')
441
+ #Explanation
442
+ answer = "This paper cannot be considered race-related, as it does not mention any group or topic keywords, or it does mention group keywords but only in the last sentence of provided abstract."
443
+ #Details
444
+ data = {
445
+ "type": ["blackball", "issue", "group"],
446
+ "term": ["term1", "term2", "term3"],
447
+ "freq": [0, 0, 0]
448
+ }
449
+ df_details = pd.DataFrame(data)
450
+
451
+
452
+ return(output_image, answer, df_details, text_analysis)
453
+
454
+
455
+ #####################
456
+ # STYLE
457
+ #####################
458
+
459
+ def_image = os.path.join(dirname, 'images/default.png')
460
+
461
+
462
+ title_prompt = """
463
+ <!DOCTYPE html>
464
+ <html>
465
+ <head>
466
+ <style>
467
+ .title {
468
+ font-family: Arial, sans-serif;
469
+ font-size: 24px;
470
+ font-weight: bold;
471
+ text-align: center;
472
+ letter-spacing: 3px;
473
+ color: #333;
474
+ }
475
+ .subtitle {
476
+ font-family: Arial, sans-serif;
477
+ font-size: 18px;
478
+ text-align: center;
479
+ color: #666;
480
+ }
481
+ </style>
482
+ </head>
483
+ <body>
484
+
485
+ <div class="title">IDENTIFYING RACE-RELATED RESEARCH</div>
486
+
487
+ </body>
488
+ </html>
489
+ """
490
+
491
+ description_prompt = """
492
+ <p>This app is supplementary material to the <strong>"Race-related Research in Economics" paper</strong>, where we examine how academic economists contribute to discussions about racial justice and enduring economic disparities among different racial and ethnic groups. Specifically, we analyze the production of race-related research in Economics. Our study is based on the analysis of a corpus of 250,000 economics publications from 1960 to 2020, employing an algorithmic approach to classify race-related publications. <strong>This app enables users to verify whether their research can be categorized as race-related based on our algorithm</strong>.</p>
493
+
494
+ <p>If you would like our algorithm to classify your research, please submit the title and abstract of your paper. By default, the title and abstract of our paper are provided, and you can verify whether it is a race-related research.</p>
495
+
496
+ """
497
+
498
+
499
+
500
+ #####################
501
+ # APP LAUNCH
502
+ #####################
503
+
504
+ title_smpl = "Race-related Research in Economics"
505
+ abstract_smpl = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics."
506
+
507
+
508
+ demo = gr.Interface(fn=rr_detector, inputs=[
509
+ gr.Textbox(label="Title", value=title_smpl, lines=2),
510
+ gr.Textbox(label="Abstract", value=abstract_smpl, lines=12)],
511
+ outputs=[
512
+ gr.Image(label = 'Result', value=def_image),
513
+ gr.Textbox(label="Explanation"),
514
+ gr.BarPlot(
515
+ label = "Details",
516
+ x="term",
517
+ y="freq",
518
+ color="type",
519
+ title="Frequency of Race-related Keywords in Title and Abstract",
520
+ tooltip=["type", "term", "freq"],
521
+ vertical=False,
522
+ #caption = "TEST",
523
+ #height = 150,
524
+ #width = 300,
525
+ color_legend_title = 'Type of Keywords',
526
+ x_title = "Keywords",
527
+ y_title = "Frequency"
528
+ ),
529
+ gr.HighlightedText(
530
+ label="Text Analysis",
531
+ show_legend=True,
532
+ color_map={"group": "yellow", "issue": "blue", "blackball": "grey"}),
533
+ ], theme='ParityError/Interstellar', title = title_prompt, description = description_prompt, allow_flagging = 'auto')
534
+
535
+
536
+ if __name__ == "__main__":
537
+ demo.launch(share=True)
538
+
539
+
540
+ # Add default picture for output
541
+ # Output as graph of just text but with fancy representation -- use labels from theme
542
+ # Generate picts for output with GenAi
543
+
544
+ #RR
545
+ title_raw = 'When expectations work race and socioeconomic differences in school performance'
546
+ abstract_raw = 'Why race between are expectations for future performance realized more often by some people than by others and why are such differences in the efficacy of performance expectations socially patterned we hypothesize that differences in attentiveness to performance feedback may be relevant reasoning that follow-through behaviors will be less well conceived when expectations are formed without regard to evaluation of previous performance. using data from baltimore fourth-grade students and their parents we find that expectations anticipate marks more accurately when recall of prior marks is correct than when it is incorrect. because errors of recall mostly on the high side are more common among lower-ses and minority children and their parents their school performance is affected most strongly. research on school attainment process from a motivational perspective must give more attention to the additional resources that facilitate successful goal attainment given high expectations. our perspective focuses on resources internal to the individual but external constraints also are important. the discussion stresses the need for further work in both areas.'
547
+
548
+ #Default
549
+ title_raw = "Race-related Research in Economics"
550
+ abstract_raw = "Issues of racial justice and persistent economic inequalities across racial and ethnic groups have risen to the top of public debate. The ability of academic economists to contribute to these debates in part depends on the production of race-related research in the profession. We study the issue combining information on a corpus of 250,000 publications in economics from 1960 to 2020 on which we use an algorithmic approach to classify race-related publications, constructing paths to publication for 22,000 NBER working papers between 1974 and 2015, and constructing the career prole of publications of 2800 economics faculty in US economics departments active in 2020/1. We present four new stylized facts on race-related research in economics."
551
+
552
+
553
+
554
+ #non-RR
555
+ title = 'Hurting stalemate or mediation the conflict over nagorno-karabakh 1990-95'
556
+ abstract = 'The impacts of six attempts to mediate the conflict over the political status of nagorno-karabakh in the caucasus region of the former soviet union were compared. each mediation was intended to get the direct parties armenia azerbaijan and nagorno-karabakh to the negotiating table. nearly 4000 events were recorded for a six-year period from 1990 through 1995. each event was coded in terms of a six-step scale ranging from a significant action toward peace 3 to substantial violence directed at an adversary -3. time-series analyses of changes in the extent of violence showed no change from before to after any of the mediations. a significant change did occur however between the months preceding and following the period of intensive combat between april 1993 and february 1994. these results support the hypothesis that a mutually hurting stalemate is a condition for negotiating a ceasefire and reduced violence between warring parties. a number of theoretical and practical implications of the findings are discussed.'
557
+
558
+
559
+ rr_detector(title_raw, abstract_raw)
560
+
561
+
562
+
563
+
564
+
565
+