From 8780a924a060ced3468b71a088409d5ef83fc985 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Fri, 4 Dec 2009 20:32:11 -0500 Subject: oops, forgot to add tests --- tests/tools/compare-statistics.pl | 49 +++++++++++++++++++++++++++++++++++++++ tests/tools/filter-stderr.pl | 30 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 tests/tools/compare-statistics.pl create mode 100755 tests/tools/filter-stderr.pl (limited to 'tests/tools') diff --git a/tests/tools/compare-statistics.pl b/tests/tools/compare-statistics.pl new file mode 100755 index 00000000..3122c534 --- /dev/null +++ b/tests/tools/compare-statistics.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w +use strict; + +die "Usage: $0 gold.statistics < test.statistics\n" unless scalar @ARGV == 1; + +my $gold_file = shift @ARGV; +open G, "<$gold_file" or die "Can't read $gold_file: $!"; +my @gold_keys = (); +my @gold_vals = (); +while() { + chomp; + if (/^([^ ]+)\s*(.*)$/) { + push @gold_keys, $1; + push @gold_vals, $2; + } else { + die "Unexpected line in $gold_file: $_\n"; + } +} + +my $sc = 0; +my $MATCH = 0; +my $MISMATCH = 0; +while(<>) { + my $gold_key = $gold_keys[$sc]; + my $gold_val = $gold_vals[$sc]; + $sc++; + if (/^([^ ]+)\s*(.*)$/) { + my $test_key = $1; + my $test_val = $2; + if ($test_key ne $gold_key) { + die "Missing key in output! Expected '$gold_key' but got '$test_key'\n"; + } + if ($gold_val ne 'IGNORE') { + if ($gold_val eq $test_val) { $MATCH++; } else { + $MISMATCH++; + print STDERR "[VALUE FAILURE] key: '$gold_key'\n expected value: '$gold_val'\n actual value: '$test_val'\n"; + } + } + } else { + die "Unexpected line in test data: $_\n"; + } +} + +my $TOT = $MISMATCH + $MATCH; + +print "$MATCH $TOT\n"; + +if ($MISMATCH > 0) { exit 1; } else { exit 0; } + diff --git a/tests/tools/filter-stderr.pl b/tests/tools/filter-stderr.pl new file mode 100755 index 00000000..29a97298 --- /dev/null +++ b/tests/tools/filter-stderr.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w +use strict; + +my $REAL = '(\+|-)?[1-9][0-9]*(\.[0-9]*)?|(\+|-)?[1-9]\.[0-9]*e(\+|-)?[0-9]+'; + +while(<>) { +if (/-LM forest\s+\(nodes\/edges\): (\d+)\/(\d+)/) { print "-lm_nodes $1\n-lm_edges $2\n"; } +if (/-LM forest\s+\(paths\): (.+)$/) { print "-lm_paths $1\n"; } +# -LM Viterbi: -12.7893 +if (/-LM\s+Viterbi:\s+($REAL)/) { + print "-lm_viterbi $1\n"; +} elsif (/-LM\s+Viterbi:\s+(.+)$/) { + # -LM Viterbi: australia is have diplomatic relations with north korea one of the few countries . + print "-lm_trans $1\n"; +} +#Constr. forest (nodes/edges): 111/305 +#Constr. forest (paths): 9899 +if (/Constr\. forest\s+\(nodes\/edges\): (\d+)\/(\d+)/) { print "constr_nodes $1\nconstr_edges $2\n"; } +if (/Constr\. forest\s+\(paths\): (.+)$/) { print "constr_paths $1\n"; } + +if (/\+LM forest\s+\(nodes\/edges\): (\d+)\/(\d+)/) { print "+lm_nodes $1\n+lm_edges $2\n"; } +if (/\+LM forest\s+\(paths\): (.+)$/) { print "+lm_paths $1\n"; } +if (/\+LM\s+Viterbi:\s+($REAL)/) { + print "+lm_viterbi $1\n"; +} elsif (/\+LM\s+Viterbi:\s+(.+)$/) { + # -LM Viterbi: australia is have diplomatic relations with north korea one of the few countries . + print "+lm_trans $1\n"; +} + +} -- cgit v1.2.3