diff options
author | Patrick Simianer <p@simianer.de> | 2011-11-03 00:38:49 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2011-11-03 00:38:49 +0100 |
commit | bcfb20c1e1e9434ae04a30240859db6a353457d0 (patch) | |
tree | 4611721111f4fef5bd132ed3236b820c4e16fa9c /word-aligner/stemmers/rw.pl | |
parent | 4df1aea9e6edce1c79059d3310d55947be0a302e (diff) | |
parent | 6de8f58cd13813bf33af4903bf386439683c0fd6 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'word-aligner/stemmers/rw.pl')
-rwxr-xr-x | word-aligner/stemmers/rw.pl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/word-aligner/stemmers/rw.pl b/word-aligner/stemmers/rw.pl new file mode 100755 index 00000000..6d873b40 --- /dev/null +++ b/word-aligner/stemmers/rw.pl @@ -0,0 +1,38 @@ +#!/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 = 5; + if ($w =~ /(ny|jy|nk|nt|sh|cy)/) { $el++; } + 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"; + } +} + |