初识文本处理工具 - TextBlob

news/2024/7/8 14:13:41 标签: python, 自然语言处理, 情感

  • 综述
  • TextBlob基本介绍
    • 基本功能
    • TextBlob安装
  • 情感分析

综述


本文主要介绍TextBlob基本使用,侧重点在于情感分析。

TextBlob基本介绍


TextBlob是一个用Python编写的开源的文本处理库。它可以用来执行很多自然语言处理的任务,比如,词性标注,名词性成分提取,情感分析,文本翻译,等等。你可以在官方文档阅读TextBlog的所有特性。

基本功能

  • Noun phrase extraction
  • Part-of-speech tagging
  • Sentiment analysis
  • Classification (Naive Bayes, Decision Tree)
  • Language translation and detection powered by Google Translate
  • Tokenization (splitting text into words and sentences)
  • Word and phrase frequencies
  • Parsing
  • n-grams
  • Word inflection (pluralization and singularization) and lemmatization
  • Spelling correction
  • Add new models or languages through extensions
  • WordNet integration

TextBlob安装

$ pip install -U textblob
$ python -m textblob.download_corpora

情感分析">情感分析

情感分析">什么是文本情感分析?


来自wiki百科:文本情感分析
文本情感分析(也称为意见挖掘)是指用自然语言处理、文本挖掘以及计算机语言学等方法来识别和提取原素材中的主观信息。

通常来说,情感分析的目的是为了找出说话者/作者在某些话题上或者针对一个文本两极的观点的态度。这个态度或许是他或她的个人判断或是评估,也许是他当时的情感状态(就是说,作者在做出这个言论时的情绪状态),或是作者有意向的情感交流(就是作者想要读者所体验的情绪)。

文本情感分析的一个基本步骤就是将文本中的某段已知文字的两极性进行分类,这个分类可能是在句子级、功能级。分类的作用就是判断出此文字中表述的观点是积极的、消极的、还是中性的情绪。更高级的“超出两极性”的情感分析还会寻找更复杂的情绪状态,比如“生气”、“悲伤”、“快乐” 等等。

情感分析">使用TextBlob进行情感分析


使用TextBlob情感分析的结果,以元组的方式进行返回,形式如(polarity, subjectivity). 其中polarity的分数是一个范围为 [-1.0 , 1.0 ] 浮点数, 正数表示积极,负数表示消极。subjectivity 是一个 范围为 [0.0 , 1.0 ] 的浮点数,其中 0.0 表示 客观,1.0表示主观的。
情感分析实例:

python hljs ">from textblob import TextBlob
testimonial = TextBlob("Textblob is amazingly simple to use. What great fun!")
print testimonial.sentiment

更多细节:
TextBlob Sentiment: Calculating Polarity and Subjectivity

参考:
【TextBlob】Tutorial: Quickstart
【TextBlob】API Reference


http://www.niftyadmin.cn/n/1427888.html

相关文章

计算机网络-05-数据链路层的差错监测

请看奇偶校验码的局限性: 第一步: 第二步: 第三步骤; 如果余数为0则表示为正确:

leetcode -- 605. Can Place Flowers 【边界处理 + 数学规律】

题目 Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represented as an array containing 0…

leetcode -- 628. Maximum Product of Three Numbers

题目 Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: Input: [1,2,3] Output: 6Example 2: Input: [1,2,3,4] Output: 24Note: The length of the given array will be in range [3,104] and all el…

计算机网络-07-以太网01

使用 Ipconfig /all 查看计算机MAC地址 MAC 是48位,8位一个字节,那么就6个字节,类型占2个字节,其中帧数据和类型相关 如果路由器不知道MAC地址就以广播的方式: 需要继续学习才能解决,请看下面的文章。…

leetcode -- 606. Construct String from Binary Tree【递归 + 字符串优化】

题目 You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pa…

计算机网络-08-网络层之IP协议

主要有两个内容: 1.虚拟互连网络: 从A到B的方式有很多,使用者无需关心。 也就是说把上面那一堆东西,看做成一个网络。 2.IP协议 物理层传输比特流: 数据链路层: IPv4只能和IPv4通信。 标志:占3位(两位有…

计算机网络-09-网络层之IP协议转发流程

1.路由表简介: MAC地址占48位,6个字节 2.IP协议转发流程: 继续理解: 此时会填充源MAC地址和目的MAC地址,源MAC地址为E,目的MAC地址为F. 注意: