Chapter 1.2 分词的优化操作
知识点1.2.1 新词词典的形成
1、搜狗细胞词库
第一步:下载搜狗细胞词库(https://pinyin.sogou.com/dict/)
第二步:下载深蓝输入法词库转换软件,并转换搜狗细胞词库(https://github.com/studyzy/imewlconverter)
第三步:导入新词词典
2、NLPIR(北京理工大学张华平博士)
第一步:下载NLPIR(https://github.com/NLPIR-team/NLPIR)
第二步:进行”新词提取“操作,并形成新词词典
第三步:导入新词词典
知识点1.2.2 新词词典的使用
1、新词词典的格式
格式:一词一行
要素:词、词频(可省略)、词性(可省略),用空格隔开
编码:txt文件必须为UTF-8 编码
2、新词词典的实操
#导入自定义的词典
dict = 'C:\\Users\\dell-pc\\desktop\\新词.txt'
jieba.load_userdict(dict)
#使用jieba.lcut命令进行分词
word_list = jieba.lcut(" ".join(chap1.txt))
print(word_list)
#查看分词结果的个数
dimen = np.array(word_list).shape
print(dimen)
知识点1.2.3 停用词词典的使用
1、停用词词典的格式
格式:一词一行
要素:词
编码:txt文件必须为UTF-8 编码
类型:标点和符号、虚词(副词、介词、连词、叹词、拟声词、助词)、基于实际情况而定的词
2、停用词词典的实操
#导入停用词词典,并查看前10行
stopword = pd.read_csv('C:\\Users\\dell-pc\\desktop\\停用词.txt', names = ['stopword'], sep = ' ', encoding = 'utf-8')
stopword.head(10)
#使用jieba.cut命令进行分词,并去除停用词和空字符串
word_list = [word for word in jieba.cut(" ".join(chap1.txt)) if word not in list(stopword.stopword)]
word_list = [x.strip() for x in word_list if len(x.strip()) > 0]
print(word_list)
#查看分词结果的个数
dimen = np.array(word_list).shape
print(dimen)
知识点1.2.4 词性标注
1、词性标注的标签及含义
标签 | 含义 | 标签 | 含义 | 标签 | 含义 | 标签 | 含义 |
---|---|---|---|---|---|---|---|
n | 普通名词 | f | 方位名词 | s | 处所名词 | t | 时间 |
nr | 人名 | ns | 地名 | nt | 机构名 | nw | 作品名 |
nz | 其他专名 | v | 普通动词 | vd | 动副词 | vn | 名动词 |
a | 形容词 | ad | 副形词 | an | 名形词 | d | 副词 |
m | 数量词 | q | 量词 | r | 代词 | p | 介词 |
c | 连词 | u | 助词 | xc | 其他虚词 | w | 标点符号 |
PER | 人名 | LOC | 地名 | ORG | 机构名 | TIME | 时间 |
2、词性标注的实操
#载入所需要的程序模块
import jieba.posseg as pseg
#使用pseg.cut命令进行分词和词性标注,并print结果
word_list = pseg.cut(" ".join(chap1.txt))
for word, flag in word_list:
print('%s %s' % (word, flag))
#使用pseg.lcut命令进行分词和词性标注,并print结果
word_list = psg.lcut(" ".join(chap1.txt))
print(word_list)