mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-01 10:04:12 +08:00
Update xiaoxueguan.py
This commit is contained in:
parent
461ddefe13
commit
7b483f200d
@ -1,4 +1,4 @@
|
|||||||
import sqlite3, os
|
import sqlite3, os, re
|
||||||
import winsharedutils
|
import winsharedutils
|
||||||
from myutils.utils import argsort, autosql
|
from myutils.utils import argsort, autosql
|
||||||
|
|
||||||
@ -15,9 +15,13 @@ class xiaoxueguan(cishubase):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def search(self, word):
|
def search(self, word: str):
|
||||||
if not self.sql:
|
if not self.sql:
|
||||||
return
|
return
|
||||||
|
if word in "【】":
|
||||||
|
return
|
||||||
|
if not word.strip():
|
||||||
|
return
|
||||||
x = self.sql.execute(
|
x = self.sql.execute(
|
||||||
"select word,explanation from xiaoxueguanrizhong where word like ?",
|
"select word,explanation from xiaoxueguanrizhong where word like ?",
|
||||||
("%{}%".format(word),),
|
("%{}%".format(word),),
|
||||||
@ -27,8 +31,17 @@ class xiaoxueguan(cishubase):
|
|||||||
save = []
|
save = []
|
||||||
dis = []
|
dis = []
|
||||||
for w, xx in exp:
|
for w, xx in exp:
|
||||||
|
w: str = w.strip()
|
||||||
d = winsharedutils.distance(w, word)
|
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"]:
|
if d <= self.config["distance"]:
|
||||||
dis.append(d)
|
dis.append(d)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user