From d007133f3f7a13cf010d84d017fa46a258669240 Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Fri, 16 May 2025 18:12:36 +0800 Subject: [PATCH] =?UTF-8?q?update:"=E8=A7=A3=E5=86=B3=E6=95=B0=E5=AD=A6?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=E8=AF=AF=E8=AF=86=E5=88=AB=E9=97=AE=E9=A2=98?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/utils/util.py | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/main/xiaozhi-server/core/utils/util.py b/main/xiaozhi-server/core/utils/util.py index 9ab77a5a7..d59087e06 100644 --- a/main/xiaozhi-server/core/utils/util.py +++ b/main/xiaozhi-server/core/utils/util.py @@ -153,29 +153,29 @@ def get_string_no_punctuation_or_emoji(s): end = len(chars) - 1 while end >= start and is_punctuation_or_emoji(chars[end]): end -= 1 - return "".join(chars[start : end + 1]) + return "".join(chars[start: end + 1]) def remove_punctuation_and_length(text): - # 全角符号和半角符号的Unicode范围 - full_width_punctuations = ( - "!"#$%&'()*+,-。/:;<=>?@[\]^_`{|}~" - ) - half_width_punctuations = r'!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~' + # 定义需要保留的数学符号(全角+半角) + allowed_symbols = {'+', '-', '*', '/', '=', '+', '-', '×', '÷', '='} + + # 需要过滤的标点符号(排除保留的符号) + full_width_punctuations = "!"#$%&'(),。/:;<>?@[\]^_`{|}~" + half_width_punctuations = r'!"#$%&\'(),./:;<>?@[\]^_`{|}~' space = " " # 半角空格 full_width_space = " " # 全角空格 - # 去除全角和半角符号以及空格 - result = "".join( - [ - char - for char in text - if char not in full_width_punctuations - and char not in half_width_punctuations - and char not in space - and char not in full_width_space - ] - ) + # 保留数学符号的过滤逻辑 + result = "".join([ + char + for char in text + if (char not in full_width_punctuations and + char not in half_width_punctuations and + char not in space and + char not in full_width_space) + or char in allowed_symbols + ]) if result == "Yeah": return 0, ""