summaryrefslogtreecommitdiff
path: root/gi/scfg/abc/Release/process_grammar.pl
blob: f82a8e5aca10adfaf30b29c643bdf4d8b0d264eb (plain)
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
#!perl

use warnings;
use strict;

my $grammar_file = $ARGV[0];

my %nt_count; #maps nt--> count rules whose lhs is nt 

open(G, "<$grammar_file") or die "Can't open file $grammar_file";

while (<G>){

    chomp();

    s/\|\|\|.*//g;
    s/\s//g;

    $nt_count{$_}++;
}


close (G);

open(G, "<$grammar_file") or die "Can't open file $grammar_file";

while (<G>){

    chomp();

    (my $nt = $_) =~ s/\|\|\|.*//g;
    $nt =~ s/\s//g;

    s/(.+\|\|\|.+\|\|\|.+\|\|\|).+/$1/g;
    print $_ . " MinusLogP=" .(log($nt_count{$nt})) ."\n";
}