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如何通过循环Id数组设置按钮Id,并使用循环设置按钮文本?   java在一个JTextField中添加字符串和int值   java如何解析2006年2月20日这样的日期?   java Android我试图从SharePreference获取数据   java如何在springboot中将ObjectId转换成字符串   java如何在ListActivity中将按钮返回工具栏   web服务如何使用免费API或web服务从java程序向手机发送短信   java Udp如何从服务器获取整数?   使用DAM资产进行java AEM JUnit测试   数组Java程序循环不会执行并提示用户?   安卓上的java改造2和xml   java 安卓中有字典数据类型吗?   java如何单元测试guice createinjector方法   java无法为Pulsar设置Zookeeper群集   java我无法解密发送消息AES   Java中的tomcat异步   java如何修复“OAutheException,errorMessage:(#803)您请求的某些别名不存在:您的(应用程序)ID}”   java通过构造函数传递整数