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

use GD::Graph::lines;
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 $width      = shift || 800;
my $height     = shift || 400;

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

my $size = @{ $opinion->nrc_scores };

my @data = ( 
    [ 1 .. $size ],
    [ map { $_->{$emotion} } @{ $opinion->nrc_scores } ],
);

my $my_graph = GD::Graph::lines->new( $width, $height );

$my_graph->set( 
    x_label => 'Sentence',
    y_label => ucfirst($emotion),
    title => ucfirst($emotion) . ' Over Time',
    transparent => 0,
    dclrs => [qw( black )],
);

my $gd = $my_graph->plot(\@data);

print $gd->png;
