diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-01-23 15:47:29 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-01-23 15:47:29 -0500 |
commit | 4ebb11b25cf87dc5938b5eb65e884d0e3f4ee146 (patch) | |
tree | 69966f7d05dff15742e43698d004c183646b2d98 /word-aligner/stemmers | |
parent | 5f998b1d600a34f95a5293522167394d3dd37bf6 (diff) |
more alignment stuff
Diffstat (limited to 'word-aligner/stemmers')
-rwxr-xr-x | word-aligner/stemmers/ur.pl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/word-aligner/stemmers/ur.pl b/word-aligner/stemmers/ur.pl new file mode 100755 index 00000000..3a4f5a45 --- /dev/null +++ b/word-aligner/stemmers/ur.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 = 4; + if ($w =~ /^(al|Al)/) { $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"; + } +} + |