def va_ts_exceptions(specific_suffix, possible_names, vf_col): if not vf_col == 'vf_township': specific_suffix += ' CITY' if specific_suffix in possible_names: return no_spaces(possible_names[possible_names.index(specific_suffix)]) else: return ''
def get_high_level(vf_col, ocdid, districts): # Reads in all possible districts as ripped from the VF possible_names = districts[vf_col] # Pull most specific section of the ocdid & clean up suffix = ocdid.split('/')[-1] specific_suffix = suffix.split(':')[-1].upper().replace('_', ' ').replace('~', '') if re.match(r'[0-9]+', specific_suffix): specific_suffix = add_zeros(specific_suffix) if 'state:md' in ocdid: specific_suffix = se.md_ts_exceptions(specific_suffix, ocdid) # Check for state exception cases if 'state:nh' in ocdid: if vf_col == 'vf_hd': return se.nh_ts_exceptions(specific_suffix, possible_names) elif 'state:ma' in ocdid: if vf_col == 'vf_hd' or vf_col == 'vf_sd': return se.ma_ts_exceptions(specific_suffix, possible_names) elif 'state:vt' in ocdid: if vf_col == 'vf_hd' or 'GRAND ISLE' in specific_suffix: return se.vt_ts_exceptions(vf_col, specific_suffix, possible_names) elif 'state:va' in ocdid and 'place:' in ocdid: return se.va_ts_exceptions(specific_suffix, possible_names, vf_col) # Match to possible districts if there are no exceptions if specific_suffix in possible_names: return no_spaces(possible_names[possible_names.index(specific_suffix)]) else: for p in possible_names: if fuzz.ratio(specific_suffix, p) >= 90: return no_spaces(possible_names[possible_names.index(p)]) elif fuzz.partial_ratio(specific_suffix, p) >= 90: return no_spaces(possible_names[possible_names.index(p)]) else: return ''
def va_exceptions(estimated_ocdid, ed): temp_ed = ed.replace('county', '').strip().replace(' ', '_') place = estimated_ocdid + '/place:{}'.format(temp_ed.replace('_city', '')) if 'county council district' in ed: temp_ed = ed.split('district') estimated_ocdid = place + '/council_district:{}'.format(temp_ed[-1]) elif 'muni' in ed: temp_ed = ed.split('town') estimated_ocdid = estimated_ocdid + '/place:{}'.format(no_spaces(temp_ed[0])) else: estimated_ocdid = place if not ocdid.is_ocdid(estimated_ocdid): return '' else: return estimated_ocdid
def nh_ts_exceptions(specific_suffix, possible_names): nh_floats = {} with open('nh-floats.csv', 'rU') as nh_data: reader = DictReader(nh_data) for row in reader: nh_floats[row['float']] = row['regular'] specific_suffix = specific_suffix.replace(' ', '') if specific_suffix in possible_names: return no_spaces(possible_names[possible_names.index(specific_suffix)]) elif specific_suffix + 'F' in nh_floats: return specific_suffix + 'F-special-' + nh_floats[specific_suffix + 'F'] else: print specific_suffix return ''
def assign_lower(state, ed, office, level, role, estimated_ocdid): nothing = False if level == 'administrativearea1': nothing = True elif level == 'administrativearea2': if 'county' in ed: if state == 'va' and 'city' in ed: estimated_ocdid = se.va_exceptions(estimated_ocdid, ed) elif 'county council district' in ed: temp_ed = ed.split('county council district') estimated_ocdid += '/county:{}/council_district:{}'.format( no_spaces(temp_ed[0]), no_spaces(temp_ed[-1].strip()) ) elif 'school' in ed: nothing = True elif 'subcircuit' in ed: nothing = True elif 'finance' in ed or 'dorchester county judicial' in ed: nothing = True else: ed = ed.replace('county', '').strip().replace(' ', '_').replace('.', '') estimated_ocdid += '/county:{}'.format(ed) else: nothing = True elif level == 'regional': if state == 'ky': estimated_ocdid = se.ky_exceptions(estimated_ocdid, ed) elif state == 'il': estimated_ocdid = se.il_exceptions(estimated_ocdid, ed) elif 'county' in ed and 'district' not in ed: ed = ed.replace('county', '').strip().replace(' ', '_').replace('.', '') estimated_ocdid += '/county:{}'.format(ed) elif 'supreme' in ed: estimated_ocdid += 'supreme_court:{}'.format(get_district(ed)) if not ocdid.is_ocdid(estimated_ocdid): nothing = True elif 'circuit' in ed: nothing = True else: nothing = True elif level == 'locality': if state == 'va': estimated_ocdid = se.va_exceptions(estimated_ocdid, ed) else: nothing = True elif level == 'special': nothing = True else: nothing = True if state == 'co' and 'school' in role: estimated_ocdid = se.co_exceptions(estimated_ocdid, ed, role) nothing = False if nothing: estimated_ocdid = '' return estimated_ocdid