コード例 #1
0
    def _replace(self, replacement_op: TextReplacementOp,
                 input_anno: Annotation) -> bool:
        r"""
        This is a wrapper function to call the replacement op. After
        getting the augmented text, it will register the input & output
        for later batch process of building the new data pack.

        It will ignore the input if it has an overlap with the already
        augmented spans.

        Args:
            replacement_op: The class for data augmentation algorithm.
            input_anno: The entry to be replaced.
        Returns:
            A bool value. True if the replacement happened, False otherwise.
        """
        # Ignore the new annotation if overlap.
        pid: int = input_anno.pack.pack_id
        if self._overlap_with_existing(pid, input_anno.begin, input_anno.end):
            return False
        replaced_text: str
        is_replace: bool
        is_replace, replaced_text = replacement_op.replace(input_anno)
        if is_replace:
            self._replaced_annos[pid].add((input_anno.span, replaced_text))
            return True
        return False
コード例 #2
0
 def replace(self, replacement_op: TextReplacementOp, input: Entry):
     """
     This is a wrapper function to call the replacement op. After
     getting the augmented text, it will register the input & output
     for later batch process of building the new data pack.
     """
     replaced_text: str = replacement_op.replace(input)
     self.replaced_spans.append((input, replaced_text))