【语言处理与Python】2.1获取文本语料库
2013-05-22 12:27
579 查看
古藤堡语料库(电子文本档案经过挑选的一小部分文本)
#语料库中所有的文件Import nltk Nltk.corpus.gutenberg.fileids() From nltk.corpus import Gutenberg Gutenberg.fileids() Emma=Gutenberg.words(‘austen-emma.txt’)
#挑选其中的某一部著作进行操作
Emma=nltk.corpus.gutenberg.words(‘austen-emma.txt’) Num_chars=len(Gutenberg.raw(fileid)) Num_words=len(Gutenberg.words(fileid)) Num_sents=len(Gutenberg.sents(fileid)) Num_vocab=len(set([w.lower() for w in Gutenberg.words(fileid)]))
网络和聊天文本
From nltk.corpus import webtext From nltk.corpus import nps_chat
布朗语料库
#对布朗语料库的一些操作:
From nltk.corpus import brown Brown.categories()#语料库的一些分类 Brown.words(categories=’news’)#访问某一文体的单词 Brown.words(fields=[‘cg22’]) Brown.sents(categories=[‘news’,’editorial’,’reviews’]) #使用条件频率分布做一些统计 Cfd=nltk.ConditionalFreqdist( (genre,word) For genre in brown.categories() For word in brown.words(categories=genre) ) Genres=[‘news’,’religion’,’hobbies’,’science_fiction’,’’romance’,’humor’] Modals=[‘can’,’could’,’may’,’might’,’must’m’will’] Cfd.tabulate(conditions=generes,samples=modals)
路透社语料库(新闻文档,分成了90个主题,按照训练和测试分为两组)
就职演说语料库
#使用条件分布做一些统计工作 Cfd=nltk.ConditionalFreqdist( (target,fileid[:4]) For fileid in inaugural.fileids() For w in inaugural.words(fileid) For target in [‘america’,’citizen’] If w.lower().startswith(target) ) Cfd.plot()
标注文本语料库(含有语言学标注,词性标注、命名实体、句法结构、语义角色等)
在其他语言的语料库
文本语料库的结构
载入自己的语料库
#在一些地方可以用匹配符号 From nltk.corpus import PlaintextCorpusReader Corpus_root=’/usr/share/dict’ Wordlists=PlaintextCorpusReader(corpus_root,’.*’) Wordlists.fileids() Wordlists.words(‘connectives’) #在硬盘上的语料库 From nltk.corpus import BracketParseCorpusReader Corpus_root=r”C:\corpura\penntreebank\parsed\mrg\wsj” File_pattern=r”.*/wsj_.*\.mrg” Ptb=BracketParseCorpusReader(corpus_root,file_pattern) Ptb.fileids()
相关文章推荐
- python+NLTK 自然语言学习处理四:获取文本语料和词汇资源
- python3.x如何从互联网获取想要的文章,及转化为nltk可以处理的文本
- 【语言处理与Python】3.2字符串:最底层的文本处理
- 【语言处理与Python】11.1语料库结构:一个案例研究\11.2语料库生命周期
- 流行的脚本语言Python 中的文本处理
- Python语言和标准库(第七章:文本处理)
- 【语言处理与Python】5.1使用词性标注器/5.2标注语料库
- 【语言处理与Python】3.6规范化文本
- [置顶] python语言处理get类型请求,调试模式获取数据代码
- python+NLTK 自然语言学习处理二:文本
- 【语言处理与Python】1.1文本和单词
- 【语言处理与Python】1.2将文本当作词链表
- [Python] 专题五.列表基础知识 二维list排序、获取下标和处理txt文本实例
- 【语言处理与Python】3.7用正则表达式为文本分词
- 【Python】Python文本处理中用langid工具包来对文本进行语言检测与判别
- Python 专题五 列表基础知识(二维list排序、获取下标和处理txt文本实例)
- python+NLTK 自然语言学习处理八:分类文本一
- 【Python】Python与文本处理langid工具包的文本语言检测和歧视
- 【语言处理与Python】3.1从网络和硬盘访问文本
- 【语言处理与Python】8.1一些语法困境