Skip to main content

Python 3 Wrapper for SentiStrength, reads a single or multiple input with options for binary class or scale output.

Project description

Python-SentiStrength

Python 3 Wrapper for SentiStrength, reads a single or multiple input with options for binary class or scale output.

Ensure that you have SentiStrength.jar file and SentiStrengthData Language folders, otherwise you can download them from http://sentistrength.wlv.ac.uk/. For jar file, you will have to email Dr. Mike Thelwall.

Installation

Pip:

pip install sentistrength

Examples

Example use (single string):

>>> from sentistrength import PySentiStr
>>> senti = PySentiStr()
>>> result = senti.getSentiment('What a lovely day')
>>> print(result)

... [0.25]

Example use (list of strings or pandas Series):

>>> from sentistrength import PySentiStr
>>> senti = PySentiStr()
>>> str_arr = ['What a lovely day', 'What a bad day']
>>> result = senti.getSentiment(str_arr, score='scale')
>>> print(result)

... [1, -1]
# OR, if you want dual scoring (a score each for positive rating and negative rating)
>>> result = senti.getSentiment(str_arr, score='dual')
>>> print(result)

... [(2, -1), (1, -2)]
# OR, if you want binary scoring (1 for positive sentence, -1 for negative sentence)
>>> result = senti.getSentiment(str_arr, score='binary')
>>> print(result)

... [1, -1]
# OR, if you want trinary scoring (a score each for positive rating, negative rating and neutral rating)
>>> result = senti.getSentiment(str_arr, score='trinary')
>>> print(result)

... [(2, -1, 1), (1, -2, -1)]

Path Setup

Specify the paths as such:

>>> senti = PySentiStr()
>>> senti.setSentiStrengthPath('C:/Documents/SentiStrength.jar') # Note: Provide absolute path instead of relative path
>>> senti.setSentiStrengthLanguageFolderPath('C:/Documents/SentiStrengthData/') # Note: Provide absolute path instead of relative path

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Big thanks to Dr. Mike Thelwall for access to SentiStrength.

Project details


Download files

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

Files for sentistrength, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size sentistrength-0.0.9-py3-none-any.whl (3.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sentistrength-0.0.9.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page