paip.输入法编程---词库多意义条目分割 python实现.
==========子标题
python mysql 数据库操作
多字符分隔,字符串分割
字符列表循环
作者 老哇的爪子 Attilax 艾龙, EMAIL:
[email protected]
来源: http://blog.csdn.net/attilax
===================主要的流程
词库原来格式
carp n.鲤鱼;v.吹毛求疵 813
需要意义分割..
主要的流程如下:
for sqlQuery
{
#多分隔符转换为一个..
clearFmt(row)
clearBrakets
split(",") //
for insert into grejx_def (en,cn)values('@en','@cn')"
}
----------------------实际代码如下
from db import *
#多分隔符转换为一个..
def clearFmt(Ss):
Spos="prep.,pron.,n.,v.,conj.,s.,sc.,o.,oc.,vi.,vt.,aux.v.,a.,ad.,art.,num.,int.,u.,c.,pl.,adj."
print(Spos)
pos_a=Spos.split(",")
for index,v in enumerate(pos_a):
Ss=Ss.replace(v, ",")
Ss=Ss.replace(";", ",")
Ss=Ss.replace(",", ",")
Ss=Ss.replace(" ", "")
Ss=Ss.replace(",,", ",")
Ss=Ss.replace(",,", ",")
Ss=trim(Ss, ",")
print(Ss)
return Ss
""""
Ssx="v.支持,赞成;容忍;n.表情"
clearFmt(Ssx)
"""
def splitInsert(id, cnstr, en):
cnstr=clearFmt(cnstr)
cnstr_a=cnstr.split(",")
for index,v in enumerate(cnstr_a):
sql=" insert into grejx_def (en,cn)values('@en','@cn')"
sql=sql.replace("@en", trim(en)).replace("@cn", v.strip())
print(sql)
reslt= execute(sql)
print("---insert resl:")
print(reslt)
from pkg import *
from pkg.strUtil import *
Sql="SELECT * FROM `grejx_def` where 1=1 and ( nAdjV like '%;%' or nAdjV like '%,%' or nAdjV like '%...%' or nAdjV like '%,%' or nAdjV like '%;%' or LENGTH(nAdjV)>5 ) limit 10000"
print(Sql)
fdata=rs(Sql, conn)
for row in fdata:
print(row)
splitInsert(row['id'], row['nAdjV'], row['en'])
""""
for (en, cn, id) in cursor:
print(cn)
"""