Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning:规范collins, oxford, bnc, frq 字段只能为正数,不能为0. #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions del_bfz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import stardict

# sqlite3 和 csv文件路径,根据实际情况修改
MYSQLITE = 'ecdictSqlite.db'
CSVFILE = 'ecdict.csv'


def new_inflection(exchange):
Expand Down Expand Up @@ -57,7 +59,7 @@ def new_inflection(exchange):

def init_ecdict_sqlite():

stardict.convert_dict(MYSQLITE, 'ecdict.csv')
stardict.convert_dict(MYSQLITE, CSVFILE)
con = sqlite3.connect(MYSQLITE)
cur = con.cursor()

Expand All @@ -80,7 +82,8 @@ def init_ecdict_sqlite():
con.close()


init_ecdict_sqlite() # 只需运行一次,生成sqlite3 db文件
def test_del_bfz():
init_ecdict_sqlite() # 只需运行一次,将CSV文件转换为sqlite3 db文件

# 转换SQLITE为csv文件
stardict.convert_dict('ecdict.csv', MYSQLITE)
# 再将sqlite3 db文件转换回csv文件,覆盖原文件
stardict.convert_dict(CSVFILE, MYSQLITE)
26 changes: 8 additions & 18 deletions stardict.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def __open (self):
"definition" TEXT,
"translation" TEXT,
"pos" VARCHAR(16),
"collins" INTEGER DEFAULT(0),
"oxford" INTEGER DEFAULT(0),
"collins" INTEGER DEFAULT(NULL),
"oxford" INTEGER DEFAULT(NULL),
"tag" VARCHAR(64),
"bnc" INTEGER DEFAULT(NULL),
"frq" INTEGER DEFAULT(NULL),
Expand Down Expand Up @@ -398,8 +398,8 @@ def init (self):
`definition` TEXT,
`translation` TEXT,
`pos` VARCHAR(16),
`collins` SMALLINT DEFAULT 0,
`oxford` SMALLINT DEFAULT 0,
`collins` SMALLINT DEFAULT NULL,
`oxford` SMALLINT DEFAULT NULL,
`tag` VARCHAR(64),
`bnc` INT DEFAULT NULL,
`frq` INT DEFAULT NULL,
Expand Down Expand Up @@ -1774,20 +1774,10 @@ def convert_dict(dstname, srcname):
for word in src.dumps():
pc.next()
data = src[word]
x = data['oxford']
if isinstance(x, int) or isinstance(x, long):
if x <= 0:
data['oxford'] = None
elif isinstance(x, str) or isinstance(x, unicode):
if x == '' or x == '0':
data['oxford'] = None
x = data['collins']
if isinstance(x, int) or isinstance(x, long):
if x <= 0:
data['collins'] = None
elif isinstance(x, str) or isinstance(x, unicode):
if x in ('', '0'):
data['collins'] = None
for i in ['oxford', 'collins', 'frq', 'bnc']:
x = data.get(i)
if not isinstance(x, (int, long)) or x <=0:
data[i] = None
dst.register(word, data, False)
dst.commit()
pc.done()
Expand Down