webis-twitter情感识别工具的python包装器

webis的Python项目详细描述


webis twitter情感评估集成的python包装器

这是一个python包装器,它围绕着由Hagen et al. (2015)提出的twitter情感评估框架的java实现。它使用PyJnius调用java模块来评估情绪。

依赖性

脚本是用python 3编写的,依赖于python模块PyJniuspandasemojientities

除此之外,还需要一个Java运行时环境(JRE),外加一个匹配的Java开发工具包(JDK)。我们使用了java 8,但是其他版本也可以。OpenJDK工作正常。

要在基于debian的系统上安装所有依赖项,请运行:

apt-get update -y &&
apt-get install -y python3-dev python3-pip python3-virtualenv cython3 openjdk-8-jdk-headless openjdk-8-jre-headless ca-certificates-java

(有一个archlinux aur包引入了所有依赖项,请参阅下一步)

安装

  • 使用pip或类似:
pip3 install webis
  • 或:手动:

    • 克隆此存储库
    git clone https://gitlab.com/christoph.fink/python-webis.git
    
    • 切换到克隆目录
    • 使用pythonsetuptools安装包:
    cd python-webis
    python3 ./setup.py install
    
  • 或:(仅限Arch Linux)来自AUR

# e.g. using yaourt
yaourt python-webis

使用量

导入webis模块。在第一次运行时,python webis将下载并编译java后端,这可能需要几分钟的时间。

然后实例化一个webis.SentimentIdentifier对象并使用它的identifySentiment()函数,传入一个元组列表([(tweetId, tweetText),(tweetId, tweetText), … ])、一个dict({tweetId: tweetText, … })或一个pandas.DataFrame(第一列作为标识符,第二列作为tweettext)。

函数返回一个元组列表([(tweetId, sentiment), … ])、一个dict({tweetId: sentiment, … })或一个数据帧(第一列id,第二列情感),它成功地标识了一个情感。返回值的类型与调用函数的参数匹配。tweetId值将强制转换为第一行的类型tweetId

importwebissentimentIdentifier=webis.SentimentIdentifier()# list of tuplestweets=[(1,"What a beautiful morning! There’s nothing better than cycling to work on a sunny day ?."),(2,"Argh, I hate it when you find seven (7!) cars blocking the bike lane on a five-mile commute")]tweets=sentimentIdentifier.identifySentiment(tweets)# [(1, "positive"), (2, "negative")]# pandas Dataframeimportpandastweets=pandas.DataFrame([(1,"What a beautiful morning! There’s nothing better than cycling to work on a sunny day ?."),(2,"Argh, I hate it when you find seven (7!) cars blocking the bike lane on a five-mile commute")])tweets=sentimentIdentifier.identifySentiment(tweets)#   sentiment tweetId# 0  positive       1# 1  negative       2# dicttweets={1:"What a beautiful morning! There’s nothing better than cycling to work on a sunny day ?.",2:"Argh, I hate it when you find seven (7!) cars blocking the bike lane on a five-mile commute"}tweets=sentimentIdentifier.identifySentiment(tweets)# { 1: "positive", 2: "negative" }

python-webis可以充当context manager

withwebis.SentimentIdentifier()ass:tweets=s.identifySentiment(tweets)

webis.identifySentiment()是初始化一个SentimentIdentifier对象并调用其identifySentiment()方法的简写方法:

tweets=webis.identifySentiment(tweets)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java ImageIO。写入()低质量图像   使用安卓的设备屏幕大小的java拖放图像   java Adler32重复速度非常快   java在使用Burp Suite Community Edition时遇到此错误   java是否可以在交换机中使用已存在的字符串?   java:把反斜杠看作正常字符的方法   java如何创建Criteria Builder查询来连接三个具有一对一和多对一实体关系的表?   Java Spark:如何在数据集上进行flatMap,并为后续的groupBy提供新的模式?   JavaTestNG运行每个方法,并忽略TestNG中包含的方法。xml   无法使用Java运行linux命令   java我可以用什么来代替AudioPlayer。游戏者停止();?   关于如何使用pop3使用javamail从gmail帐户删除电子邮件的java查询   java Firebase Android数据库查询(读取数据)