From 22e05bf807ad59bfad38fcdf35bb51524034e23b Mon Sep 17 00:00:00 2001 From: redpony Date: Thu, 28 Oct 2010 00:22:42 +0000 Subject: change stem handling git-svn-id: https://ws10smt.googlecode.com/svn/trunk@693 ec762483-ff6d-05da-a07a-a48fb63a330f --- word-aligner/aligner.pl | 4 ++++ word-aligner/makefiles/makefile.grammars | 34 ++++++++++++++++++++++------ word-aligner/stemmers/en.pl | 39 ++++++++++++++++++++++++++++++++ word-aligner/stemmers/fr.pl | 39 ++++++++++++++++++++++++++++++++ word-aligner/support/make_lex_grammar.pl | 6 ----- 5 files changed, 109 insertions(+), 13 deletions(-) create mode 100755 word-aligner/stemmers/en.pl create mode 100755 word-aligner/stemmers/fr.pl (limited to 'word-aligner') diff --git a/word-aligner/aligner.pl b/word-aligner/aligner.pl index e23c2beb..508dbd8d 100755 --- a/word-aligner/aligner.pl +++ b/word-aligner/aligner.pl @@ -105,7 +105,9 @@ sub make_stage { my ($direction) = @_; my $stage_dir = "$align_dir/model-$direction"; my $first = $direction; + my $second = $direction; $first =~ s/^(.+)-.*$/$1/; + $second =~ s/^.+-(.+)$/$1/; mkdir $stage_dir; open CDEC, ">$stage_dir/cdec.ini" or die "Can't write $stage_dir/cdec.ini: $!"; print CDEC < e.voc +e.voc: corpus.e + $(EXTRACT_VOCAB) < corpus.e > $@ + +f.voc: corpus.f + $(EXTRACT_VOCAB) < corpus.f > $@ + +orthonorm-dict.e: corpus.e e.voc $(ORTHONORM_E) < e.voc > e.ortho-voc $(MERGE_CORPUS) e.voc e.ortho-voc > $@ -orthonorm-dict.f: corpus.f - $(EXTRACT_VOCAB) corpus.f > f.voc +orthonorm-dict.f: corpus.f f.voc $(ORTHONORM_F) < f.voc > f.ortho-voc $(MERGE_CORPUS) f.voc f.ortho-voc > $@ +# this is just a "stem" map +estem.map: e.voc + $(STEM_E) --vocab < e.voc > $@ + +fstem.map: f.voc + $(STEM_F) --vocab < f.voc > $@ + +# corpus.stemmed.f can use context to do "stemming" +corpus.stemmed.f: corpus.f + $(STEM_F) < corpus.f > $@ + +corpus.stemmed.e: corpus.e + $(STEM_E) < corpus.e > $@ + voc2class.e: corpus.e $(MKCLS) $(MKCLS) -c$(NCLASSES) -n10 -pcorpus.e -Vvoc2class.e opt diff --git a/word-aligner/stemmers/en.pl b/word-aligner/stemmers/en.pl new file mode 100755 index 00000000..2c85dd06 --- /dev/null +++ b/word-aligner/stemmers/en.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 = 4; + if ($w =~ /^(ac|be|un|ad|al|re|co|de|in|im|ab|pr)/) { $el++; } + if ($w =~ /^(trans|inter|under|over)/) { $el+=2; } + 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/fr.pl b/word-aligner/stemmers/fr.pl new file mode 100755 index 00000000..fdf9ff6f --- /dev/null +++ b/word-aligner/stemmers/fr.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 = 4; + if ($w =~ /^(ac|un|ad|al|ré|co|dé|de|in|im|en|em|ab|pr)/) { $el++; } + if ($w =~ /^(trans|inter|under|over)/) { $el+=2; } + 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/support/make_lex_grammar.pl b/word-aligner/support/make_lex_grammar.pl index fb9d0214..3e243125 100755 --- a/word-aligner/support/make_lex_grammar.pl +++ b/word-aligner/support/make_lex_grammar.pl @@ -99,7 +99,6 @@ $oe_dict{''} = ''; my $MIN_FEATURE_COUNT = 0; my $ADD_PREFIX_ID = 1; -my $ADD_CLASS_CLASS = 1; my $ADD_LEN = 1; my $ADD_SIM = 1; my $ADD_DICE = 1; @@ -203,11 +202,6 @@ for my $f (sort keys %fdict) { push @feats, "Dice=$dice"; } } - if ($ADD_CLASS_CLASS) { - my $ce = $eclass{$e} or die "E- no class for: '$e'"; - my $cf = $fclass{$f} or die "F- no class for: '$f'"; - push @feats, "C${cf}_${ce}=1"; - } my $is_null = undef; if ($ADD_NULL && $f eq '') { $is_null = 1; -- cgit v1.2.3