old-failsafe.pl 5.84 KB
Newer Older
priyank's avatar
priyank committed
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
#!/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";

&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);

					@new_lcath="";


					my(@childs) = &get_children($node,$sent);
					$num_child = @childs;
#Child are been read here 
					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);
#Processing on childrens of Heads 
						if(($lcat[0] eq "unk")&&($pos=~/NN/)) 
						{ $new_lcat[0]="n";}

						elsif(($lcat[0] eq "unk")&&($pos=~/NNP/)) 
						{ $new_lcat[0]="n"; }

						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($output eq "" )
{
	&printstory();
}

else
{
	&printstory_file("$output");
}