""" Conversion result data structure. This module provides the ConversionResult class which represents the result of an OMML to LaTeX conversion operation. """ from typing import Optional, List, Dict, Any class ConversionResult: """Result of OMML conversion process. Attributes: success: Whether conversion was successful omml: Original OMML XML string mathml: Intermediate MathML XML string latex: Final LaTeX output context: Surrounding text context from source document position: Position/index of equation in source document source_file: Source file name or path error: Error message if conversion failed warnings: List of warning messages processing_time: Time taken for conversion in seconds display_mode: True for display equations ($$), False for inline ($) Example: >>> result = ConversionResult() >>> result.success = True >>> result.latex = '\\\\frac{1}{2}' >>> result.display_mode = False >>> print(result.to_dict()) {'success': True, 'latex': '\\\\frac{1}{2}', ...} """ def __init__(self): """Initialize conversion result with default values.""" self.success: bool = False self.omml: str = "" self.mathml: str = "" self.latex: str = "" self.context: str = "" self.position: int = 0 self.source_file: str = "" self.error: Optional[str] = None self.warnings: List[str] = [] self.processing_time: float = 0.0 self.display_mode: bool = False # True for display equations ($$), False for inline ($) def to_dict(self) -> Dict[str, Any]: """Convert result to dictionary for JSON serialization. Returns: Dictionary representation of conversion result Example: >>> result = ConversionResult() >>> result.success = True >>> result.latex = 'x + y' >>> data = result.to_dict() >>> print(data['latex']) 'x + y' """ return { 'success': self.success, 'omml': self.omml, 'mathml': self.mathml, 'latex': self.latex, 'context': self.context, 'position': self.position, 'source_file': self.source_file, 'error': self.error, 'warnings': self.warnings, 'processing_time': self.processing_time, 'display_mode': self.display_mode } def __repr__(self) -> str: """Return detailed string representation. Returns: String representation showing key attributes """ status = "Success" if self.success else f"Failed: {self.error}" return f"ConversionResult(position={self.position}, status={status}, latex='{self.latex[:50]}...')" def __str__(self) -> str: """Return human-readable string representation. Returns: User-friendly string representation """ if self.success: return f"Equation {self.position}: {self.latex}" else: return f"Equation {self.position}: ERROR - {self.error}"