mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
.
This commit is contained in:
parent
dca0be0aa8
commit
5e19acfe48
@ -1,59 +0,0 @@
|
||||
import sqlite3, os
|
||||
import winsharedutils, re
|
||||
from myutils.utils import argsort, autosql
|
||||
from cishu.cishubase import cishubase, DictTree
|
||||
|
||||
|
||||
class edict(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):
|
||||
if not self.sql:
|
||||
return
|
||||
x = self.sql.execute(
|
||||
"select text, entry_id from surface where text like ?",
|
||||
("%{}%".format(word),),
|
||||
)
|
||||
exp = x.fetchall()
|
||||
dis = 9999
|
||||
dis = []
|
||||
for w, xx in exp:
|
||||
d = winsharedutils.distance(w, word)
|
||||
if d <= self.config["distance"]:
|
||||
dis.append(d)
|
||||
save = []
|
||||
srt = argsort(dis)
|
||||
for ii in srt[: self.config["max_num"]]:
|
||||
if exp[ii][1] not in save:
|
||||
save.append(exp[ii][1])
|
||||
saveres = []
|
||||
for _id in save:
|
||||
x = self.sql.execute(
|
||||
"select word, content from entry where id =?", (_id,)
|
||||
).fetchone()
|
||||
saveres.append(x[0] + "<hr>" + re.sub("/EntL.*/", "", x[1][1:]))
|
||||
|
||||
return "<hr>".join(saveres)
|
||||
|
||||
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 text from surface").fetchall():
|
||||
c.append(_[0])
|
||||
return c
|
||||
|
||||
return DictTreeRoot(self)
|
@ -1,58 +0,0 @@
|
||||
import winsharedutils, os
|
||||
import re
|
||||
from myutils.utils import argsort
|
||||
from traceback import print_exc
|
||||
from cishu.cishubase import cishubase, DictTree
|
||||
|
||||
|
||||
class edict2(cishubase):
|
||||
def init(self):
|
||||
self.save = None
|
||||
try:
|
||||
path = self.config["path"]
|
||||
if os.path.exists(path):
|
||||
with open(path, "r", encoding="euc-jp") as ff:
|
||||
_ = ff.read()
|
||||
_ = _.split("\n")[1:]
|
||||
self.save = {}
|
||||
for _l in _:
|
||||
try:
|
||||
_s = _l.index(" ")
|
||||
except:
|
||||
continue
|
||||
self.save[_l[:_s]] = _l[_s:]
|
||||
except:
|
||||
print_exc()
|
||||
|
||||
def search(self, word):
|
||||
if not self.save:
|
||||
return
|
||||
dis = 9999
|
||||
dis = []
|
||||
savew = []
|
||||
for w in self.save:
|
||||
if word in w or w in word:
|
||||
d = winsharedutils.distance(w, word)
|
||||
if d <= self.config["distance"]:
|
||||
dis.append(d)
|
||||
savew.append(w)
|
||||
saveres = []
|
||||
srt = argsort(dis)
|
||||
for ii in srt[: self.config["max_num"]]:
|
||||
saveres.append(
|
||||
savew[ii] + "<hr>" + re.sub("/EntL.*/", "", self.save[savew[ii]][1:])
|
||||
)
|
||||
return "<hr>".join(saveres)
|
||||
|
||||
def tree(self):
|
||||
if not self.save:
|
||||
return
|
||||
|
||||
class DictTreeRoot(DictTree):
|
||||
def __init__(self, ref) -> None:
|
||||
self.ref = ref
|
||||
|
||||
def childrens(self):
|
||||
return list(self.ref.save.keys())
|
||||
|
||||
return DictTreeRoot(self)
|
@ -1275,69 +1275,6 @@
|
||||
"name": "小学馆",
|
||||
"type": "offline"
|
||||
},
|
||||
"edict": {
|
||||
"use": false,
|
||||
"name": "EDICT",
|
||||
"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
|
||||
}
|
||||
},
|
||||
"type": "offline"
|
||||
},
|
||||
"edict2": {
|
||||
"use": false,
|
||||
"name": "EDICT2",
|
||||
"args": {
|
||||
"path": "",
|
||||
"distance": 0,
|
||||
"max_num": 10
|
||||
},
|
||||
"argstype": {
|
||||
"path": {
|
||||
"type": "file",
|
||||
"name": "路径",
|
||||
"dir": false
|
||||
},
|
||||
"distance": {
|
||||
"type": "intspin",
|
||||
"name": "模糊匹配_编辑距离",
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"max_num": {
|
||||
"type": "intspin",
|
||||
"name": "最大结果条数",
|
||||
"min": 0,
|
||||
"max": 9999,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
"type": "offline"
|
||||
},
|
||||
"linggesi": {
|
||||
"use": false,
|
||||
"name": "灵格斯词典",
|
||||
|
Loading…
x
Reference in New Issue
Block a user