NLTK英文文本分词的常用模块

目录

1.断句模块:

2.分词模块:

3.去除文本中的除标点符号:

4.去除停用词:

5.词频提取与词频绘图: 

5.1词频的提取

5.2画出词频

5.3画出出现频率最高的三个词

 6.单词搜索


NLTK被常用于 处理语料库、分类文本、分析语言结构 中

https://www.nltk.org/         #NLTK官网有教程

NLTK支持python3.7及以上的版本 

安装分两步

(1)pip install nltk

   (2)去 Gitee网站下载nltk数据包 

nltk.find('.')    #可以找到 nltk在找东西时的调用目录

1.断句模块:

import nltk
from nltk.tokenize import sent_tokenize  #英文断句模块

#要断句的文本
paragraph = 'You must follow me carefully. I shall have to controvert one or twoideas that are almost universally accepted. The geometry, forinstance, they taught you at school is founded on a misconception.'

tokenized_text = sent_tokenize(paragraph)
print(tokenized_text)

tokenized_text输出结果:
['You must follow me carefully.', 'I shall have to controvert one or twoideas that are almost universally accepted.', 'The geometry, forinstance, they taught you at school is founded on a misconception.']

2.分词模块:

from nltk import word_tokenize  #导入分词模块


text = 'You must follow me carefully.'
tokenized_word = word_tokenize(text)
print(tokenized_word)

tokenized_word输出结果:
['You', 'must', 'follow', 'me', 'carefully', '.'] 


3.去除文本中的除标点符号:

import string   #python自带的英文标点模块


punctuation = string.punctuation  #英文标点符号
text = 'You must follow me carefully.' #待处理文本

#设置映射关系: 用空格替代标点=删除掉标点
#translate()函数功能:  用A替代B
text_1 = text.translate(str.maketrans(punctuation, ' ' * len(punct
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值