<commit_before>import re
import typing as T
from copy import copy

from bubblesub.api import Api
from bubblesub.ass_renderer import AssRenderer
from bubblesub.fmt.ass.event import AssEvent

from .common import (
    WIDTH_MULTIPLIERS,
    BaseResult,
    Information,
    get_width,
    is_event_title,
    measure_frame_size,
)


def check_unnecessary_breaks(
    event: AssEvent, api: Api, renderer: AssRenderer
) -> T.Iterable[BaseResult]:
    if r"\N" not in event.text:
        return
    event_copy = copy(event)
    event_copy.text = event.text.replace(r"\N", " ")
    width, _height = measure_frame_size(api, renderer, event_copy)
    optimal_width = get_width(api) * WIDTH_MULTIPLIERS[1]

    many_sentences = len(re.split(r"[\.!?…—] ", event_copy.text)) > 1
    if (
        width < optimal_width
        and not many_sentences
        and not is_event_title(event)
    ):
        yield Information(
            event,
            f"possibly unnecessary break "<commit_msg>cfg/bubblesub/qc: exempt karaoke from line breaks check<commit_after>import re
import typing as T
from copy import copy

from bubblesub.api import Api
from bubblesub.ass_renderer import AssRenderer
from bubblesub.fmt.ass.event import AssEvent

from .common import (
    WIDTH_MULTIPLIERS,
    BaseResult,
    Information,
    get_width,
    is_event_karaoke,
    is_event_title,
    measure_frame_size,
)


def check_unnecessary_breaks(
    event: AssEvent, api: Api, renderer: AssRenderer
) -> T.Iterable[BaseResult]:
    if r"\N" not in event.text:
        return
    event_copy = copy(event)
    event_copy.text = event.text.replace(r"\N", " ")
    width, _height = measure_frame_size(api, renderer, event_copy)
    optimal_width = get_width(api) * WIDTH_MULTIPLIERS[1]

    many_sentences = len(re.split(r"[\.!?…—] ", event_copy.text)) > 1
    if (
        width < optimal_width
        and not many_sentences
        and not is_event_title(event)
        and not is_event_karaoke(event)
    ):
        yield Information(
            event,
            f"possibly unnecessary break "
{'fraction_non_alphanumeric': 0.09082125603864734, 'fraction_numerical': 0.001932367149758454, 'mean_word_length': 3.084812623274162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4626246', 'n_tokens_mistral': 692, 'n_tokens_neox': 671, 'n_words': 164}