-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenise.prl
executable file
·90 lines (50 loc) · 1.16 KB
/
tokenise.prl
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
#!/usr/bin/perl -w
################################################################################
#
# Author: Tim Baldwin
#
# Synposis: word and sentence tokenise a Malay text
#
# License: LGPL (see http://malay-toklem.googlecode.com/)
#
# Usage: see README
#
################################################################################
$HOME=".";
$BATCH = 0;
$FPIN = "-";
use Getopt::Long;
# Get Command-Line options.
GetOptions("<>" => sub{$FPIN = $_[0]},
"i=s" => \$FPIN,
"o=s" => \$FPOUT,
"b" => \$BATCH,
"eval" => sub {$FPIN = "$HOME/eval/corpora/corpus.orig"; $BATCH = 1;},
);
if ($BATCH)
{
die "ERROR: must define both input directory (-i) and output directory (-o) in batch mode" unless -d $FPOUT and -d $FPIN;
while (my $IN = <$FPIN/*>)
{
print STDERR "Sentence tokenising $IN ....\n";
$IN =~ /.*\/(.+)/ or die;
my $OUT = "$FPOUT/$1";
&file_tokenise($IN,$OUT);
}
}
else
{
&file_tokenise($FPIN,$FPOUT);
}
sub file_tokenise
{
($IN,$OUT) = @_;
if (defined $OUT)
{
system("cat $IN | $HOME/token > $OUT");
}
else
{
system("cat $IN | $HOME/token ");
}
}