summaryrefslogtreecommitdiff
path: root/gi/scfg/abc/Release/process_grammar.pl
diff options
context:
space:
mode:
authorlinh.kitty <linh.kitty@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-13 20:20:55 +0000
committerlinh.kitty <linh.kitty@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-13 20:20:55 +0000
commit298eed4f842bcc01b392a40c4a316110a6347f6c (patch)
tree3b2f4df81bafc58138c7b8f278eae0fc2241eb42 /gi/scfg/abc/Release/process_grammar.pl
parent19dc80f89a047b09010187f2306c85a16b25f575 (diff)
linh added
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@241 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/scfg/abc/Release/process_grammar.pl')
-rw-r--r--gi/scfg/abc/Release/process_grammar.pl36
1 files changed, 36 insertions, 0 deletions
diff --git a/gi/scfg/abc/Release/process_grammar.pl b/gi/scfg/abc/Release/process_grammar.pl
new file mode 100644
index 00000000..f82a8e5a
--- /dev/null
+++ b/gi/scfg/abc/Release/process_grammar.pl
@@ -0,0 +1,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";
+}