没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
PYTHON自然语言处理(中文版)
一、语言处理与Python
1、NLTK入门
2、自然语言处理
二、获得文本语料和词汇资料
1、单语料库使用
书籍
网络文本
即时聊天会话语料库
布朗语料库
路透社语料库
就职演说语料库
标注文本语料库:https://www.nltk.org/howto/
词汇列表语料库
其他语言语料库
2、使用自己的预料库
3、生成随机文本
4、条件概率
5、词典语料
6、WordNet
三、加工原料文本
1、从网络和硬盘访问文本
2、编码
3、正则表达式
4、词干提取器(中文不需要)
5、词形归并/词形还原(中文不需要)
6、分词
四、编写结构化程序
五、分类和标注词汇
默认标注器
正则表达式标注器
查询标注器
N-gram标注器
组合标注器
存储标注器
基于转换的标注 - Brill标注
确定词性
六、学习分类文本
性别鉴定
词性分析
序列分类
句子分割
七-十、文法
使用文法
交互式文法编辑器
依存文法
特征结构
十一、语言数据管理
TIMIT
XML
Toolbox
OLAC元数据
PYTHON自然语言处理(中文版)
一、语言处理与Python
1、NLTK入门
下载数据集:输入命令: nltk.download() , 之后选择要下载的数据集(如book)
若
出
现
拒接
连
接
则
将
https://github.com/nltk/nltk_data/tree/gh-pages/packages
文
件全
部
复
制
替换
到
C:\Users[
用
户
名
]\AppData\Roaming\nltk_data
下
即可
解
决
查看模块内容: from nltk.book import *
检索指定词: text1.concordance("monstrous")
检索指定词的上下文: text2.similar("life")
检索多个词共同的上下文: text2.common_contexts(["love", "dear"])
计算指定词从开头算起其前面有多少词: text4.dispersion_plot(["citizens", "democracy",
"freedom", "duties", "America"])
随机生成指定文本风格的文字: text3.generate()
计算特定词出现的次数: text3.count("smote")
获取指定文本的词频信息(字典): fdist1=FreqDist(text1)
检索只出现一次的词: fdist1.hapaxes()
前50高频词累计频率图(cumulative=False是频率分布图): fdist1.plot(50,
cumulative=True)
获取相邻词对: bigrams(['more', 'is', 'than', 'done'])
检索高频双连词: text4.collocations()
检索指定长度的词的数量: fdist.items()
计算词频: fdist.freq('I')
创建频率分布表: fdist.tabulate()
2、自然语言处理
文本对齐:给出一个双语文档,可以自动配对组成句子的过程
二、获得文本语料和词汇资料
1、单语料库使用
书籍
网络文本
即时聊天会话语料库
10-19-20s_706posts.xml表示包括2006年10月19日从20多岁聊天室收集的706个帖子。
布朗语料库
from nltk.corpus import gutenberg # 书籍文本库
gutenberg.fileids() # 获取语料库标识符
emma = gutenberg.words('austen-emma.txt') # 获取《爱玛》语料
emma = nltk.Text(emma) # 获取单个文本检索信息对象
emma.concordance('surprize')
gutenberg.raw('austen-emma.txt') # 原文
gutenberg.words('austen-emma.txt') # 词汇集
gutenberg.sents('austen-emma.txt') # 句子(词链表)
1
2
3
4
5
6
7
8
9
10
from nltk.corpus import webtext # 网络文本集
for fileid in webtext.fileids():
print(fileid, webtext.raw(fileid)[:50])
1
2
3
from nltk.corpus import nps_chat # 即时聊天回话预料库
chatroom = nps_chat.posts('10-19-20s_706posts.xml')
chatroom[123]
1
2
3
比较不同文体中情态动词的用法:
路透社语料库
就职演说语料库
from nltk.corpus import brown # 英语电子预料库
brown.categories()
brown.words(categories='news')
brown.words(fileids=['cg22'])
brown.sents(categories=['news', 'editorial', 'reviews'])
1
2
3
4
5
6
7
8
from nltk.corpus import brown
news_text = brown.words(categories='news')
fdist = nltk.FreqDist([w.lower() for w in news_text]) # 统计词频
modals = ['can', 'could', 'may', 'might', 'must', 'will']
# 显示指定文体的情态动词词频信息
for m in modals:
print(m + ':' + str(fdist[m]))
# 获取不同文体以及对应的词
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', 'will']
# 对指定文体的指定词计算词频
cfd.tabulate(conditions=genres, samples=modals)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from nltk.corpus import reuters # 路透社预料库
reuters.fileids()[:10]
reuters.categories()[:20]
reuters.categories(['training/9865', 'test/14826']) # 获取指定集的类别信息
reuters.fileids(['barley', 'corn'])[:10] # 指定类别查询语料集
reuters.words('training/9865')[:15] # 开头大写的是题目
reuters.words(['training/9865', 'training/9880'])[:15]
reuters.words(categories=['barley'])[:15]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
标注文本语料库:https://www.nltk.org/howto/
词汇列表语料库
其他语言语料库
2、使用自己的预料库
from nltk.corpus import inaugural # 就职演说预料库
inaugural.fileids()[:10]
[fileid[:4] for fileid in inaugural.fileids()][:10] # 获取时间
# 绘制不同词在随时间演讲时的变换
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()
1
2
3
4
5
6
7
8
9
10
11
12
# 过滤高频词汇
def unusual_words(text):
text_vocab = set(w.lower() for w in text if w.isalpha()) # 不重复英文单词
english_vocab = set(w.lower() for w in nltk.corpus.words.words()) # 所有
不重复单词
# 返回text_vocab不同于english_vocab的词
unusual = text_vocab.difference(english_vocab)
return sorted(unusual)
unusual_words(nltk.corpus.gutenberg.words('austen-sense.txt'))[:10]
1
2
3
4
5
6
7
8
9
from nltk.corpus import stopwords # 停用词
stopwords.words('english')[:10]
1
2
from nltk.corpus import udhr # 引入世界人权宣言语料
udhr.fileids()[:20] # 检索语言
# 绘制不同语言在《世界人权宣言》的字长差异
languages = ['Chickasaw', 'English', 'German_Deutsch']
cfd = nltk.ConditionalFreqDist(
(lang, len(word)) for lang in languages
for word in udhr.words(lang + '-Latin1'))
cfd.conditions() # 查看条件,对于每个cfd['xxx']都是一个频率分布
cfd.plot(cumulative=True)
1
2
3
4
5
6
7
8
9
10
11
from nltk.corpus import PlaintextCorpusReader
corpus_root = '.' # 设置路径
wordlists = PlaintextCorpusReader(corpus_root, ".*") # 查询
wordlists.fileids() # 查看文件夹内容
wordlists.words('my_text.txt') # 使用
1
2
3
4
5
6
剩余24页未读,继续阅读
资源评论
甜甜不加糖
- 粉丝: 27
- 资源: 323
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功