From 6de8f58cd13813bf33af4903bf386439683c0fd6 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Mon, 31 Oct 2011 14:03:22 -0400 Subject: lbfgs + time-series minibatch optimization --- word-aligner/stemmers/mg.pl | 39 +++++++++++++++++++++++++++++++++++++++ word-aligner/stemmers/rw.pl | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 word-aligner/stemmers/mg.pl create mode 100755 word-aligner/stemmers/rw.pl (limited to 'word-aligner/stemmers') diff --git a/word-aligner/stemmers/mg.pl b/word-aligner/stemmers/mg.pl new file mode 100755 index 00000000..2f79a94e --- /dev/null +++ b/word-aligner/stemmers/mg.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() { + chomp; + my @words = split /\s+/; + my @out = (); + for my $w (@words) { + my $tw = $dict{$w}; + if (!defined $tw) { + my $el = 5; + if ($w =~ /(ndz|ndr|nts|ntr)/) { $el++; } + if ($w =~ /^(mp|mb|nd)/) { $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"; + } +} + 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() { + 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"; + } +} + -- cgit v1.2.3