import re

from .stage import Stage


class TextSpellCorrectionStage(Stage):
    def __init__(self):
        Stage.__init__(self)

    def process(self, document):
        # Replace all newlines with spaces"
        processed = document.text.replace(
            "\r", " ").replace("\n", " ")

        # Remove abnormal characters
        processed = processed.replace("|", "I")
        processed = re.sub("[^A-Za-z0-9 .,\-%:]+", " ", processed)

        # Fix spaces around punctuation
        processed = processed.replace(',', ', ').replace(
            ' ,', ',').replace(' .', '.')

        # Remove duplicate spaces and dots
        processed = re.sub("\.(\.+)", " ", processed)
        processed = re.sub("  +", " ", processed)

        document.text = processed
        return [document]

import re

from .stage import Stage


class TextSpellCorrectionStage(Stage):
    def __init__(self):
        Stage.__init__(self)

    def process(self, document):
        # Replace all newlines with spaces"
        processed = document.text.replace(
            "\r", " ").replace("\n", " ")

        # Remove abnormal characters
        processed = processed.replace("|", "I")
        processed = re.sub("[^A-Za-z0-9 .,\-%:]+", " ", processed)

        # Fix spaces around punctuation
        processed = processed.replace(',', ', ').replace(
            ' ,', ',').replace(' .', '.')

        # Remove duplicate spaces and dots
        processed = re.sub("\.(\.+)", " ", processed)
        processed = re.sub("  +", " ", processed)

        document.text = processed
        return [document]

# Replace all newlines with spaces" # Remove abnormal characters # Fix spaces around punctuation # Remove duplicate spaces and dots