Skip to main content

An affect generator based on TextBlob and the NRC affect lexicon.

Project description

NRCLex

(C) 2019 Mark M. Bailey, PhD

About

NRCLex measures emotional affect from text. Affect dictionary contains approximately 27,000 words and is based on the National Research Council Canada (NRC) affect lexicon and NLTK 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. Reference: Bird, Steven, Edward Loper and Ewan Klein (2009), Natural Language Processing with Python. O’Reilly Media Inc.

Installation

pip install NRCLex

Affects

Emotional affects measured include:

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

Sample Usage

from nrclex import NRCLex

Instantiate NRCLex object. By default this loads the bundled lexicon packaged with the library:

text_object = NRCLex()

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 already tokenized text as a list of tokens. This usage does not require TextBlob tokenization:

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 Distribution

nrclex-4.1.0.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nrclex-4.1.0-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file nrclex-4.1.0.tar.gz.

File metadata

  • Download URL: nrclex-4.1.0.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for nrclex-4.1.0.tar.gz
Algorithm Hash digest
SHA256 0fdf04b0b59bf48d8006ac3f96bfda9bfe55a2a31300326fe345ecd35b6ba4a2
MD5 d539f1421ad1effbbbb98b4c6ea639a5
BLAKE2b-256 1ea67218aacd34b4f7b426df240d3d4d67bc35ae5ec9a25f58bf20b1bb871fb3

See more details on using hashes here.

File details

Details for the file nrclex-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: nrclex-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for nrclex-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61d68d09cd6cddf7f2c4ad12d2b5ea13d376a75bf38c7f96ff306e112e96a386
MD5 11a9dc33fc15ba1b3cd544a1ea008ca1
BLAKE2b-256 2d15339ce55f38f9a4309a9db6600cdce878e1d45d5cc1d04e869fa720a8b2fa

See more details on using hashes here.

Supported by

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