python nltk 入门demo
2023-09-14 09:11:55 时间
sudo pip install -U pyyaml nltk
import nltk
nltk.download()
搞不定,必须代理:
Installing via a proxy web server¶
If your web connection uses a proxy server, you should specify the proxy address as follows. In the case of an authenticating proxy, specify a username and password. If the proxy is set to None then this function will attempt to detect the system proxy.
>>> nltk.set_proxy('http://proxy.example.com:3128', ('USERNAME', 'PASSWORD'))
>>> nltk.download()
然后下载:
输入d,下载模块,比如 stopwords等。
import nltk from nltk.stem.lancaster import LancasterStemmer def main(): english_punctuations = set([',', '.', ':', ';', '?', '(', ')', '[', ']', '!', '@', '#', '%', '$', '*']) stemmer = LancasterStemmer() stopwords = set(nltk.corpus.stopwords.words('english')) sentence = """At eight o'clock on Thursday morning Arthur didn't feel very good. interesting booking store.""" sentence = sentence.lower() tokens = nltk.word_tokenize(sentence) for word in tokens: if not word in english_punctuations: if not word in stopwords: word = stemmer.stem(word) print word if __name__ == '__main__': main()
输出:
eight
o'clock
thursday
morn
arth
n't
feel
good
interest
book
stor
相关文章
- Python爬虫从入门到精通——基本库re的使用:正则表达式
- 华为云·云享专家公开课:45分钟掌握Python项目部署与调度核心逻辑直播
- Python学习--18 进程和线程
- Python学习--01入门
- Python 文件I/O
- 小白学 Python 爬虫(32):异步请求库 AIOHTTP 基础入门
- python禁止函数修改列表的实现方法
- 零基础如何快速入门Python自动化办公?
- Python: 爬虫入门-python爬虫入门教程(非常详细)
- 给大家整理了一份麻省理工老师的python笔记,5分钟看会python,原来python入门如此简单ǃ
- Python编程语言学习:基于python各种库(matplotlib、Image)利用多种方法展示图片或进行图片可视化之详细攻略
- Python编程:利用python编程实现对基于时间序列的数据(dataframe格式)按照指定时间范围进行单方向关联,不存在的日期补充为默认的NaN
- Python编程语言学习:python编程语言中重要函数讲解之map函数等简介、使用方法之详细攻略
- Python编程入门指南:从小白到大神
- 〖Python零基础入门篇(57)〗- Python中的日志模块
- python music21 解析midi 文件为音符
- 打基础丨Python图像处理入门知识详解
- python 二分查找代码
- 【华为机试真题 Python实现】统计文本数量
- Python:cached_property缓存对象的属性
- Python编程:实现tail-n查看日志文件
- Python:mysql-connector-python模块对MySQL数据库进行增删改查
- Python科学计算库演示
- 60集Python入门视频PPT整理 | Python编程基础
- python web py入门(68)- jQuery - 按钮事件的响应顺序
- Python 中,字符串"连接"效率最高的方式是?一定出乎你的意料
- 【北京大学】1 TensorFlow1.x中Python基础知识
- Python: 爬虫入门-python爬虫入门教程(非常详细)
- python使用技巧(十八):numpy中np.max和np.maximum
- python的pygame写贪吃蛇小游戏
- ROS Python 入门学习笔记 --3-- 订阅者程序的编写