summaryrefslogtreecommitdiff
path: root/word-aligner/stemmers/en.pl
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-10-28 00:22:42 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-10-28 00:22:42 +0000
commit22e05bf807ad59bfad38fcdf35bb51524034e23b (patch)
treece537739d375d5216a9558414dd9d8dce065f6fc /word-aligner/stemmers/en.pl
parentecde8cb600b24c31b062f8f53d57641e3fa23379 (diff)
change stem handling
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@693 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'word-aligner/stemmers/en.pl')
-rwxr-xr-xword-aligner/stemmers/en.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/word-aligner/stemmers/en.pl b/word-aligner/stemmers/en.pl
new file mode 100755
index 00000000..2c85dd06
--- /dev/null
+++ b/word-aligner/stemmers/en.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl -w
+
+use strict;
+use utf8;
+
+binmode(STDIN, ":utf8");
+binmode(STDOUT,":utf8");
+
+my $vocab = undef;
+if (scalar @ARGV > 0) {
+ die "Only allow --vocab" unless ($ARGV[0] eq '--vocab' && scalar @ARGV == 1);
+ $vocab = 1;
+}
+
+my %dict;
+while(<STDIN>) {
+ chomp;
+ my @words = split /\s+/;
+ my @out = ();
+ for my $w (@words) {
+ my $tw = $dict{$w};
+ if (!defined $tw) {
+ my $el = 4;
+ if ($w =~ /^(ac|be|un|ad|al|re|co|de|in|im|ab|pr)/) { $el++; }
+ if ($w =~ /^(trans|inter|under|over)/) { $el+=2; }
+ if ($el > length($w)) { $el = length($w); }
+ $tw = substr $w, 0, $el;
+ $dict{$w} = $tw;
+ }
+ push @out, $tw;
+ }
+ if ($vocab) {
+ die "Expected exactly one word per line with --vocab: $_" unless scalar @out == 1;
+ print "$_ @out\n";
+ } else {
+ print "@out\n";
+ }
+}
+