#!/usr/bin/perl use Getopt::Long; GetOptions("help!"=>\$help,"path=s"=>\$vibh_home,"input=s"=>\$input,"output=s",\$output); print "Unprocessed by Getopt::Long\n" if $ARGV[0]; foreach (@ARGV) { print "$_\n"; exit(0); } if($help eq 1) { print "Failsafe System Version 1.0\n(22th Oct 2009 )\n\n"; print "usage : perl ./failsafe.pl --path=\$PWD [-i inputfile|--input=\"input_file\"] [-o outputfile|--output=\"output_file\"] -rule hin/rule.rl\n"; print "\tIf the output file is not mentioned then the output will be printed to STDOUT\n"; exit(0); } if($vibh_home eq "") { print "Please Specify the Path as defined in --help\n"; exit(0); } require "$vibh_home/API/shakti_tree_api.pl"; require "$vibh_home/API/feature_filter.pl"; open(ROOTDICT,"$vibh_home/suffix"); @ROOTS = ; chomp(@ROOTS); %root_hash = (); foreach $root_1 (@ROOTS) { ($root,$pdgm) = split(/\,/,$root_1); $key = $root; $root_hash{ $key } = $pdgm; } &read_story($input); $numBody = &get_bodycount(); for(my($bodyNum)=1;$bodyNum<=$numBody;$bodyNum++) { $body = &get_body($bodyNum,$body); my($numPara) = &get_paracount($body); for(my($i1)=1;$i1<=$numPara;$i1++) { my($para); $para = &get_para($i1); my($numSent) = &get_sentcount($para); for(my($j1)=1;$j1<=$numSent;$j1++) { $flag = 0; my($sent) = &get_sent($para,$j1); #Read All the heads my @all_childrennp =&get_nodes(3,"NP",$sent); my @all_childrenvgf =&get_nodes(3,"VGF",$sent); my @all_childrenvgnf =&get_nodes(3,"VGNF",$sent); my @all_childrenvgnn =&get_nodes(3,"VGNN",$sent); my @all_childrenjj =&get_nodes(3,"JJP",$sent); my @all_childrencc =&get_nodes(3,"CCP",$sent); my @all_childrenblk =&get_nodes(3,"BLK",$sent); my @all_childrenneg =&get_nodes(3,"NEGP",$sent); my @all_childrenrb =&get_nodes(3,"RBP",$sent); my @all_childrenfrag =&get_nodes(3,"FRAGP",$sent); @all_children=(@all_childrennp,@all_childrenvgf,@all_childrenvgnf,@all_childrenvgnn,@all_childrenjj,@all_childrencc,@all_childrenblk,@all_childrenneg,@all_childrenrb,@all_childrenfrag); $num = @all_children; for($i = 0; $i < $num; $i++) { my @all_childrennp =&get_nodes(3,"NP",$sent); my @all_childrenvgf =&get_nodes(3,"VGF",$sent); my @all_childrenvgnf =&get_nodes(3,"VGNF",$sent); my @all_childrenvgnn =&get_nodes(3,"VGNN",$sent); my @all_childrenjj =&get_nodes(3,"JJP",$sent); my @all_childrencc =&get_nodes(3,"CCP",$sent); my @all_childrenblk =&get_nodes(3,"BLK",$sent); my @all_childrenneg =&get_nodes(3,"NEGP",$sent); my @all_childrenrb =&get_nodes(3,"RBP",$sent); my @all_childrenfrag =&get_nodes(3,"FRAGP",$sent); @all_children=(@all_childrennp,@all_childrenvgf,@all_childrenvgnf,@all_childrenvgnn,@all_childrenjj,@all_childrencc,@all_childrenblk,@all_childrenneg,@all_childrenrb,@all_childrenfrag); $node = $all_children[$i]; #processing on the Head my $posh = &get_field($node, 3,$sent); my $val_fsh=&get_field($node, 4,$sent); $fs_arrayh = &read_FS($val_fsh,$sent); @lcath = &get_values("cat", $fs_arrayh,$sent); if(($lcath[0] eq "unk")&&($posh=~/^V/)) { $new_lcath[0]="v"; } elsif(($lcath[0] eq "unk")&&($posh=~/^NP/)) { $new_lcath[0]="n"; } elsif(($lcath[0] eq "unk")&&($posh=~/^J/)) { $new_lcath[0]="adj"; } elsif(($lcath[0] eq "unk")&&($posh=~/^C/)) { $new_lcath[0]="avy"; } elsif(($lcath[0] eq "unk")&&($posh=~/^RB/)) { $new_lcath[0]="adv"; } elsif(($lcath[0] eq "unk")&&($posh=~/^NE/)) { $new_lcath[0]="v"; } else{$new_lcath[0]=$lcath[0];} &update_attr_val("cat",\@new_lcath,$fs_arrayh,$sent); my $ret_string = &make_string($fs_arrayh,$sent); &modify_field($node,4,$ret_string,$sent); my @new_lcath=""; my(@childs) = &get_children($node,$sent); $num_child = @childs; foreach $child (@childs) { my $pos = &get_field($child, 3,$sent); my $val_fs=&get_field($child, 4,$sent); $fs_array = &read_FS($val_fs,$sent); my @lcat = &get_values("cat", $fs_array,$sent); my @root = &get_values("lex", $fs_array,$sent); if($lcat[0] eq "n"){ if($pos=~/JJ|NN|NNP|QF|WQ|QC|QO|QF|INTJ|NST/){ $posh="NP"; } else{ $posh="NP"; $pos="NN"; } } if($lcat[0] eq "v"){ if(($pos=~/RDP|CL|ECH|VM|VAUX|UT|NEG|INTF|RB|WQ|RP|CC|INTJ|NST/)&&($posh!~/^V/)){ $posh="VGF"; } #elsif($pos=~/PSP/){ # $posh="NP"; #} elsif(($pos=~/QF/)&&($posh!~/^V/)){ $posh="VGNN"; } #elsif($psoh!~/^V/){ # $pos="VM"; # $posh="VGF"; #} } if($lcat[0] eq "pn"){ if($pos=~/PRP|QF|WQ|QF|DEM|NST/){ $posh="NP"; } else{ $pos="PRP"; $posh="NP"; } } if($lcat[0] eq "adj"){ if($pos=~/ECH/){ $posh="VGF"; } } &modify_field($node,3,$posh,$sent); &modify_field($child,3,$pos,$sent); if($lcat[0] eq "unk") { if(($lcat[0] eq "unk")&&($pos=~/NN/)) { #my @new_lcat,@new_gen,@new_num,@new_per; $new_lcat[0]="n"; $new_gen[0]="n"; $new_num[0]="sg"; $new_per[0]="3"; #print "iam here with $pdgm $key \n"; if($root[0]=~/lo$|lopal[A-z]*$|lon[A-z]*$/) { $root[0]=~s/lo.*$//g; $new_vib[0]="lo"; } elsif($root[0]=~/([0-9]*)vIM$/) { $root[0]=~s/vIM//g; $new_vib[0]="vIM"; } elsif($root[0]=~/k[iu]$/) { $root[0]=~s/k[iu]$//g; $new_vib[0]="ku"; } elsif($root[0]=~/n[iu]$/) { $root[0]=~s/n[iu]$//g; $new_vib[0]="nu"; } elsif($root[0]=~/wo$/) { $root[0]=~s/wo//g; $new_vib[0]="wo"; } elsif($root[0]=~/n[ui]M[cd]i$/) { $root[0]=~s/n[iu]M[cd]i$//; $new_vib[0]="niMci"; } elsif($root[0]=~/kosaM$|karaku$/) { $root[0]=~s/kosaM$|karaku$//g; $new_vib[0]="kosaM"; } elsif($root[0]=~/kiMx[A-z]*$/) { $root[0]=~s/kiMx[A-z]*$//g; $new_vib[0]="kiMxa"; } elsif($root[0]=~/pE[A-z]*$/) { $root[0]=~s/pE[A-z]*$//g; $new_vib[0]="pEna"; } else{ $new_vib[0]="0"; } &update_attr_val("lex",\@root,$fs_array,$sent); &update_attr_val("gen",\@new_gen,$fs_array,$sent); &update_attr_val("num",\@new_num,$fs_array,$sent); &update_attr_val("per",\@new_per,$fs_array,$sent); &update_attr_val("vib",\@new_vib,$fs_array,$sent); &update_attr_val("tam",\@new_vib,$fs_array,$sent); my $string1 = &make_string($fs_array,$sent); &modify_field($child,4,$string1,$sent); } elsif(($lcat[0] eq "unk")&&($pos=~/CL/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/VM/)) { $new_lcat[0]="v"; } elsif(($lcat[0] eq "unk")&&($pos=~/VAUX/)) { $new_lcat[0]="v"; } elsif(($lcat[0] eq "unk")&&($pos=~/UT/)) { $new_lcat[0]="v"; } elsif(($lcat[0] eq "unk")&&($pos=~/NEG/)) { $new_lcat[0]="v"; } elsif(($lcat[0] eq "unk")&&($pos=~/JJ/)) { $new_lcat[0]="adj"; } elsif(($lcat[0] eq "unk")&&($pos=~/INTF/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/RB/)) { $new_lcat[0]="adv"; } elsif(($lcat[0] eq "unk")&&($pos=~/PRP/)) { $new_lcat[0]="pn"; } elsif(($lcat[0] eq "unk")&&($pos=~/QF/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/WQ/)) { $new_lcat[0]="pn"; } elsif(($lcat[0] eq "unk")&&($pos=~/PSP/)) { $new_lcat[0]="psp"; } elsif(($lcat[0] eq "unk")&&($pos=~/QC/)) { $new_lcat[0]="num"; } elsif(($lcat[0] eq "unk")&&($pos=~/QO/)) { $new_lcat[0]="num"; } elsif(($lcat[0] eq "unk")&&($pos=~/QF/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/DEM/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/RP/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/CC/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/INJ/)) { $new_lcat[0]="avy"; } elsif(($lcat[0] eq "unk")&&($pos=~/NST/)) { $new_lcat[0]="nst"; } else { $new_lcat[0]=$lcat[0]; } &update_attr_val("cat",\@new_lcat,$fs_array,$sent); my $string = &make_string($fs_array,$sent); &modify_field($child,4,$string,$sent); @new_lcat=""; } if(($posh eq "NP")&&($pos=~/NN/)&&($lcat[0] eq "unk")) { $new_lcat[0]="n"; } if(($posh eq "NP")&&($pos!=~/NN/)&&($lcat[0] eq "unk")) { $new_lcat[0]="n"; } elsif(($posh=~/^V/)&&($pos!=~/V/)&&($lcat[0] eq "unk")) { $new_lcat[0]="v"; } else{ $new_lcat[0]=$lcat[0]; } &update_attr_val("cat",\@new_lcat,$fs_array,$sent); my $string = &make_string($fs_array,$sent); &modify_field($child,4,$string,$sent); @new_lcat=""; } } } } } if($output eq "" ) { &printstory(); } else { &printstory_file("$output"); }