summaryrefslogtreecommitdiff
path: root/tests/tools/flex-diff.pl
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2013-11-28 11:11:22 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2013-11-28 11:11:22 +0100
commitab02696b1c104febc7f13c896acf4165f2721018 (patch)
tree61969895daa79d1d67c90f4adc1de7d91ef3cdfd /tests/tools/flex-diff.pl
parentab63f2f2988e0093a721d0599c7fe68e183561d8 (diff)
parente346cd5cd3c5d7164819c35e485a9850d825996e (diff)
Merge branch 'master' of github.com:pks/cdec-dtrain
Diffstat (limited to 'tests/tools/flex-diff.pl')
-rwxr-xr-xtests/tools/flex-diff.pl46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/tools/flex-diff.pl b/tests/tools/flex-diff.pl
new file mode 100755
index 00000000..30f73c4d
--- /dev/null
+++ b/tests/tools/flex-diff.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/perl -w
+use strict;
+
+my $script_dir; BEGIN { use Cwd qw/ abs_path cwd /; use File::Basename; $script_dir = dirname(abs_path($0)); push @INC, "$script_dir/.."; }
+
+use IPC::Run3;
+
+# this file abstracts away from differences due to different hash
+# functions that lead to different orders of features, n-best entries,
+# etc.
+
+die "Usage: $0 file1.txt file2.txt\n" unless scalar @ARGV == 2;
+my $tmpa = "tmp.$$.a";
+my $tmpb = "tmp.$$.b";
+create_sorted($ARGV[0], $tmpa);
+create_sorted($ARGV[1], $tmpb);
+
+my $failed = 0;
+run3 "diff $tmpa $tmpb";
+if ($? != 0) {
+ run3 "diff $ARGV[0] $ARGV[1]";
+ $failed = 1;
+}
+
+unlink $tmpa;
+unlink $tmpb;
+
+exit $failed;
+
+sub create_sorted {
+ my ($in, $out) = @_;
+ open A, "sort $in|" or die "Can't read $in: $!";
+ open AA, ">$out" or die "Can't write $out: $!";
+ while(<A>) {
+ chomp;
+ s/^\s*//;
+ s/\s*$//;
+ my @cs = split //;
+ @cs = sort @cs;
+ my $o = join('', @cs);
+ print AA "$o\n";
+ }
+ close AA;
+ close A;
+}
+