下载WordNet词库:
wget http://wordnetcode.princeton.edu/3.0/WNprolog-3.0.tar.gz
安装Python模块Whoosh解析词库:
yum -y install python-pip
pip install whoosh
直接加载词库文件并解析:
from whoosh.lang.wordnet import Thesaurus
t = Thesaurus.from_filename("wn_s.pl")
print t.synonyms("hail")
使用索引,生成索引:
from whoosh.filedb.filestore import FileStorage
t = Thesaurus.from_filename("wn_s.pl")
fs = FileStorage("index")
t.to_storage(fs)
通过索引解析:
from whoosh.filedb.filestore import FileStorage
from whoosh.lang.wordnet import Thesaurus
fs = FileStorage("index")
t = Thesaurus.from_storage(fs)
print t.synonyms("hail")
标签:none