python nltk 入门demo
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 nltk 入门demo的更多相关文章
- Python NLTK 自然语言处理入门与例程(转)
转 https://blog.csdn.net/hzp666/article/details/79373720 Python NLTK 自然语言处理入门与例程 在这篇文章中,我们将基于 Pyt ...
- 【NLP】Python NLTK 走进大秦帝国
Python NLTK 走进大秦帝国 作者:白宁超 2016年10月17日18:54:10 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的一种自然语言工具包,其收集的大量公 ...
- Python 简单入门指北(一)
Python 简单入门指北(一) Python 是一门非常容易上手的语言,通过查阅资料和教程,也许一晚上就能写出一个简单的爬虫.但 Python 也是一门很难精通的语言,因为简洁的语法背后隐藏了许多黑 ...
- 3.Python爬虫入门三之Urllib和Urllib2库的基本使用
1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它是一段HTML代码,加 JS.CSS ...
- Python基础入门总结
Python基础入门教学 基础中的基础 列表.元组(tuple).字典.字符串 变量和引用 函数 python视频教程下载 基础中的基础 解释型语言和编译型语言差距: Python概述 解释器执行原理 ...
- 【NLP】干货!Python NLTK结合stanford NLP工具包进行文本处理
干货!详述Python NLTK下如何使用stanford NLP工具包 作者:白宁超 2016年11月6日19:28:43 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的 ...
- 【NLP】Python NLTK处理原始文本
Python NLTK 处理原始文本 作者:白宁超 2016年11月8日22:45:44 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的一种自然语言工具包,其收集的大量公开 ...
- 【NLP】Python NLTK获取文本语料和词汇资源
Python NLTK 获取文本语料和词汇资源 作者:白宁超 2016年11月7日13:15:24 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的一种自然语言工具包,其收集 ...
- Python 正则表达式入门(中级篇)
Python 正则表达式入门(中级篇) 初级篇链接:http://www.cnblogs.com/chuxiuhong/p/5885073.html 上一篇我们说在这一篇里,我们会介绍子表达式,向前向 ...
随机推荐
- DetachedCriteria和Criteria的使用方法
DetachedCriteria和Criteria的使用方法 /* * 下载统计 * @return */ public String downloadStatistics(){ logger ...
- 【译】x86程序员手册00 - 翻译起因
从上一次学习MIT的操作系统课程又过去了一年.上次学习并没有坚持下去.想来虽有种种原因,其还在自身无法坚持罢了.故此次再鼓起勇气重新学习,发现课程都已由2014改版为2016了.但大部分内容并没有改变 ...
- Python语言之类
1.一个空类 #Filename : emptyclass.py class Empty: pass e = Empty() print( e ) #<__main__.Empty object ...
- day02 python
列表: : 在[ ]内,可以存放多个任意类型的值: 并以逗号隔开. 一般用于存放学生的爱好:课堂的周期等等... 例如: 定义一个学生列表,可存放多个学生 list(['钱垚', '李小龙', '张全 ...
- Redis 之order set有序集合结构及命令详解
1.zadd key score1 value1 score2 value2 添加元素 2.zrem key value1 value2 .. 删除集合中的元素 3.zremrangebyscor ...
- 20180429NOIP提高组精英班Day1测试
- String formatting in Python
| \n | 换行 || \t | 制表符 || \ | 转义 || \\ | \ | the '%' operator is used to format a set of va ...
- 746. Min Cost Climbing Stairs(动态规划)
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- Marshal.ReleaseComObject() vs. Marshal.FinalReleaseComObject()
很简单,不翻译了. If you are using COM components on your .NET code, you might be already aware of the Marsh ...
- Wizard's Tour
F. Wizard's Tour time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...