python nltk 基本操作
来源:互联网 发布:win7网络控制器有叹号 编辑:程序博客网 时间:2024/06/05 20:48
分词
nltk.sent_tokenize(text) #按句子分割
nltk.word_tokenize(sentence) #分词
nltk的分词是句子级别的,所以对于一篇文档首先要将文章按句子进行分割,然后句子进行分词:
词性标注
nltk.pos_tag(tokens) #对分词后的句子进行词性标注
tags = [nltk.pos_tag(tokens) for tokens in words]>>>tags[[('This', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('text', 'NN'), ('for', 'IN'), ('test', 'NN'), ('.', '.')], [('And', 'CC'), ('I', 'PRP'), ('want', 'VBP'), ('to', 'TO'), ('learn', 'VB'), ('how', 'WRB'), ('to', 'TO'), ('use', 'VB'), ('nltk', 'NN'), ('.', '.')]]
分块 Chunking
用于实体识别的基本技术是分块,可以理解为把对个token组成词组。
名词短语分块
NP-chunking,寻找单独名词短语对应的块。为了创建NP分块,首先需要定义分块语法,规定句子如何分块。下面使用的是一个简单的正则,这条规则规定由可选的且后面跟着任意数量形容词(JJ)的限定词(DJ)和名词(NN)组成。
>>> text = "the little yellow dog barked at the cat">>> sentence = nltk.word_tokenize(text)>>> sentence = nltk.pos_tag(sentence)>>> sentence[('the', 'DT'), ('little', 'JJ'), ('yellow', 'NN'), ('dog', 'NN'), ('barked', 'VBD'), ('at', 'IN'), ('the', 'DT'), ('cat', 'NN')]>>> grammar = "NP: {<DT>?<JJ>*<NN>}">>> cp = nltk.RegexpParser(grammar)>>> result = cp.parse(sentence)>>> resultTree('S', [Tree('NP', [('the', 'DT'), ('little', 'JJ'), ('yellow', 'NN')]), Tree('NP', [('dog', 'NN')]), ('barked', 'VBD'), ('at', 'IN'), Tree('NP', [('the', 'DT'), ('cat', 'NN')])])>>> result.draw()
命名实体识别
ref: http://www.pythontip.com/blog/post/10012/
0 0
- python nltk 基本操作
- python NLTK、中文分词
- python NLTK学习
- python NLTK 环境搭建
- Python-NLTK环境搭建
- Python nltk -- Sinica Treebank
- 第一章 Python and NLTK
- python NLTK环境搭建
- python NLTK 环境搭建
- Python NLTK学习
- python+Myeclipse2014+pymongo+NLTK
- Python安装nltk模块
- windows7 安装python +nltk
- [python]NLTK简明教程
- 【python】NLTK-01-入门
- Python自然语言处理(一)--利用NLTK自带方法完成NLP基本任务
- Python自然语言处理(一)--利用NLTK自带方法完成NLP基本任务
- Python自然语言处理(一)--利用NLTK自带方法完成NLP基本任务
- 浅谈设计模式之三——Prototype模式
- Web开发中需要了解的东西
- Eclipse环境配置
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- 处理android studio有时会莫名奇妙无法使用的问题
- python nltk 基本操作
- OAI Kernel Requirements
- ImageView的scaletype属性 总结
- C#中将以0x开头的16进制字符串转换成对应的整数
- 使用XIB创建自定义的View
- Combination Sum II
- C运行库中的安全字符串处理函数(即函数名以_s结尾的函数)
- Eclipse开发Android应用程序入门
- 关于android、java单元测试 案例