summaryrefslogtreecommitdiff
path: root/word-aligner/stemmers
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-01-23 15:47:29 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2012-01-23 15:47:29 -0500
commit26d9ad04bd81508163d75c99726f970dd75f5127 (patch)
tree9fc49e4cbe8bdabbdd57ee616dc90094f114f255 /word-aligner/stemmers
parentf0bdd4de6455855d705d9056deb2e90c999dc740 (diff)
more alignment stuff
Diffstat (limited to 'word-aligner/stemmers')
-rwxr-xr-xword-aligner/stemmers/ur.pl38
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";
+ }
+}
+