Python NLTK库中包含着大量的语料库,但是大部分都是英文,不过有一个Sinica(中央研究院)提供的繁体中文语料库,值得我们注意。
在使用这个语料库之前,我们首先要检查一下是否已经安装了这个语料库。
>>>import nltk
>>>nltk.download()
检查箭头所指的sinica_treebank是否安装,如果未安装,则首先要进行安装。
安装完毕后就可以使用了
import nltk
from nltk.corpus import sinica_treebank
print(sinica_treebank.words())
结果:['一', '友情', '嘉珍', '和', '我', '住在', '同一條', '巷子', '我們', ...]
(1)来看一下NLTK中文语法树。
>>>sinica_treebank.parsed_sents()[33].draw()
Python 万岁!!!
(2)搜索中文文本
import nltk
from nltk.corpus import sinica_treebank
sinica_text=nltk.Text(sinica_treebank.words())
print(sinica_text.concordance('我'))