From 7b483f200d1cca96aa9a87ee2e45cd94232f653b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sun, 11 Aug 2024 14:44:08 +0800 Subject: [PATCH] Update xiaoxueguan.py --- .../LunaTranslator/cishu/xiaoxueguan.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/LunaTranslator/LunaTranslator/cishu/xiaoxueguan.py b/LunaTranslator/LunaTranslator/cishu/xiaoxueguan.py index 106e9f96..56538ed6 100644 --- a/LunaTranslator/LunaTranslator/cishu/xiaoxueguan.py +++ b/LunaTranslator/LunaTranslator/cishu/xiaoxueguan.py @@ -1,4 +1,4 @@ -import sqlite3, os +import sqlite3, os, re import winsharedutils from myutils.utils import argsort, autosql @@ -15,9 +15,13 @@ class xiaoxueguan(cishubase): except: pass - def search(self, word): + def search(self, word: str): if not self.sql: return + if word in "【】": + return + if not word.strip(): + return x = self.sql.execute( "select word,explanation from xiaoxueguanrizhong where word like ?", ("%{}%".format(word),), @@ -27,8 +31,17 @@ class xiaoxueguan(cishubase): save = [] dis = [] for w, xx in exp: - - d = winsharedutils.distance(w, word) + w: str = w.strip() + if w.startswith("-"): + w = w[1:] + match1 = re.match("(.*?)【(.*?)】", w) + if match1: + pr, w = match1.groups() + d = min( + winsharedutils.distance(pr, word), winsharedutils.distance(w, word) + ) + else: + d = winsharedutils.distance(w, word) if d <= self.config["distance"]: dis.append(d)