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