Normalize Chinese Part ordinals and support resumable complete-book translation

This commit is contained in:
Kai Tan
2026-10-08 08:32:05 +08:00
parent 498b5d09ce
commit 644e93b874
12 changed files with 186 additions and 20 deletions
+8 -3
View File
@@ -29,8 +29,9 @@ class FineGrainedExtractor:
r'toc\.x?html',
]
def __init__(self, translate_toc: bool = False):
def __init__(self, translate_toc: bool = False, complete_book: bool = False):
self.translate_toc = translate_toc
self.complete_book = complete_book
self.format_extractor = FormatExtractor()
def extract(self, structure: BookStructure, profile: Optional[BookProfile] = None) -> List[ManifestEntry]:
@@ -42,7 +43,10 @@ class FineGrainedExtractor:
manifest_entries = []
# Iterate over spine to maintain order
for item_id in structure.spine:
item_ids = list(structure.spine)
if self.complete_book:
item_ids.extend(item_id for item_id in structure.resources if item_id not in item_ids)
for item_id in item_ids:
if item_id not in structure.resources:
logger.warning(f"Item ID {item_id} in spine but not in resources.")
continue
@@ -97,8 +101,9 @@ class FineGrainedExtractor:
def _classify_document(self, file_name: str) -> str:
if not file_name: return 'core'
fname = file_name.lower()
if any(re.search(p, fname) for p in self.SKIP_TRANSLATION_PATTERNS): return 'skip'
if any(re.search(p, fname) for p in self.TOC_PATTERNS): return 'toc'
if any(re.search(p, fname) for p in self.SKIP_TRANSLATION_PATTERNS):
return 'core' if self.complete_book else 'skip'
return 'core'
def _should_translate(self, doc_type: str, is_decorative: bool, text: str = "") -> bool: