- 博客(8)
- 资源 (1)
- 收藏
- 关注
原创 第1、2章 分词、词干提取
把文章分为句子 para = "Hello World. It's good to see you. Thanks for buying this book." from nltk.tokenize import sent_tokenize sent_tokenize(para) 把句子分为单词 from nltk.tokenize import word_tokeniz
2015-09-21 00:16:46
1557
原创 第六章 文本分类
def gender_features(word): return {'last_letter':word[-1]} 定义一个性别特征,通过尾字母进行判断 names = ([(name, 'male') for name in names.words('male.txt')] + [(name, 'female') for name in names.words('fem
2015-09-12 18:35:40
591
原创 第五章 分类和词性标注
import nltk text = nltk.word_tokenize("And now for something completely different") a=nltk.pos_tag(text) 分词后进行词性标注,CC是连词,RB是副词,IN是介词,NN是名词,JJ是形容词, 可以使用 nltk.help.upenn_tagset('RB') 查询缩写字
2015-09-07 15:34:36
1060
原创 第四章 编写结构化程序
遍历的几种方法: for item in s 遍历s 中的元素 for item in sorted(s) 按顺序遍历s 中的元素 for item in set(s) 遍历s 中的无重复的元素 for item in reversed(s) 按逆序遍历s 中的元素 for item in set(s).difference(t) 遍历在集合s 中不在集合t 的元素 for item
2015-09-02 16:39:27
504
原创 第三章 原料加工
raw.find("PART I") raw.rfind("End of Project Gutenberg's Crime") 通过find和rfind标记文章的开始和末尾 将要处理的文本拷贝到python文件夹下后, f=open("2008.txt") raw=f.read() words=raw.split() len(words) 转化为单词 逐
2015-08-29 16:37:26
525
原创 第二章 获取文本语料和词汇资源
nltk.corpus.gutenberg.fileids() 加载自带的书籍 emma = nltk.corpus.gutenberg.words('austen-emma.txt') 读取其中一本书,注意此时还无法进行处理 emma=nltk.Text(emma) 将书转化为单词资源 或者 from nltk.corpus import gutenberg gutenb
2015-08-27 20:10:13
574
原创 第一章 Python and NLTK
*搜索文本 import nltk 引入包 nltk.download 下载所需文档 from nltk.book import * 输入全部文档 text1.concordance("monwtrous") 关键字查询 text1.similar("monstrous") 类似词语查询 text4.dispersion_plot(["citizens",
2015-08-24 16:21:40
716
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人