feat: Release v0.10 - Modular Architecture & External Config
- Refactor codebase into src/ (preprocessing, translation, assembly) - Add pipeline/ scripts for individual stages - Externalize configuration to config/config.yaml - Fix Cover Image preservation - Update documentation and manuals
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from bs4 import BeautifulSoup
|
||||
from loguru import logger
|
||||
|
||||
# Add project root to path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from src.epub_parser import EPUBParser
|
||||
from src.text_processor import TextProcessor
|
||||
from src.utils import load_config
|
||||
|
||||
def debug_nested_structure(epub_path: str):
|
||||
config = load_config()
|
||||
parser = EPUBParser(epub_path)
|
||||
content_items = parser.extract_all_content_items()
|
||||
|
||||
# Check just one chapter (e.g. Chapter 1)
|
||||
target_item = None
|
||||
for item in content_items:
|
||||
if 'c01' in item['file_name']: # Chapter 1 usually
|
||||
target_item = item
|
||||
break
|
||||
|
||||
if not target_item:
|
||||
target_item = content_items[2] # Fallback to 3rd item
|
||||
|
||||
print(f"Checking file: {target_item['file_name']}")
|
||||
|
||||
soup = BeautifulSoup(target_item['content'], 'html.parser')
|
||||
|
||||
# Simulate TextProcessor extraction logic
|
||||
text_elements = soup.find_all(['p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
||||
'blockquote', 'li', 'td'])
|
||||
|
||||
min_len = config['processing'].get('min_paragraph_length', 30)
|
||||
|
||||
extracted = []
|
||||
|
||||
for i, element in enumerate(text_elements):
|
||||
# Clean text logic
|
||||
clean_text = TextProcessor.clean_element_text(element)
|
||||
|
||||
is_valid = True
|
||||
if len(clean_text) < min_len:
|
||||
is_valid = False
|
||||
if TextProcessor.is_navigation_element(element):
|
||||
is_valid = False
|
||||
|
||||
if is_valid:
|
||||
extracted.append((element, clean_text))
|
||||
|
||||
# Check for nesting
|
||||
# If this element contains other valid extracted elements
|
||||
for prev_el, prev_text in extracted[:-1]:
|
||||
# Check if current element is inside previous element
|
||||
if element in prev_el.descendants:
|
||||
print(f"\n⚠️ NESTING DETECTED!")
|
||||
print(f" Parent: <{prev_el.name}> {prev_text[:50]}...")
|
||||
print(f" Child: <{element.name}> {clean_text[:50]}...")
|
||||
|
||||
# Check if previous element is inside current element
|
||||
if prev_el in element.descendants:
|
||||
print(f"\n⚠️ NESTING DETECTED!")
|
||||
print(f" Parent: <{element.name}> {clean_text[:50]}...")
|
||||
print(f" Child: <{prev_el.name}> {prev_text[:50]}...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python debug_structure.py <epub_file>")
|
||||
sys.exit(1)
|
||||
|
||||
epub_file = sys.argv[1]
|
||||
debug_nested_structure(epub_file)
|
||||
Reference in New Issue
Block a user