#!/usr/bin/perl -w
use strict;

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use Getopt::Long;

my $lang;

# Read command line options
&GetOptions("lang=s"=>\$lang);
# If no language option specified, default is English.
$lang="en" unless $lang;
# Check language code validity
die "Illegal language code: $lang\n" unless $lang=~/^(da|de|en|es|fi|fr|it|nl|no|sv)$/;

my $ua=LWP::UserAgent->new();

my $text;

my $authkey='YourAuthenticationKey';

die "Please change the authentication key string in this script.\n" if $authkey eq 'YourAuthenticationKey';

# Read input
while(<>) {
    $text.=$_;
}

my $url= "http://cxserv2.nlpengine.net/serv/tech/fdg1/$lang/";

# Send HTTP request
my $req=POST $url,
      [AuthKey=>$authkey,
       text=>$text];
my $result = $ua->request($req);
# Print output
if($result->is_success) {
    print $result->content, "\n";
} else {
    print $result->status_line;
}

