Lingua::EN::Opinion - Measure the emotional sentiment of text
version 0.0801
use Lingua::EN::Opinion; my $opinion = Lingua::EN::Opinion->new( file => '/some/file.txt' ); $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.');
A Lingua::EN::Opinion measures the emotional sentiment of text.
Lingua::EN::Opinion
* 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/
The text file to analyze.
A text string to analyze instead of a text file.
Computed result.
$opinion = Lingua::EN::Opinion->new(%arguments);
Create a new Lingua::EN::Opinion object.
$opinion->analyze();
Measure the positive/negative emotional sentiment of text. This method sets the scores and sentences attributes.
$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.
$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.
$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.
undef
$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.
$values = $opinion->get_sentence($sentence);
Return the positive/negative values for the words of the given sentence.
$values = $opinion->nrc_get_sentence($sentence);
Return the NRC emotion values for each word of the given sentence.
Moo
File::Slurper
Lingua::EN::Sentence
Statistics::Lite
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/
Gene Boggs <gene@cpan.org>
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.
To install Lingua::EN::Opinion, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lingua::EN::Opinion
CPAN shell
perl -MCPAN -e shell install Lingua::EN::Opinion
For more information on module installation, please visit the detailed CPAN module installation guide.