Perl Interactive Client
From Textserver wiki
1 #! /usr/bin/perl
2
3 ########################################################################
4 #
5 # Example client to submit an interactive request to TextServer
6 # SERVICENAME service.
7 # Input may be a plain text or a text file. No ZIP files.
8 # Output will be in the requested format (XML, json, conll)
9 #
10 ########################################################################
11
12 use strict;
13
14 # import needeed libraries
15 use HTTP::Request::Common;
16 use LWP::UserAgent;
17
18 # get query parameters
19 print "Text to analyze: ";
20 my $text=<>; chomp $text;
21 print "Language: ";
22 my $lang=<>; chomp $lang;
23 print "Output format (xml,json,conll,naf): ";
24 my $out=<>; chomp $out;
25 print "TextServer username: ";
26 my $user=<>; chomp $user;
27 print "TextServer password: ";
28 my $pwd=<>; chomp $pwd;
29
30 # URL for the requested service
31 my $service = "SERVICENAME";
32 my $URL = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/processQuery/".$service;
33
34 # create user agent
35 my $ua = LWP::UserAgent->new;
36
37 # send request to server
38 my $resp = $ua->post($URL,
39 Content_Type => 'form-data',
40 Content => [
41 username => $user,
42 password => $pwd,
43 text_input => $text,
44 language => $lang,
45 output => $out,
46 interactive => "1"
47 ]
48 );
49
50
51 # handle errors
52 die $resp->status_line." - ".$resp->decoded_content."\n" unless $resp->is_success;
53
54 # No error, appropriately process response
55 # (e.g. parsing XML or JSON, and doing clever stuff with the content)
56 print $resp->decoded_content."\n";