| 1 |
#!/usr/bin/perl |
| 2 |
# Written by <[email protected]>. |
| 3 |
#%DESC List all the sentences that have an error in one batch out file but not the other |
| 4 |
# |
| 5 |
# How to use: |
| 6 |
# lg.old > /tmp/b-old.out |
| 7 |
# lg.new > /tmp/b-new.out |
| 8 |
# lgerror /tmp/b-old.out /tmp/b-new.out |
| 9 |
# |
| 10 |
use warnings; |
| 11 |
use strict; |
| 12 |
|
| 13 |
(my $prog = $0) =~ s/.*\///; |
| 14 |
(my $progdir = $0) =~ s,/[^/]+$,,; |
| 15 |
|
| 16 |
my $W = 250; |
| 17 |
my $zflag; |
| 18 |
|
| 19 |
while (defined $ARGV[0] && $ARGV[0] =~ /^-(.*)/) { |
| 20 |
my $argv = shift; |
| 21 |
my $flag = $1; |
| 22 |
|
| 23 |
$flag eq '-help' and do { |
| 24 |
system("$progdir/sh-flags", $0); |
| 25 |
usage(); |
| 26 |
}; |
| 27 |
$flag eq 'z' and do { #- -0 Be silent on 0 errors |
| 28 |
$zflag = $argv; |
| 29 |
next; |
| 30 |
}; |
| 31 |
} |
| 32 |
|
| 33 |
sub usage |
| 34 |
{ |
| 35 |
die "$prog: Missing file argument.\nUsage: $prog batch-result-old batch-result-new\n"; |
| 36 |
} |
| 37 |
|
| 38 |
my $f1 = shift or usage(); |
| 39 |
my $f2 = shift or usage(); |
| 40 |
|
| 41 |
my $max_width = `cat $f1 $f2 | wc -L` * 2; |
| 42 |
$W = $max_width > $W ? $max_width :$W; |
| 43 |
|
| 44 |
my $cmd = "diff -W $W -y '$f1' '$f2'"; |
| 45 |
open (DIFF, "$cmd|") or die "Cannot open pipe from diff: $!"; |
| 46 |
|
| 47 |
my $sentence; |
| 48 |
my $prev_sentence = ''; |
| 49 |
my $errdiffcnt = 0; |
| 50 |
my $last_bar; |
| 51 |
my %errsentence; |
| 52 |
|
| 53 |
#I hope that he comes to the party tomorrow I hope that ... |
| 54 |
#Found 8 linkages (4 had no P.P. violations) Found 8 linkages ... |
| 55 |
#*I hope him to come to the party tomorrow *I hope him to ... |
| 56 |
# |
| 57 |
# +----------MVpn----------+ |
| 58 |
# +-----WV-----+---MVi---+ | +----Js---+ | |
| 59 |
# +--Wd--+-Sp*i+-Ox-+ +--I--+-MVp-+ +--Ds-+ | |
| 60 |
# | | | | | | | | | | |
| 61 |
#LEFT-WALL I.p hope.v him to.r come.v to.r the party.n tomorrow ... |
| 62 |
# |
| 63 |
#(S (NP I.p) |
| 64 |
# (VP hope.v |
| 65 |
# (NP him) |
| 66 |
# (S (VP to.r |
| 67 |
# (VP come.v |
| 68 |
# (PP to.r |
| 69 |
# (NP the party.n)) |
| 70 |
# (NP tomorrow)))))) |
| 71 |
# |
| 72 |
#+++++ error 5 +++++ error 6 |
| 73 |
|
| 74 |
while (<DIFF>) { |
| 75 |
next if /^%|\s+[<>|]\s%/; |
| 76 |
#print "INPUT->$_"; |
| 77 |
($sentence) = /^([^\t]+)/ unless /^(Found \d|\s|\(|\+|LEFT|$)|[<>|]|\+{5} error/ || $last_bar; |
| 78 |
#print "SENTENCE->$_"; |
| 79 |
if (/\+{5} error/ && !/^\+{5} error \d+[\s|]+\+{5} error/) { |
| 80 |
if ($sentence eq $prev_sentence) { |
| 81 |
delete $errsentence{$sentence}; |
| 82 |
$prev_sentence = $sentence; |
| 83 |
next; |
| 84 |
} |
| 85 |
$errsentence{$sentence} = /^\+/ != ($sentence =~ /^\*/) ? '<' : '>'; |
| 86 |
$prev_sentence = $sentence; |
| 87 |
} |
| 88 |
$last_bar = /\|/ && !/\+{5} error/; |
| 89 |
} |
| 90 |
|
| 91 |
if (close(DIFF) && $! != 0) |
| 92 |
{ |
| 93 |
die "Error closing pipe to diff: $!"; |
| 94 |
} |
| 95 |
|
| 96 |
foreach (sort keys %errsentence) { |
| 97 |
$errdiffcnt++; |
| 98 |
print "$errsentence{$_} $_\n"; |
| 99 |
} |
| 100 |
#print "\n" if $errdiffcnt; |
| 101 |
exit if ($errdiffcnt == 0) && $zflag; |
| 102 |
print "$f1 $f2: Total error differences: $errdiffcnt\n"; |