-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_anl.pl
executable file
·123 lines (102 loc) · 2.45 KB
/
client_anl.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl -w
use IO::Socket;
use Getopt::Long;
use strict;
# use xml parser in parameter list.
use XML::Twig;
# Simple command-line client for the server that does the analysis.
#
# Usage: client_anl.pl [OPTIONS]
#
my $language="sme";
my $analyze=0;
my $generate=0;
my $hyphenate=0;
my $preprocess=0;
my $disamb=0;
my $paradigm=0;
my $help;
my $fst;
my $rle;
my $xml=0;
#my $PORT=9000;
my $PORT=8081;
my $param="/home/saara/gt/script/paras.xml";
my $host=`hostname`;
# If we are in G5
if ($host =~ /hum-tf4-ans142/) {
$param="/Users/saara/gt/script/paras.xml";
}
# Allow combination of options, -pad
Getopt::Long::Configure ("bundling");
GetOptions ("lang|l=s" => \$language,
"analyze|a" => \$analyze,
"hyphenate|y" => \$hyphenate,
"generate|g" => \$generate,
"paradigm|r" => \$paradigm,
"preprocess|p" => \$preprocess,
"disamb|d" => \$disamb,
"fst=s" => \$fst,
"rle=s" => \$rle,
"xml|x" => \$xml,
"param=s" => \$param,
"help" => \$help);
if ($help) {
&print_help;
exit 1;
}
my $remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => $PORT,
)
or die "cannot connect to port $PORT at localhost";
$remote->autoflush(1);
my $welcome = <$remote>;
print $welcome;
# Read processing instructions from file.
my $parameters;
if ($param) {
open (FH, "<$param");
while(<FH>) {
$parameters .= $_;
}
}
print $remote "$parameters";
# Take the confirmation of parameters, and possible error.
my $msg = <$remote>;
if ($msg =~ /ERROR/) { print STDERR $msg; exit; }
while(<STDIN>) {
if (/quit|exit/) {
print $remote "END_CLIENT\n";
exit;
}
print $remote "$_";
my $line = <$remote>;
while ($line !~ /^$/) {
print "$line";
$line = <$remote>;
}
}
sub print_help {
print << "END";
Usage: client_anl.pl [OPTIONS]
Call the analysis server and communicate with it.
The available options:
--help Print this help text and exit.
--lang=<lang> Set language to <lang>.
-l lang
--analyze Start the lookup-tool for analysis.
-a
--hyphenate Start the lookup-tool for hyphenation.
-y
--generate Start the lookup-tool for generation.
-g
--paradigm Start the lookup-tool for paradigm generation.
-r
--preprocess Preprocess all the input strings.
-p
--fst=<file> Complete path to the lang.fst. The default is
the fst in opt-hierarchy.
END
}