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
commit5f998b1d600a34f95a5293522167394d3dd37bf6 (patch)
tree187c5b4146e49d5303bf8fb958fe8f488e80647a /word-aligner
parent72b0ebee7d3398dfb657f2949b9e5dac82342198 (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";
+ }
+}
+