Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions llm_web_kit/extractor/html/recognizer/cc_math/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,20 @@ def wrap_math(self, s, display=False):

def wrap_math_md(self, s):
"""去掉latex公式头尾的$$或$或\\(\\)或\\[\\]"""
if not s:
return s
s = s.strip()
if s.startswith('$$') and s.endswith('$$'):
return s.replace('$$', '')
return s.replace('$$', '').strip()
if s.startswith('$') and s.endswith('$'):
return s.replace('$', '')
return s.replace('$', '').strip()
if s.startswith('\\(') and s.endswith('\\)'):
return s.replace('\\(', '').replace('\\)', '')
return s.replace('\\(', '').replace('\\)', '').strip()
if s.startswith('\\[') and s.endswith('\\]'):
return s.replace('\\[', '').replace('\\]', '')
return s.replace('\\[', '').replace('\\]', '').strip()
if s.startswith('`') and s.endswith('`'):
return s.replace('`', '')
return s
return s.replace('`', '').strip()
return s.strip()

def wrap_math_space(self, s):
"""转义空格."""
Expand Down
19 changes: 18 additions & 1 deletion tests/llm_web_kit/extractor/html/recognizer/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@
],
'raw_html': '<script type="math/tex"></script>',
'expected': []
},
{
'input': [
('<p>保证生活,可能会影响自己的身心健康。当然,在 不打工的情况下考虑创业, 但是创业是有风险的,在自己没有经济$ $③收入的情况下,考虑打工也会让自己的压力倍增,所以是否选择打工,需要根据自己的实际情况决定!</p>', '<p>保证生活,可能会影响自己的身心健康。当然,在 不打工的情况下考虑创业, 但是创业是有风险的,在自己没有经济$ $③收入的情况下,考虑打工也会让自己的压力倍增,所以是否选择打工,需要根据自己的实际情况决定!</p>')
],
'raw_html': '<p>保证生活,可能会影响自己的身心健康。当然,在 不打工的情况下考虑创业, 但是创业是有风险的,在自己没有经济$ $③收入的情况下,考虑打工也会让自己的压力倍增,所以是否选择打工,需要根据自己的实际情况决定!</p>',
'expected': [('<p>保证生活,可能会影响自己的身心健康。当然,在 不打工的情况下考虑创业, 但是创业是有风险的,在自己没有经济$ $③收入的情况下,考虑打工也会让自己的压力倍增,所以是否选择打工,需要根据自己的实际情况决定!</p>', '<p>保证生活,可能会影响自己的身心健康。当然,在 不打工的情况下考虑创业, 但是创业是有风险的,在自己没有经济$ $③收入的情况下,考虑打工也会让自己的压力倍增,所以是否选择打工,需要根据自己的实际情况决定!</p>')]
}

]

TEST_CASES_HTML = [
Expand Down Expand Up @@ -311,7 +319,16 @@
{
'input': r'\[a^2 + b^2 = c^2\]',
'expected': r'a^2 + b^2 = c^2'
}
},
{
'input': r'`E=mc^2`',
'expected': r'E=mc^2'
},
{
'input': '',
'expected': ''
},

]

TEST_FIX_MATHML_SUPERSCRIPT = [
Expand Down