def replace_and_adjust(
      input_text: str, match: Any, prefix_len: int,
      inverted_mapping: np.ndarray) -> Tuple[str, np.ndarray]:
    """Remove subj/obj annotations and adjust token mapping accordingly."""

    original_span_start = match.start() + prefix_len + 1
    original_span_end = match.end() - 1
    actual_string = input_text[original_span_start:original_span_end]
    new_text = input_text[:match.start()] + actual_string + input_text[match
                                                                       .end():]

    # Inverted mapping maps from remaining tokens to positions in original text
    new_inverted_mapping = np.zeros(len(new_text), dtype=np.int32)
    new_inverted_mapping[:match.start()] = inverted_mapping[:match.start()]

    new_span_start = match.start()
    new_span_end = match.start() + len(actual_string)
    new_inverted_mapping[new_span_start:new_span_end] = inverted_mapping[
        original_span_start:original_span_end]
    new_inverted_mapping[new_span_end:] = inverted_mapping[original_span_end +
                                                           1:]

    return new_text, new_inverted_mapping
Remove subj/obj annotations and adjust token mapping accordingly.
language/mentionmemory/data/prepare_webred.py