Capgemini Government Solutions is preparing text features for a document-analysis pipeline. Implement a deterministic preprocessing function that converts raw ASCII text into normalized token frequencies.
For each input string:
stop_words, which should be matched case-insensitively.ing, ed, es, or a final s when the remaining token has at least three characters. Do not remove a final s when the token ends in ss.min_length.The input text contains only ASCII characters. Stemming is intentionally simple and does not need to handle every English word.
Implement preprocess_text(text, stop_words, min_length). text is a string, stop_words is a list of strings, and min_length is a positive integer. Return a dictionary from normalized string tokens to integer counts. Return {} when no tokens remain.
def preprocess_text(text, stop_words, min_length):