Skip to main content

An affect generator based on TextBlob and the NRC affect lexicon. Note that lexicon license is for research purposes only.

Project description

NRCLex

(C) 2019 Mark M. Bailey, PhD

About

NRCLex will measure emotional affect from a body of text. Affect dictionary contains approximately 27,000 words, and is based on the National Research Council Canada (NRC) affect lexicon (see link below) and the NLTK library's WordNet synonym sets.

Lexicon source is (C) 2016 National Research Council Canada (NRC) and this package is for research purposes only. Source: http://saifmohammad.com/WebPages/NRC-Emotion-Lexicon.htm As per the terms of use of the NRC Emotion Lexicon, if you use the lexicon or any derivative from it, cite this paper: Crowdsourcing a Word-Emotion Association Lexicon, Saif Mohammad and Peter Turney, Computational Intelligence, 29 (3), 436-465, 2013.

NLTK data is (C) 2019, NLTK Project. Source: [NLTK] (https://www.nltk.org/). Reference: Bird, Steven, Edward Loper and Ewan Klein (2009), Natural Language Processing with Python. O’Reilly Media Inc.

Update

  • Finally got around to cleaning this up a bit. Updated PyPI package with current version. Thanks to all the contributors for cleaning up my terrible code!
  • Expanded NRC lexicon from approximately 10,000 words to 27,000 based on WordNet synonyms.
  • Minor bug fixes.
  • Contributor updated NTC library.

Installation

pip install NRCLex

Affects

Emotional affects measured include the following:

  • fear
  • anger
  • anticipation
  • trust
  • surprise
  • positive
  • negative
  • sadness
  • disgust
  • joy

Sample Usage

from nrclex import NRCLex

#Instantiate NRCLex object, you can pass your own dictionary filename in json format.

text_object = NRCLex(lexicon_file='nrc_en.json')

#You can pass your raw text to this method(for best results, 'text' should be unicode).

text_object.load_raw_text(text: str)

#You can pass your already tokenized text as a list of tokens, if you want to use an already tokenized input. This usage assumes that the text is correctly tokenized and does not make use of TextBlob.

text_object.load_token_list(list_of_tokens: list)

#Return words list.

text_object.words

#Return sentences list.

text_object.sentences

#Return affect list.

text_object.affect_list

#Return affect dictionary.

text_object.affect_dict

#Return raw emotional counts.

text_object.raw_emotion_scores

#Return highest emotions.

text_object.top_emotions

#Return affect frequencies.

text_object.affect_frequencies

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

NRCLex-4.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file NRCLex-4.0-py3-none-any.whl.

File metadata

  • Download URL: NRCLex-4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for NRCLex-4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a73dc8fa03f2d9431552573689af8d001ffad74cc06232dafcda15e389a04ee6
MD5 1038e62dad6924ef71a36393f60d8ef3
BLAKE2b-256 e71d9ed2747da4fdbd098b20c0e7ec8513f14d2c6b6486dbe25eb6e4b9f404a7

See more details on using hashes here.

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