コード例 #1
0
    def inline_replacements(self, text_index, original_text):
        """Apply multiple inline layers to given text (e.g. links,
        highlighting, etc.)"""
        layer_pairs = self.apply_layer(original_text, text_index)

        # convert from offset-based to a search and replace layer.
        for original, replacement, offset in layer_pairs:
            offset_locations = LocationReplace.find_all_offsets(
                original, original_text)
            locations = [offset_locations.index(offset)]
            yield Replacement(original, replacement, locations)
コード例 #2
0
    def get_layer_pairs(self, text_index, original_text):
        layer_pairs = []
        for layer in self.layers.values():
            layer_pairs += list(layer.apply_layer(original_text, text_index))

        # convert from offset-based to a search and replace layer.
        layer_elements = []

        for o, r, offset in layer_pairs:
            offset_locations = LocationReplace.find_all_offsets(o, original_text)
            locations = [offset_locations.index(offset)]
            layer_elements.append((o, r, locations))
        return layer_elements
コード例 #3
0
    def get_layer_pairs(self, text_index, original_text):
        layer_pairs = []
        for layer in self.layers.values():
            layer_pairs += list(layer.apply_layer(original_text, text_index))

        # convert from offset-based to a search and replace layer.
        layer_elements = []

        for o, r, offset in layer_pairs:
            offset_locations = LocationReplace.find_all_offsets(o,
                                                                original_text)
            locations = [offset_locations.index(offset)]
            layer_elements.append((o, r, locations))
        return layer_elements
コード例 #4
0
    def get_layer_pairs(self, text_index, original_text):
        layer_pairs = []
        for layer in self.layers.values():
            applied = layer.apply_layer(original_text, text_index)
            if applied:
                layer_pairs += applied

        #convert from offset-based to a search and replace layer.
        layer_elements = []

        for o, r, offset in layer_pairs:
            offset_locations = LocationReplace.find_all_offsets(o,
                                                                original_text)
            try:
                locations = [offset_locations.index(offset)]
                layer_elements.append((o, r, locations))
            except Exception as ex:
                logging.info('{0!s}'.format(ex))
                logging.info('Problem interpolating offsets: {0}, {1}'.format(offset_locations, offset))
        return layer_elements
コード例 #5
0
    def get_layer_pairs(self, text_index, original_text):
        layer_pairs = []
        for layer in self.layers.values():
            applied = layer.apply_layer(original_text, text_index)
            if applied:
                layer_pairs += applied

        #convert from offset-based to a search and replace layer.
        layer_elements = []

        for o, r, offset in layer_pairs:
            offset_locations = LocationReplace.find_all_offsets(
                o, original_text)
            try:
                locations = [offset_locations.index(offset)]
                layer_elements.append((o, r, locations))
            except Exception as ex:
                logging.info('{0!s}'.format(ex))
                logging.info('Problem interpolating offsets: {0}, {1}'.format(
                    offset_locations, offset))
        return layer_elements