Skip to main content

Python wrapper for the webis Twitter sentiment identification tool

Project description

Python wrapper for the webis Twitter sentiment evaluation ensemble

This is a Python wrapper around the Java implementation of a Twitter sentiment evaluation framework presented by Hagen et al. (2015). The example script fetches Tweets from a PostgreSQL database, uses PyJnius to call the Java modules to evaluate the sentiment, and saves results to a table in the same database.

Dependencies

The script depends on the Python modules PyJnius, pandas and emojientities.

On top of that, a Java Runtime Environment (jre) is required, plus a matching Java Development Kit (jdk). We used Java 8, but other versions might work just as well. OpenJDK works fine.

Installation

  • using pip or similar:
pip install webis
  • manually:

    • Clone this repository
    git clone https://gitlab.com/christoph.fink/python-webis.git
    
    • Change to the cloned directory
    • Use the Python setuptools to install the package:
    cd python-webis
    python ./setup.py install
    

Usage

First, make sure the environment variable JAVA_HOME is set and pointing to your Java installation.

Then instantiate a webis.SentimentIdentifier object and use its identifySentiment() function, passing in a list of tuples ([(tweetId, tweetText),(tweetId, tweetText), … ]) or a pandas.DataFrame (first column is treated as identifier, second as tweetText).

The function returns a list of tuples ([(tweetId, sentiment), … ]) or a data frame (first column id, second column sentiment) of rows it successfully identified a sentiment of.

import webis

sentimentIdentifier = webis.SentimentIdentifier()

tweets = [
    (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")
]

sentimentIdentifier.identifySentiment(tweets)
# [(1, "positive"), (2, "negative")]

import pandas
tweets = pandas.DataFrame(tweets)
sentimentIdentifier.identifySentiment(tweets)
#   sentiment tweetId
# 0  positive       1
# 1  negative       2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webis-0.1.1.tar.gz (17.8 kB view hashes)

Uploaded Source

Built Distribution

webis-0.1.1-py3-none-any.whl (19.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page