From 61df36626cc80afc9e75aa3caa1f9469bb121564 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Thu, 23 Oct 2025 15:09:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BC=96=E8=BE=91=E8=B7=9D?= =?UTF-8?q?=E7=A6=BB=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Convention/Runtime/File.py | 6 +++--- Convention/Runtime/String.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Convention/Runtime/File.py b/Convention/Runtime/File.py index 50551ee..64cdea1 100644 --- a/Convention/Runtime/File.py +++ b/Convention/Runtime/File.py @@ -218,7 +218,7 @@ class ToolFile(BaseModel): with open(self.OriginFullPath, 'rb') as f: return f.read() def LoadAsText(self) -> str: - with open(self.OriginFullPath, 'r') as f: + with open(self.OriginFullPath, 'r', encoding='utf-8') as f: return f.read() def LoadAsWav(self): try: @@ -370,8 +370,8 @@ class ToolFile(BaseModel): f.write(binary_data) return self def SaveAsText(self, text_data:str): - with open(self.OriginFullPath, 'w') as f: - f.writelines(text_data) + with open(self.OriginFullPath, 'w', encoding='utf-8') as f: + f.write(text_data) return self def SaveAsAudio(self, audio_data:"AudioSegment"): ''' diff --git a/Convention/Runtime/String.py b/Convention/Runtime/String.py index 1453146..83317dd 100644 --- a/Convention/Runtime/String.py +++ b/Convention/Runtime/String.py @@ -52,7 +52,10 @@ def word_segmentation( except ImportError: raise ValueError("jieba is not install") -def GetEditorDistanceAndOperations(s1:str, s2:str) -> Tuple[int, List[Tuple[str, int, int, str]]]: +def GetEditorDistanceAndOperations( + s1:str, + s2:str, + ) -> Tuple[int, List[Tuple[Literal["add","delete"], int, int, str]]]: """ 计算两个字符串的编辑距离和操作序列 操作格式: (操作类型, 开始位置, 结束位置, 内容) @@ -112,3 +115,14 @@ def GetEditorDistanceAndOperations(s1:str, s2:str) -> Tuple[int, List[Tuple[str, edit_distance = m + n - 2 * lcs[m][n] return edit_distance, merged_operations +def GetDiffOperations( + s1:str, + s2:str, + ) -> List[Tuple[Literal["add","delete"], int, int, str]]: + """ + 计算两个字符串的差异操作序列 + 操作格式: (操作类型, 开始位置, 结束位置, 内容) + 位置基于源字符串s1 + """ + + return operations \ No newline at end of file