版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:[https://blog.csdn.net/github\_39655029/article/details/82893018](https://blog.csdn.net/github_39655029/article/details/82893018)
什么是NLTK
NLTK
,全称Natural Language Toolkit
,自然语言处理工具包,是NLP研究领域常用的一个Python
库,由宾夕法尼亚大学的Steven Bird
和Edward Loper
在Python
的基础上开发的一个模块,至今已有超过十万行的代码。这是一个开源项目,包含数据集、Python
模块、教程等;
怎样安装
详情可以参见我的另一篇博客NLP的开发环境搭建,通过这篇博客,你将学会Python
环境的安装以及NLTK
模块的下载;
常见模块及用途
NLTK能干啥?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018-9-28 22:21
# @Author : Manu
# @Site :
# @File : python_base.py
# @Software: PyCharm
from __future__ import division
import nltk
import matplotlib
from nltk.book import *
from nltk.util import bigrams
# 单词搜索
print('单词搜索')
text1.concordance('boy')
text2.concordance('friends')
# 相似词搜索
print('相似词搜索')
text3.similar('time')
#共同上下文搜索
print('共同上下文搜索')
text2.common_contexts(['monstrous','very'])
# 词汇分布表
print('词汇分布表')
text4.dispersion_plot(['citizens', 'American', 'freedom', 'duties'])
# 词汇计数
print('词汇计数')
print(len(text5))
sorted(set(text5))
print(len(set(text5)))
# 重复词密度
print('重复词密度')
print(len(text8) / len(set(text8)))
# 关键词密度
print('关键词密度')
print(text9.count('girl'))
print(text9.count('girl') * 100 / len(text9))
# 频率分布
fdist = FreqDist(text1)
vocabulary = fdist.keys()
for i in vocabulary:
print(i)
# 高频前20
fdist.plot(20, cumulative = True)
# 低频词
print('低频词:')
print(fdist.hapaxes())
# 词语搭配
print('词语搭配')
words = list(bigrams(['louder', 'words', 'speak']))
print(words)
NLTK设计目标
NLTK中的语料库
gutenberg
;webtext
、nps_chat
;brown
;reuters
;inaugural
;文本语料库结构
基本语料库函数
条件频率分布
总结
以上就是自然语言处理NLP
中NLTK
模块的相关知识介绍了,希望通过本文能解决你对NLTK
的相关疑惑,欢迎评论互相交流!!!