mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
update:"解决数学符号误识别问题"
This commit is contained in:
parent
5173dded2a
commit
d007133f3f
1 changed files with 17 additions and 17 deletions
|
|
@ -157,25 +157,25 @@ def get_string_no_punctuation_or_emoji(s):
|
||||||
|
|
||||||
|
|
||||||
def remove_punctuation_and_length(text):
|
def remove_punctuation_and_length(text):
|
||||||
# 全角符号和半角符号的Unicode范围
|
# 定义需要保留的数学符号(全角+半角)
|
||||||
full_width_punctuations = (
|
allowed_symbols = {'+', '-', '*', '/', '=', '+', '-', '×', '÷', '='}
|
||||||
"!"#$%&'()*+,-。/:;<=>?@[\]^_`{|}~"
|
|
||||||
)
|
# 需要过滤的标点符号(排除保留的符号)
|
||||||
half_width_punctuations = r'!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'
|
full_width_punctuations = "!"#$%&'(),。/:;<>?@[\]^_`{|}~"
|
||||||
|
half_width_punctuations = r'!"#$%&\'(),./:;<>?@[\]^_`{|}~'
|
||||||
space = " " # 半角空格
|
space = " " # 半角空格
|
||||||
full_width_space = " " # 全角空格
|
full_width_space = " " # 全角空格
|
||||||
|
|
||||||
# 去除全角和半角符号以及空格
|
# 保留数学符号的过滤逻辑
|
||||||
result = "".join(
|
result = "".join([
|
||||||
[
|
|
||||||
char
|
char
|
||||||
for char in text
|
for char in text
|
||||||
if char not in full_width_punctuations
|
if (char not in full_width_punctuations and
|
||||||
and char not in half_width_punctuations
|
char not in half_width_punctuations and
|
||||||
and char not in space
|
char not in space and
|
||||||
and char not in full_width_space
|
char not in full_width_space)
|
||||||
]
|
or char in allowed_symbols
|
||||||
)
|
])
|
||||||
|
|
||||||
if result == "Yeah":
|
if result == "Yeah":
|
||||||
return 0, ""
|
return 0, ""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue