summaryrefslogtreecommitdiff
path: root/word-aligner
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-01-20 15:35:47 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2012-01-20 15:35:47 -0500
commitf0bdd4de6455855d705d9056deb2e90c999dc740 (patch)
treeac4ebe783d4f613c6f0b01a28210b014f7ba7ed6 /word-aligner
parentd156a65ac638b574abfabfd78c949e122faada5d (diff)
'pseudo model 2' that strictly favors a diagonal, with tunable parameters for p(null) and how sharp/flat the alignment distribution is around the diagonal
Diffstat (limited to 'word-aligner')
-rwxr-xr-xword-aligner/stemmers/ar.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/word-aligner/stemmers/ar.pl b/word-aligner/stemmers/ar.pl
new file mode 100755
index 00000000..c85e883a
--- /dev/null
+++ b/word-aligner/stemmers/ar.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 =~ /^(.st|.n|Al)/) { $el+=2; }
+ if ($w =~ /^(y|t|n)/) { $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";
+ }
+}
+