#!/usr/bin/env perl
use strict;
use warnings;

use Lingua::EN::Opinion;

my $input_file = shift || die "Usage: perl $0 /some/file.txt\n";
my $emotion    = shift || 'anger';  # anger, anticipation, disgust, fear, joy, negative, positive, sadness, surprise, trust

my $opinion = Lingua::EN::Opinion->new( file => $input_file );

$opinion->nrc_sentiment();

my %score;
@score{ @{ $opinion->sentences } } = @{ $opinion->nrc_scores };

print "Sentence with the most $emotion:\n",
    [ map {"$score{$_}{$emotion} => $_"} sort { $score{$a}{$emotion} <=> $score{$b}{$emotion} } @{ $opinion->sentences } ]->[-1],
    "\n";
