init: WordFileParse docx→HTML 解析服务(含 Word EQ 域公式修复)
服务:Spring Boot 3.2 + docx4j 8.3.9,POST /api/v3/server_office_file/file/parse
接受 .docx,返回 HTML(公式 → LaTeX,图片 → RustFS 外链)
公式支持三类来源:
- OMML(Word 2007+ 公式) → Python omml_mathml2latex
- MathType OLE 对象 → Ruby mathtype2mathml → MathML → LaTeX
- Word EQ 域(老教辅主力) → EqToLatexUtil(本次新增)
本次改动:
1. 新增 java-svc/.../core/EqToLatexUtil.java:
移植自 jby backend-services office-core,EQ 语法 → LaTeX
(\f→\dfrac、\r→\sqrt、\i→\int/\sum/\prod、\s→^{}/_{}、\b→\left\right、
\a→array、\x→\boxed/\overline、\o\al 堆叠、圈码、化学符号、极限、连等式)
品牌标记 JBYU* → WPU*,与采集端一致
2. CtoMathFinder:接上 EQ 分支(原为 not-ported 桩),域代码经
EqToLatexUtil.convert 转 LaTeX 写入 eqLatexMap(WPEQNUM 占位符)
3. WordParseUtil.dealPlaceholder:EQ 的 LaTeX 同样加 \( \) 包裹
(原先因 WPEQNUM 例外不加包裹,前端/MathJax 不渲染)
修前症状:教辅 Word 里分式/方程组/上下标整段丢失(如 {−1/3, 1} 变成 {-,1})
修后实测:46 份教辅 2908 处 EQ 域全部还原,公式总数 2954 处、零未包裹残留
安全:application.yml(含 RustFS 密钥)不入库,提供 application.yml.example;
OssService 的 @Value 默认密钥已清空
This commit is contained in:
96
scripts/omml_mathml2latex/processing/result.py
Normal file
96
scripts/omml_mathml2latex/processing/result.py
Normal file
@@ -0,0 +1,96 @@
|
||||
"""
|
||||
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}"
|
||||
Reference in New Issue
Block a user