NAME
Lingua::EN::Opinion - Measure the emotional sentiment of text
VERSION
version 0.09
SYNOPSIS
use Lingua::EN::Opinion;
my $opinion = Lingua::EN::Opinion->new( file => '/some/file.txt', stem => 1 );
$opinion->analyze();
my $score = $opinion->averaged_score(5);
my $sentiment = $opinion->get_word('foo');
$sentiment = $opinion->get_sentence('Mary had a little lamb.');
# OR
$opinion = Lingua::EN::Opinion->new( text => 'Mary had a little lamb...' );
$opinion->nrc_sentiment();
# And now do something cool with $opinion->nrc_scores...
$sentiment = $opinion->nrc_get_word('foo');
$sentiment = $opinion->nrc_get_sentence('Mary had a little lamb.');
DESCRIPTION
A Lingua::EN::Opinion
measures the emotional sentiment of text.
* This module is large because of the GIANT sentiment text it comes with.
Please see the eg/ and t/ scripts for example usage.
The write-up illustrating results can be found at http://techn.ology.net/book-of-revelation-sentiment-analysis/
ATTRIBUTES
file
The text file to analyze.
text
A text string to analyze instead of a text file.
stem
Boolean flag to indicate that word stemming should take place.
stemmer
Require the WordNet::QueryData and WordNet::stem modules to stem each word of the provided file or text.
* These modules must be installed and working to use this feature.
sentences
Computed result.
scores
Computed result.
nrc_scores
Computed result.
METHODS
new()
$opinion = Lingua::EN::Opinion->new(%arguments);
Create a new Lingua::EN::Opinion
object.
analyze()
$opinion->analyze();
Measure the positive/negative emotional sentiment of text. This method sets the scores and sentences attributes.
averaged_score()
$averaged = $opinion->averaged_score($bins);
Compute the averaged score given a number of (integer) bins (default: 10).
This reduces the amount of "noise" in the original signal. As such, it loses information detail.
For example, if there are 400 sentences, bins of 10 will result in 40 data points. Each point will be the mean of each successive bin-sized set of points in the analyzed score.
nrc_sentiment()
$opinion->nrc_sentiment();
Compute the NRC sentiment of the given text by sentences.
This is given by a 0/1 list of these 10 emotional elements:
anger
anticipation
disgust
fear
joy
negative
positive
sadness
surprise
trust
This method sets the nrc_scores and sentences attributes.
get_word()
$sentiment = $opinion->get_word($word);
Get the positive/negative sentiment for a given word. Return a HashRef of positive/negative keys. If the word does not exist, return undef
.
nrc_get_word()
$sentiment = $opinion->nrc_get_word($word);
Get the NRC emotional sentiment for a given word. Return a HashRef of the NRC emotions. If the word does not exist, return undef
.
get_sentence()
$values = $opinion->get_sentence($sentence);
Return the positive/negative values for the words of the given sentence.
nrc_get_sentence()
$values = $opinion->nrc_get_sentence($sentence);
Return the NRC emotion values for each word of the given sentence.
SEE ALSO
https://www.cs.uic.edu/~liub/FBS/sentiment-analysis.html#lexicon
http://saifmohammad.com/WebPages/NRC-Emotion-Lexicon.htm
http://techn.ology.net/book-of-revelation-sentiment-analysis/
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.