Blame view

egs/wsj/s5/local/dict/count_rules.pl 1.06 KB
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  #!/usr/bin/env perl
  
  # This program takes the output of score_prons.pl and collates
  # it for each (rule, destress) pair so that we get the
  # counts of right/partial/wrong for each pair.
  
  # The input is a 7-tuple on each line, like:
  # word;pron;base-word;base-pron;rule-name;de-stress;right|partial|wrong
  #
  # The output format is a 5-tuple like:
  #
  # rule;destress;right-count;partial-count;wrong-count
  #
  
  if (@ARGV != 0 && @ARGV != 1) {
    die "Usage: count_rules.pl < scored_candidate_prons > rule_counts";
  }
  
  
  while(<>) {
    chop;
    $line = $_;
    my ($word, $pron, $baseword, $basepron, $rulename, $destress, $score) = split(";", $line);
    
    my $key = $rulename . ";" . $destress;
  
    if (!defined $counts{$key}) {
      $counts{$key} = [ 0, 0, 0 ]; # new anonymous array.
    }
    $ref = $counts{$key};
    if ($score eq "right") {
      $$ref[0]++;
    } elsif ($score eq "partial") {
      $$ref[1]++;
    } elsif ($score eq "wrong") {
      $$ref[2]++;
    } else {
      die "Bad score $score
  ";
    }
  }
  
  while ( my ($key, $value) = each(%counts)) {
    print $key . ";" . join(";", @$value) . "
  ";
  }