《用Python进行自然语言处理》代码笔记(三):第三章 加工原料文本
来源:互联网 发布:手机淘宝怎么换支付宝 编辑:程序博客网 时间:2024/04/25 08:36
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Author : Peidong# @Site : # @File : eg3.py# @Software: PyCharm"""加工原料文本"""# 从网络上访问文本import nltkfrom urllib.request import urlopenurl = "http://www.gutenberg.org/files/2554/2554.txt"raw = urlopen(url).read()print(type(raw))print(len(raw))print(raw[:75])# 分词tokens = nltk.word_tokenize(str(raw))print(type(tokens))print(len(tokens))print(tokens[:10])# 读取本地文件f = open('账号密码.txt')raw = f.read()print(raw)# 字符串操作示例a = [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]b = [' ' * 2 * (7-i) + 'very'*i for i in a]for line in b: print(b)a = u'\u0061'print(a)# 查看文本中两个或;两个以上的元音序列,并得出其相对频率import nltkimport rewsj = sorted(set(nltk.corpus.treebank.words()))fd = nltk.FreqDist(vs for word in wsj for vs in re.findall(r'[aeiou]{2,}', word))print(fd.items())# 将字符串分割成不同的字母a = 'hello python'b = '?'.join(a)print(b)import networkx as nxfrom matplotlib import pyplotfrom nltk.corpus import wordnet as wndef traverse(graph, start, node): graph.depth[node.name] = node.shortest_path_distance(start) for child in node.hyponyms(): graph.add_edge(node.name, child.name) traverse(graph, start, child)def hyponym_graph(start): G = nx.Graph() G.depth = {} traverse(G, start, start) return Gdef graph_draw(graph): nx.draw_graphviz(graph, node_size=[16 * graph.degree(n) for n in graph], node_color=[graph.depth[n] for n in graph], with_labels=False)pyplot.show()dog = wn.synset('dog.n.01')graph = hyponym_graph(dog)graph_draw(graph)
0 0
- 《用Python进行自然语言处理》代码笔记(三):第三章 加工原料文本
- 《python自然语言处理》笔记---chap3加工原料文本
- 《用Python进行自然语言处理》代码笔记(五):第七章:从文本提取信息
- 第三章 原料加工
- 《用Python进行自然语言处理》代码笔记(二):第二章 获得文本语料和词汇资源
- 《用Python进行自然语言处理》代码笔记(四):第五章 分类和标注词
- 第3章 加工原料文本
- 《Python进行自然语言处理》代码笔记(一):第一章示例
- python自然语言处理学习笔记第三章
- python自然语言处理笔记-第三章
- 用Python进行自然语言处理-笔记
- (初学者)用Python进行自然语言处理笔记一
- 《Python自然语言处理》学习笔记(三)
- 《使用Python进行自然语言处理》学习笔记三
- 《使用Python进行自然语言处理》学习笔记三
- 《使用Python进行自然语言处理》学习笔记三
- python 自然语言处理 第三章
- python 自然语言处理第三章
- ES6中Array的学习
- Android 中InputMethodManager类的用法
- vue.js2.0 自定义组件初体验
- ButterKnife的使用
- OpenCV——Install in Linux OS
- 《用Python进行自然语言处理》代码笔记(三):第三章 加工原料文本
- About Session, Graph, Operation and Tensor
- Ubuntu安装后,远程配置 ssh
- MongoDB 中的关系
- ffmpeg参考手册
- 海康威视2017软件精英挑战赛初赛题目
- 树的子结构
- 根据优先关系矩阵使用逐次加一发构造优先函数(Java)
- 报错Error:(11) No resource identifier found for attribute 'roundIcon' in package