mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-26 23:24:13 +08:00
.
This commit is contained in:
parent
5e19acfe48
commit
3c5b91c35d
@ -1,68 +0,0 @@
|
||||
from myutils.utils import autosql
|
||||
import sqlite3
|
||||
import winsharedutils
|
||||
import os
|
||||
from cishu.cishubase import cishubase, DictTree
|
||||
|
||||
|
||||
class linggesi(cishubase):
|
||||
def init(self):
|
||||
self.sql = None
|
||||
try:
|
||||
if (
|
||||
os.path.exists(os.path.join(self.config["path"], "ja-zh.db")) == False
|
||||
or os.path.exists(os.path.join(self.config["path"], "ja-zh-gbk.db"))
|
||||
== False
|
||||
):
|
||||
return
|
||||
self.sql = autosql(
|
||||
sqlite3.connect(
|
||||
os.path.join(self.config["path"], "ja-zh.db"),
|
||||
check_same_thread=False,
|
||||
)
|
||||
)
|
||||
self.sql2 = sqlite3.connect(
|
||||
os.path.join(self.config["path"], "ja-zh-gbk.db"),
|
||||
check_same_thread=False,
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
def search(self, word):
|
||||
if not self.sql:
|
||||
return
|
||||
mp = {}
|
||||
for sql in [self.sql, self.sql2]:
|
||||
x = sql.execute(
|
||||
"select word,content from entry where word like ?",
|
||||
("%{}%".format(word),),
|
||||
)
|
||||
exp = x.fetchall()
|
||||
|
||||
for w, xx in exp:
|
||||
|
||||
d = winsharedutils.distance(w, word)
|
||||
if d <= self.config["distance"]:
|
||||
mp[w] = [xx, d]
|
||||
|
||||
x = sorted(list(mp.keys()), key=lambda x: mp[x][1])[: self.config["max_num"]]
|
||||
save = [w + "<hr>" + mp[w][0] for w in x]
|
||||
return "<hr>".join(save)
|
||||
|
||||
def tree(self):
|
||||
if not self.sql:
|
||||
return
|
||||
|
||||
class DictTreeRoot(DictTree):
|
||||
def __init__(self, ref) -> None:
|
||||
self.ref = ref
|
||||
|
||||
def childrens(self):
|
||||
c = []
|
||||
for _ in self.ref.sql.execute(
|
||||
"select word from entry"
|
||||
).fetchall():
|
||||
c.append(_[0])
|
||||
return c
|
||||
|
||||
return DictTreeRoot(self)
|
@ -1,67 +0,0 @@
|
||||
import sqlite3, os, re
|
||||
import winsharedutils
|
||||
from myutils.utils import argsort, autosql
|
||||
from cishu.cishubase import cishubase, DictTree
|
||||
|
||||
|
||||
class xiaoxueguan(cishubase):
|
||||
def init(self):
|
||||
self.sql = None
|
||||
try:
|
||||
path = self.config["path"]
|
||||
if os.path.exists(path):
|
||||
self.sql = autosql(sqlite3.connect(path, check_same_thread=False))
|
||||
except:
|
||||
pass
|
||||
|
||||
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),),
|
||||
)
|
||||
exp = x.fetchall()
|
||||
dis = 9999
|
||||
save = []
|
||||
dis = []
|
||||
for w, xx in exp:
|
||||
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)
|
||||
|
||||
srt = argsort(dis)[: self.config["max_num"]]
|
||||
save = ["<span h>" + exp[i][1].replace("\\n", "") for i in srt]
|
||||
return "<hr>".join(save)
|
||||
|
||||
def tree(self):
|
||||
if not self.sql:
|
||||
return
|
||||
|
||||
class DictTreeRoot(DictTree):
|
||||
def __init__(self, ref) -> None:
|
||||
self.ref = ref
|
||||
|
||||
def childrens(self):
|
||||
c = []
|
||||
for _ in self.ref.sql.execute(
|
||||
"select word from xiaoxueguanrizhong"
|
||||
).fetchall():
|
||||
c.append(_[0])
|
||||
return c
|
||||
|
||||
return DictTreeRoot(self)
|
@ -1243,69 +1243,6 @@
|
||||
}
|
||||
},
|
||||
"cishu": {
|
||||
"xiaoxueguan": {
|
||||
"args": {
|
||||
"path": "",
|
||||
"distance": 0,
|
||||
"max_num": 10
|
||||
},
|
||||
"argstype": {
|
||||
"path": {
|
||||
"type": "file",
|
||||
"name": "路径",
|
||||
"dir": false,
|
||||
"filter": "*.db"
|
||||
},
|
||||
"distance": {
|
||||
"type": "intspin",
|
||||
"name": "模糊匹配_编辑距离",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"max_num": {
|
||||
"type": "intspin",
|
||||
"name": "最大结果条数",
|
||||
"min": 0,
|
||||
"max": 9999,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"use": false,
|
||||
"name": "小学馆",
|
||||
"type": "offline"
|
||||
},
|
||||
"linggesi": {
|
||||
"use": false,
|
||||
"name": "灵格斯词典",
|
||||
"args": {
|
||||
"path": "",
|
||||
"distance": 0,
|
||||
"max_num": 10
|
||||
},
|
||||
"argstype": {
|
||||
"path": {
|
||||
"type": "file",
|
||||
"name": "路径",
|
||||
"dir": true
|
||||
},
|
||||
"distance": {
|
||||
"type": "intspin",
|
||||
"name": "模糊匹配_编辑距离",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"max_num": {
|
||||
"type": "intspin",
|
||||
"name": "最大结果条数",
|
||||
"min": 0,
|
||||
"max": 9999,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"type": "offline"
|
||||
},
|
||||
"mojidict": {
|
||||
"use": false,
|
||||
"name": "Moji辞书",
|
||||
|
Loading…
x
Reference in New Issue
Block a user