本文主要是使用中科院的分词工具对于数据库中的数据文本进行分词 在电脑上安装python,并导入python与数据库的连接插件MySQLdb 以及中科院的分词工具NLPIR
import pynlpirimport codecsimport math,MySQLdbfrom search import *pynlpir.open()#连接数据库conn=MySQLdb.connect(host="127.0.0.1",user="root",passwd="123456",db="",charset="utf8") cursor = conn.cursor() n = cursor.execute("select * from test where id = 8 ")停用词 st = codecs.open('E://testWord//stopwords.txt', 'rb',encoding='gbk')
读取数据库中的数据
过滤停用词
#过滤停用词 localtion = 0 for word in singletext_result: localtion = localtion + 1 if word not in stopwords: if word >= u'/u4e00' and word <= u'/u9fa5':#判断是否是汉字 delstopwords_singletxt.append(word)构建词表
#构建词表 for item in delstopwords_singletxt: if(search(item)): if(savecount(item)): print 'success to add count' else: if(save(item)): print 'success to add keyword'新闻热点
疑难解答