class Postprocessor: def __init__(self, fix_one_letter_words=True): self.fix_one_letter_words = fix_one_letter_words @staticmethod def fix_sz(next_word): if next_word[0] in ['c', 'č', 'f', 'h', 'k', 'p', 's', 'š', 't']: return 's' return 'z' @staticmethod def fix_kh(next_word): if next_word[0] in ['g', 'k']: return 'h' return 'k' def process(self, match, collocation_id): if len(collocation_id) > 2: for idx, (col_id, word) in enumerate(collocation_id[1:-1]): if word in ['s', 'z']: correct_letter = self.fix_sz(collocation_id[idx + 2][1]) collocation_id[idx + 1][1] = correct_letter match[col_id].text = correct_letter elif word in ['k', 'h']: correct_letter = self.fix_kh(collocation_id[idx + 2][1]) collocation_id[idx + 1][1] = correct_letter match[col_id].text = correct_letter collocation_id = [collocation_id[0]] + [tuple(line) for line in collocation_id[1:]] return match, collocation_id