mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
refactor: unify PUNCTUATION constants in domain/split_pattern.py
This commit is contained in:
@@ -5,8 +5,12 @@ import re
|
||||
|
||||
from abogen.domain.enums import Language, SubtitleMode
|
||||
|
||||
PUNCTUATION_SENTENCE = r".!?。!?"
|
||||
PUNCTUATION_SENTENCE_COMMA = r".!?,。!?、,"
|
||||
# Canonical punctuation sets covering all supported scripts:
|
||||
# ASCII (. ! ?), Arabic ؟, CJK (。!?), Devanagari ।
|
||||
PUNCTUATION_SENTENCE = r".!?؟。!?।"
|
||||
# Commas: ASCII , CJK fullwidth ,CJK ideographic 、
|
||||
PUNCTUATION_SENTENCE_COMMA = r".!?,?。!?،,、।"
|
||||
PUNCTUATION_COMMAS = ",,、"
|
||||
|
||||
|
||||
def get_split_pattern(language: str, subtitle_mode: str) -> str:
|
||||
|
||||
@@ -11,11 +11,7 @@ import re
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from abogen.domain.enums import Language, SubtitleMode
|
||||
|
||||
|
||||
# Punctuation constants for sentence splitting
|
||||
PUNCTUATION_SENTENCE = ".!?\u061f\u3002\uff01\uff1f" # .!? .?. ??
|
||||
PUNCTUATION_SENTENCE_COMMA = ".!?,\u3001\u061f\u3002\uff01\uff0c\uff1f" # .!?, ,. ??
|
||||
from abogen.domain.split_pattern import PUNCTUATION_SENTENCE, PUNCTUATION_SENTENCE_COMMA
|
||||
|
||||
|
||||
def process_subtitle_tokens(
|
||||
@@ -87,7 +83,7 @@ def _process_karaoke_highlighting(
|
||||
fallback_end_time: Optional[float],
|
||||
) -> None:
|
||||
"""Process tokens for Sentence + Highlighting mode (karaoke effect)."""
|
||||
separator = rf"[{re.escape(PUNCTUATION_SENTENCE)}]"
|
||||
separator = rf"[{PUNCTUATION_SENTENCE}]"
|
||||
current_sentence = []
|
||||
word_count = 0
|
||||
|
||||
@@ -247,11 +243,9 @@ def _process_regex_sentences(
|
||||
if subtitle_mode == SubtitleMode.LINE:
|
||||
separator = r"\n"
|
||||
elif subtitle_mode == SubtitleMode.SENTENCE:
|
||||
# Use punctuation without comma
|
||||
separator = rf"[{re.escape(PUNCTUATION_SENTENCE)}]"
|
||||
separator = rf"[{PUNCTUATION_SENTENCE}]"
|
||||
else: # Sentence + Comma
|
||||
# Use punctuation with comma
|
||||
separator = rf"[{re.escape(PUNCTUATION_SENTENCE_COMMA)}]"
|
||||
separator = rf"[{PUNCTUATION_SENTENCE_COMMA}]"
|
||||
|
||||
current_sentence = []
|
||||
word_count = 0
|
||||
|
||||
@@ -78,6 +78,7 @@ from abogen.subtitle_utils import (
|
||||
sanitize_name_for_os,
|
||||
split_text_by_voice_markers
|
||||
)
|
||||
from abogen.domain.split_pattern import PUNCTUATION_SENTENCE, PUNCTUATION_SENTENCE_COMMA, PUNCTUATION_COMMAS
|
||||
|
||||
class CountdownDialog(QDialog):
|
||||
"""Base dialog with auto-accept countdown functionality"""
|
||||
@@ -241,11 +242,6 @@ class ConversionThread(QThread):
|
||||
log_updated = pyqtSignal(object) # Updated signal for log updates
|
||||
chapters_detected = pyqtSignal(int) # Signal for chapter detection
|
||||
|
||||
# Punctuation constants for unified handling across languages
|
||||
PUNCTUATION_SENTENCE = ".!?।。!?"
|
||||
PUNCTUATION_SENTENCE_COMMA = ".!?,।。!?、,"
|
||||
PUNCTUATION_COMMAS = ",,、"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
file_name,
|
||||
@@ -932,7 +928,7 @@ class ConversionThread(QThread):
|
||||
# For Sentence + Comma mode, still split on commas within spaCy sentences
|
||||
if self.subtitle_mode == "Sentence + Comma":
|
||||
active_split_pattern = r"(?<=[{}]){}|\n+".format(
|
||||
self.PUNCTUATION_COMMAS, spacing_pattern
|
||||
PUNCTUATION_COMMAS, spacing_pattern
|
||||
)
|
||||
else:
|
||||
active_split_pattern = (
|
||||
|
||||
Reference in New Issue
Block a user