in microservices/prior_learning_assessment/src/services/extraction/post_process.py [0:0]
def correction_script(corrected_dict, template):
"""
Function for correction of extracted values
Input:
corrected_dict:input dictionary with key value pair
template: type of correction requested
Output:
corrected_dict: output dictionary with key and corrected value
"""
# traverse through the input dictionary
for k, v in corrected_dict.items():
# check for template type
if template == "clean_value":
# check for keys in template
for key, noise in CLEAN_VALUE_DICT.items():
# if keys are matched
if k == key:
# get the noise from the template for that key
noise = CLEAN_VALUE_DICT.get(key)
# copy input value
input_value = v
# iterate th
for i in noise:
# call clean_value function
corrected_value = clean_value(input_value, i)
input_value = corrected_value
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "lower_to_upper":
# check for keys in template
for item in LOWER_TO_UPPER_LIST:
# if keys are matched
if k == item:
# call lower_to_upper function
corrected_value = lower_to_upper(v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "upper_to_lower":
# check for keys in template
for item in UPPER_TO_LOWER_LIST:
# if keys are matched
if k == item:
# call upper_to_lower function
corrected_value = upper_to_lower(v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "clean_multiple_space":
# check for keys in template
for item in CLEAN_SPACE_LIST:
# if keys are matched
if k == item:
# call clean_multiple_space function
corrected_value = clean_multiple_space(v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "date_format":
# check for keys in template
for key,value in DATE_FORMAT_DICT.items():
# if keys are matched
if k == key:
# get key values from template
value = DATE_FORMAT_DICT.get(key)
# call get_date_in_format function; value[0]=input date format;
# value[1]=output date format
corrected_value = get_date_in_format(value[0], value[1], v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "convert_to_string":
# check for keys in template
for item in CONVERT_TO_STRING:
# if keys are matched
if k == item:
# call number_to_string function
corrected_value = number_to_string(v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# check for template type
if template == "convert_to_number":
# check for keys in template
for item in CONVERT_TO_NUMBER:
# if keys are matched
if k == item:
# call string_to_number function
corrected_value = string_to_number(v)
# modify the input dictionary to the corrected value
corrected_dict[k] = corrected_value
# return corrected_dict
return corrected_dict