NLP整体流程的代码
import nltk
import numpy as np
import re
from nltk.corpus import stopwords # 1 分词1
text = "Sentiment analysis is a challenging subject in machine learning.\
People express their emotions in language that is often obscured by sarcasm,\
ambiguity, and plays on words, all of which could be very misleading for \
both humans and computers. There's another Kaggle competition for movie review \
sentiment analysis. In this tutorial we explore how Word2Vec can be applied to \
a similar problem.".lower() text_list = nltk.word_tokenize(text) #2 q去掉标点符号和停用词
#去掉标点符号
english_punctuations = [',', '.', ':', ';', '?', '(', ')', '[', ']', '&', '!', '*', '@', '#', '$', '%']
text_list = [word for word in text_list if word not in english_punctuations]
#去掉停用词
stops = set(stopwords.words("english"))
text_list = [word for word in text_list if word not in stops] #3统计词频
freq_dist = nltk.FreqDist(text_list)
freq_list = []
num_words = len(freq_dist.values())
for i in range(num_words):
freq_list.append([list(freq_dist.keys())[i],list(freq_dist.values())[i]])
freqArr = np.array(freq_list)
print(freqArr) #4词性标注
print(nltk.pos_tag(text_list))
NLP整体流程的代码的更多相关文章
- 使用git整体流程
一.git提交代码走meger请求的整体流程 工作中使用git推代码时,如果走merge请求,那么也就是说拉代码时拉公共代码库的代码,但是提交时需要先提交到自己的代码库,然后在gitlab上提交mer ...
- Mybatis技术原理理——整体流程理解
前言:2018年,是最杂乱的一年!所以你看我的博客,是不是很空! 网上有很多关于Mybatis原理介绍的博文,这里介绍两篇我个人很推荐的博文 Mybatis3.4.x技术内幕和 MyBaits源码分析 ...
- [uboot] (第三章)uboot流程——uboot-spl代码流程
http://blog.csdn.net/ooonebook/article/details/52957395 以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为 ...
- 【驱动】input子系统整体流程全面分析(触摸屏驱动为例)【转】
转自:http://www.cnblogs.com/lcw/p/3294356.html input输入子系统整体流程 input子系统在内核中的实现,包括输入子系统(Input Core),事件处理 ...
- linux input输入子系统分析《四》:input子系统整体流程全面分析
1 input输入子系统整体流程 本节分析input子系统在内核中的实现,包括输入子系统(Input Core),事件处理层(Event Handler)和设备驱动层.由于上节代码讲解了设备 ...
- (转)linux内存源码分析 - 内存回收(整体流程)
http://www.cnblogs.com/tolimit/p/5435068.html------------linux内存源码分析 - 内存回收(整体流程) 概述 当linux系统内存压力就大时 ...
- HDFS源码分析DataXceiver之整体流程
在<HDFS源码分析之DataXceiverServer>一文中,我们了解到在DataNode中,有一个后台工作的线程DataXceiverServer.它被用于接收来自客户端或其他数据节 ...
- Okhttp3源码解析(3)-Call分析(整体流程)
### 前言 前面我们讲了 [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析]( ...
- 64位CreateProcess逆向:(二)0环下参数的整合即创建进程的整体流程
转载:https://bbs.pediy.com/thread-207683.htm 点击下面进入总目录: 64位Windows创建64位进程逆向分析(总目录) 在上一篇文章中,我们介绍了Create ...
随机推荐
- MySQL 索引 视图 触发器 存储过程 函数
1.索引 索引相当于图书的目录,可以帮助用户快速的找到需要的内容. 数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万 ...
- BEC translation exercise 2
Forest fires are a regular feature of Chile's hot, arid summers.智利夏天炙热.干燥,常发生森林火灾.A nearly decade-lo ...
- BEC translation exercise 4
People have long known that nuts are part of a healthy diet.人们早就知道坚果是健康饮食的一部分.People, who you know w ...
- pthread_getspecific()--读线程私有数据|pthread_setspecific()--写线程私有数据
原型: #include <pthread.h> void *pthread_getspecific(pthread_key_t key); int pthread_setspecific ...
- UVA - 10723 Alibaba (dp)
给你两个长度不超过30的字符串序列,让你找到一个最短的字符串,使得给定的两个字符串均是它的子序列(不一定连续),求出最短长度以及符合条件的解的个数. 定义状态(a,b,c)为当前字符串长度为a,其中包 ...
- AtCoder Beginner Contest 087 B - Coins
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement You have A 500-yen coi ...
- python模块导入的问题
从模块导入函数时,通常可以使用 import somemodule 或者 from somemodule import somefunction 或者 from somemodule import s ...
- BZOJ3289:Mato的文件管理
浅谈莫队:https://www.cnblogs.com/AKMer/p/10374756.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
- C#中获取Excel文件的第一个表名
// 2.以数据库方式打开并输入数据// 此方式将xls文件所在目录看作数据库,其中的xls文件看作数据库表,表名即文件名(不加扩展名).// 函数importExcelTo ...
- 蓝桥杯 Beaver's Calculator
问题描述 从万能词典来的聪明的海狸已经使我们惊讶了一次.他开发了一种新的计算器,他将此命名为"Beaver's Calculator 1.0".它非常特别,并且被计划使用在各种各样 ...