diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-10-31 14:03:22 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-10-31 14:03:22 -0400 |
commit | a769e4964db2443ce165043095e18dfc0d788910 (patch) | |
tree | e813f3aa59fb2f242d029ff04837cbff524df2bd /word-aligner/stemmers/rw.pl | |
parent | 7007550ea4bdba74935c1817a2ba47db8000b5f0 (diff) |
lbfgs + time-series minibatch optimization
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"; + } +} + |