Package: webis
Python wrapper for the webis Twitter sentiment evaluation ensembleThis is a Python wrapper around the Java implementation of a Twitter sentiment evaluation framework presented byHagen et al. (2015). It usesPyJniusto call the Java modules to evaluate sentiment.If you usepython-webisfor scientific research, please cite it in your publication:Fink, C. (2019):python-webis: Python wrapper for the webis Twitter sentiment evaluation ensemble.doi:10.5281/zenodo.2547461.DependenciesThe script is written in Python 3 and depends on the Python modulesPyJnius,pandasandemojientities.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.OpenJDKworks fine.To install all dependencies on a Debian-based system, run:apt-getupdate-y&&apt-getinstall-ypython3-devpython3-pippython3-virtualenvcython3openjdk-8-jdk-headlessopenjdk-8-jre-headlessca-certificates-java(There’s an Archlinux AUR package pulling in all dependencies, see further down)Installationusingpipor similar:pip3installwebisOR: manually:Clone this repositorygitclonehttps://gitlab.com/christoph.fink/python-webis.gitChange to the cloned directoryUse the Pythonsetuptoolsto install the package:cdpython-webis
python3./setup.pyinstallOR: (Arch Linux only) fromAUR:# e.g. using yayyaypython-webisUsageImport thewebismodule. On first run,python-webiswill download and compile the Java backend – this might take a few minutes.Then instantiate awebis.SentimentIdentifierobject and use itsidentifySentiment()function, passing in a list of tuples ([(tweetId, tweetText),(tweetId, tweetText), … ]), a dict ({tweetId: tweetText, … }) or apandas.DataFrame(first column is treated as identifier, second as tweetText).The function returns a list of tuples ([(tweetId, sentiment), … ]), a dict ({tweetId: sentiment, … }) or a data frame (first column id, second column sentiment) of rows it successfully identified a sentiment of. The type of the return value matches the argument, with which the function is called. ThetweetIdvalues will be cast to the type of the first row’stweetId.By default messages from the Java classes (written toSystem.outandSystem.err) are suppressed. To print all messages, pass a keyword argumentsuppressJavaMessages=Falseto the constructor ofwebis.SentimentIdentifieror the shorthand functionwebis.identifySentiment(see further down).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-webiscan act as acontext manager:withwebis.SentimentIdentifier()ass:tweets=s.identifySentiment(tweets)webis.identifySentiment()is a short-hand for initialising aSentimentIdentifierobject and calling itsidentifySentiment()method:tweets=webis.identifySentiment(tweets)