<commit_before>package main.subtitle.subtitleObject;

import main.srtFixer.config.SrtFixerConfig;
import main.subtitle.fix.ChangeLsToIs;
import main.subtitle.fix.FixAbbreviations;
import main.subtitle.fix.FixAcronym;
import main.subtitle.fix.FixAmpersand;
import main.subtitle.fix.FixCapitalization;
import main.subtitle.fix.FixCommonErrors;
import main.subtitle.fix.FixContractions;
import main.subtitle.fix.FixDashes;
import main.subtitle.fix.FixEllipses;
import main.subtitle.fix.FixEnding;
import main.subtitle.fix.FixHeight;
import main.subtitle.fix.FixLetterS;
import main.subtitle.fix.FixMisplacedQuotes;
import main.subtitle.fix.FixMultilineDashes;
import main.subtitle.fix.FixMultilineQuotes;
import main.subtitle.fix.FixNonTraditionalStrings;
import main.subtitle.fix.FixNumbers;
import main.subtitle.fix.FixSingleDoubleQuotes;
import main.subtitle.fix.FixSpacing;
import main.subtitle.fix.FixSpelling;
import main.subtitle.fix.FixTime;
import main.subtitle.fix.FixToUppercase;
import main.subtitle.fix.FixWebsites;
import main.subtitle.fix.PrepareLine;
import main.subtitle.fix.fixMultipleLines.FixOneLine;
import main.subtitle.fix.fixMultipleLines.FixThreeLines;
import main.subtitle.fix.fixMultipleLines.FixTwoLines;
import main.subtitle.fix.fixMultipleLines.FixUnbalancedDashes;
import main.subtitle.fix.remove.RemoveCharacterName;
import main.subtitle.fix.remove.RemoveEmpty;
import main.subtitle.fix.remove.RemoveEndingCharacter;
import main.subtitle.map.SplitMap;
import main.subtitle.specialCases.DoNotFix;
import main.subtitle.specialCases.ManuelFix;
import main.subtitle.timeHolder.TimeHolder;
import main.subtitle.util.SubtitleUtil;
import main.util.regex.RegexEnum;
import main.util.regex.RegexUtil;
import main.util.string.StringUtil;

/**
 * Container for all necessary components of a subtitle.
 * 
 * @author budi
 */
public class SubtitleObject {

    /**
     * Unique id.
     */
    private int id;

    /**
     * Start {@link TimeHolder}.
     */
    private TimeHolder timeStart;

    /**
     * End {@link TimeHolder}.
     */
    private TimeHolder timeEnd;

    /**
     * Subtitle text.
     */
    private String text;

    /**
     * Original text.
     */
    private String originalText;

    /**
     * {@link SplitMap}.
     */
    private SplitMap splitMap;

    /**
     * Class constructor.
     * 
     * @param id current id
     * @param timeStart starting time
     * @param timeEnd ending time
     * @param text text
     * @throws SubtitleObjectException Thrown if timeStart is greater than
     *             timeEnd.
     */
    public SubtitleObject(int id, TimeHolder timeStart, TimeHolder timeEnd, String text)
            throws SubtitleObjectException {
        this.id = id;
        this.timeStart = timeStart;
        this.timeEnd = timeEnd;
        this.text = text;
        this.originalText = RemoveEndingCharacter.fix(text, '<', '>', null);
        this.splitMap = new SplitMap();

        if (timeStart != null && timeStart.calcTotalTimeMs() > timeEnd.calcTotalTimeMs()) {
            throw new SubtitleObjectException(
                    String.format("[ID: %s] Start time is greater than end time. (%s > %s)", id, timeStart, timeEnd));
        }
    }

    /**
     * Class constructor using only text.
     * 
     * @param text text
     * @throws SubtitleObjectException
     */
    public SubtitleObject(String text) throws SubtitleObjectException {
        this(-1, null, null, text);
    }

    /**
     * Apply fixes to text.
     */
    public void fix() {
        if (text == null || text.isEmpty()) {
            return;
        }
        text = text.trim();
        text = RemoveEmpty.fix(text, this);
        if (text.isEmpty()) {
            return;
        }

        // TODO: comment this

        text = RemoveEndingCharacter.fix(text, '<', '>', this);
        text = RemoveEndingCharacter.fix(text, '[', ']', this);
        if (ManuelFix.MANUEL_FIX.containsKey(text)) {
            text = ManuelFix.MANUEL_FIX.get(text);
            return;
        } else if (DoNotFix.DO_NOT_FIX.contains(text)) {
            return;
        }

        text = RemoveEndingCharacter.fix(text, '(', ')', this);
        text = FixNonTraditionalStrings.fix(text, this);

        // TODO: messy (see "...with the .22?")
        if (text.startsWith("-") && !text.startsWith("- ")) {
            text = "- " + text.substring(1);
            splitMap.clear(); // TODO: clean up
        }
        text = FixEllipses.fix(text, this);
        text = FixSingleDoubleQuotes.fix(text, this);

        String result = "";
        int removedNames = 0;
        String originalText = text;

        text = FixUnbalancedDashes.fix(text);
        boolean fixedUnbalancedDashes = !originalText.equals(text);

        if (!text.startsWith("-")) {
            //text = text.replace("\n", " "); // TODO: explain this
        }<commit_msg>Add removal of HTML tags surrounded by '{' and '}'<commit_after>package main.subtitle.subtitleObject;

import main.srtFixer.config.SrtFixerConfig;
import main.subtitle.fix.ChangeLsToIs;
import main.subtitle.fix.FixAbbreviations;
import main.subtitle.fix.FixAcronym;
import main.subtitle.fix.FixAmpersand;
import main.subtitle.fix.FixCapitalization;
import main.subtitle.fix.FixCommonErrors;
import main.subtitle.fix.FixContractions;
import main.subtitle.fix.FixDashes;
import main.subtitle.fix.FixEllipses;
import main.subtitle.fix.FixEnding;
import main.subtitle.fix.FixHeight;
import main.subtitle.fix.FixLetterS;
import main.subtitle.fix.FixMisplacedQuotes;
import main.subtitle.fix.FixMultilineDashes;
import main.subtitle.fix.FixMultilineQuotes;
import main.subtitle.fix.FixNonTraditionalStrings;
import main.subtitle.fix.FixNumbers;
import main.subtitle.fix.FixSingleDoubleQuotes;
import main.subtitle.fix.FixSpacing;
import main.subtitle.fix.FixSpelling;
import main.subtitle.fix.FixTime;
import main.subtitle.fix.FixToUppercase;
import main.subtitle.fix.FixWebsites;
import main.subtitle.fix.PrepareLine;
import main.subtitle.fix.fixMultipleLines.FixOneLine;
import main.subtitle.fix.fixMultipleLines.FixThreeLines;
import main.subtitle.fix.fixMultipleLines.FixTwoLines;
import main.subtitle.fix.fixMultipleLines.FixUnbalancedDashes;
import main.subtitle.fix.remove.RemoveCharacterName;
import main.subtitle.fix.remove.RemoveEmpty;
import main.subtitle.fix.remove.RemoveEndingCharacter;
import main.subtitle.map.SplitMap;
import main.subtitle.specialCases.DoNotFix;
import main.subtitle.specialCases.ManuelFix;
import main.subtitle.timeHolder.TimeHolder;
import main.subtitle.util.SubtitleUtil;
import main.util.regex.RegexEnum;
import main.util.regex.RegexUtil;
import main.util.string.StringUtil;

/**
 * Container for all necessary components of a subtitle.
 * 
 * @author budi
 */
public class SubtitleObject {

    /**
     * Unique id.
     */
    private int id;

    /**
     * Start {@link TimeHolder}.
     */
    private TimeHolder timeStart;

    /**
     * End {@link TimeHolder}.
     */
    private TimeHolder timeEnd;

    /**
     * Subtitle text.
     */
    private String text;

    /**
     * Original text.
     */
    private String originalText;

    /**
     * {@link SplitMap}.
     */
    private SplitMap splitMap;

    /**
     * Class constructor.
     * 
     * @param id current id
     * @param timeStart starting time
     * @param timeEnd ending time
     * @param text text
     * @throws SubtitleObjectException Thrown if timeStart is greater than
     *             timeEnd.
     */
    public SubtitleObject(int id, TimeHolder timeStart, TimeHolder timeEnd, String text)
            throws SubtitleObjectException {
        this.id = id;
        this.timeStart = timeStart;
        this.timeEnd = timeEnd;
        this.text = text;
        this.originalText = RemoveEndingCharacter.fix(text, '<', '>', null);
        this.splitMap = new SplitMap();

        if (timeStart != null && timeStart.calcTotalTimeMs() > timeEnd.calcTotalTimeMs()) {
            throw new SubtitleObjectException(
                    String.format("[ID: %s] Start time is greater than end time. (%s > %s)", id, timeStart, timeEnd));
        }
    }

    /**
     * Class constructor using only text.
     * 
     * @param text text
     * @throws SubtitleObjectException
     */
    public SubtitleObject(String text) throws SubtitleObjectException {
        this(-1, null, null, text);
    }

    /**
     * Apply fixes to text.
     */
    public void fix() {
        if (text == null || text.isEmpty()) {
            return;
        }
        text = text.trim();
        text = RemoveEmpty.fix(text, this);
        if (text.isEmpty()) {
            return;
        }

        // TODO: comment this

        text = RemoveEndingCharacter.fix(text, '<', '>', this);
        text = RemoveEndingCharacter.fix(text, '{', '}', this);
        text = RemoveEndingCharacter.fix(text, '[', ']', this);
        if (ManuelFix.MANUEL_FIX.containsKey(text)) {
            text = ManuelFix.MANUEL_FIX.get(text);
            return;
        } else if (DoNotFix.DO_NOT_FIX.contains(text)) {
            return;
        }

        text = RemoveEndingCharacter.fix(text, '(', ')', this);
        text = FixNonTraditionalStrings.fix(text, this);

        // TODO: messy (see "...with the .22?")
        if (text.startsWith("-") && !text.startsWith("- ")) {
            text = "- " + text.substring(1);
            splitMap.clear(); // TODO: clean up
        }
        text = FixEllipses.fix(text, this);
        text = FixSingleDoubleQuotes.fix(text, this);

        String result = "";
        int removedNames = 0;
        String originalText = text;

        text = FixUnbalancedDashes.fix(text);
        boolean fixedUnbalancedDashes = !originalText.equals(text);

        if (!text.startsWith("-")) {
            //text = text.replace("\n", " "); // TODO: explain this
        }
{'fraction_non_alphanumeric': 0.11951787703838752, 'fraction_numerical': 0.0010128633647320977, 'mean_word_length': 2.7444065225635192, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5895705', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2962, 'n_words': 619}