failsafe.pm 21.8 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
package ILMT::TEL::HIN::Repair::failsafe;

use Dir::Self;
use Exporter qw(import);
use ILMT::TEL::HIN::SSFAPI::feature_filter;
use ILMT::TEL::HIN::SSFAPI::shakti_tree_api;

our @EXPORT = qw(failsafe);

my $cwd = __DIR__;

my %root_hash = ();
my %vgnf_hash = ();

sub preprocess {

    open(ROOTDICT,"$cwd/failsafe/data/suffix");
    @ROOTS = <ROOTDICT>;
    chomp(@ROOTS);

    open(VGNFTAM,"$cwd/failsafe/data/vgnf-tam");
    @VGNFT = <VGNFTAM>;
    chomp(@VGNFT);

    foreach my $root_1 (@ROOTS)
    {
	my ($root,$pdgm) = split(/\,/,$root_1);
	my $key = $root;
	$root_hash{ $key } = $pdgm;
    }

    foreach my $vgnftam (@VGNFT)
    {
	my ($root,$pdgm) = split(/\,/,$vgnftam);
	my $key = $root;
	$vgnf_hash{ $key } = $pdgm;
    }

}

sub failsafe {
    my %par = @_;
    my $input = $par{'data'};
    read_story(\$input);
    my $result;

    my $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/)&&($posh!~/VGNF/))) {
                        $new_lcath[0]="v";
                    }
                    elsif(($lcath[0] eq "unk")&&(($posh=~/^NP/)||($posh=~/VGNF/))) {
                        $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";
                    }
                    ###
                    #elsif(($lcath[0] eq "unk")&&($posh=~/BLK/)&&($pos eq "PSP")) {

                    ###
                    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;
#Children are been read here 
                    foreach $child (@childs)
                    {
                        my $pos = &get_field($child, 3,$sent);
                        my $npos = &get_field($child-1, 3,$sent);
                        my $token = &get_field($child, 2,$sent);
                        my $val_fs=&get_field($child, 4,$sent);
                        $fs_array = &read_FS($val_fs,$sent);

                        #if($val_fs=~/[0-9],[0-9][^_']/){
                        #	$val_fs=~s/([0-9]),([0-9])/$1\&comma;$2/g;
                        #	&modify_field($child,4,$val_fs,$sent);
                        #}
                        my @lcat = &get_values("cat", $fs_array,$sent);
                        my @root = &get_values("lex", $fs_array,$sent);
                        if(($npos=~/Q/)&&($token=~/^sAr[lAiuUeo]/)){
                            $root[0]="sAri";
                            &update_attr_val("lex",\@root,$fs_array,$sent);
                            my $string1 = &make_string($fs_array,$sent);
                            &modify_field($child,4,$string1,$sent);
                        }

                        my @new_vib = &get_values("vib", $fs_array,$sent);

                        # some one blocked this, can i know why- chris-261112
                        ##my @new_vib = &get_values("vib", $fs_array,$sent);

#Processing on childrens of Heads if they are unk 
                        $key=$new_vib[0];
                        $pdgm=$vgnf_hash{$key};
                        chomp($pdgm);
                        if(($posh eq "VGF")&&($pos eq "VM")&&($pdgm eq "yes")){
                            $newposh="VGNF";
                            &modify_field($node,3,$newposh,$sent);
                        }
                        if(($pos=~/VM/)&&($lcat[0]=~/n/)&&($val_fs=~/deri/)){
                            my @new_lcat;
                            $new_lcat[0]="v";
                            &update_attr_val("cat",\@new_lcat,$fs_array,$sent);
                            my $string = &make_string($fs_array,$sent);
                            &modify_field($child,4,$string,$sent);
                        }

                        if(($pos=~/RB/)&&($lcat[0]=~/avy/)){
                            my @new_lcat;
                            $new_lcat[0]="adv";
                            &update_attr_val("cat",\@new_lcat,$fs_array,$sent);
                            my $string = &make_string($fs_array,$sent);
                            &modify_field($child,4,$string,$sent);
                        }

                        if(($lcat[0]=~/^v/)&&($new_vib[0]=~/wU_uMdu_wU_uMdu_A/)){
                            #print "Imhere\n";
                            #	my @new_lcat;
                            $new_vib[0]="wU_uMdu_wA";
                            &update_attr_val("vib",\@new_vib,$fs_array,$sent);
                            &update_attr_val("tam",\@new_vib,$fs_array,$sent);
                            #&update_attr_val("cat",\@new_lcat,$fs_array,$sent);
                            my $string = &make_string($fs_array,$sent);
                            &modify_field($child,4,$string,$sent);
                        }


                        if($lcat[0] eq "unk")
                        {
                            if(($lcat[0] eq "unk")&&($pos eq "RB")){
                                $new_lcat[0]="adv";
                                if($root[0]=~/gA$/) { 
                                    $root[0]=~s/gA$//g;
                                    $new_vib[0]="gA"; 
                                }
                                &update_attr_val("lex",\@root,$fs_array,$sent);
                                &update_attr_val("vib",\@new_vib,$fs_array,$sent);
                                my $string1 = &make_string($fs_array,$sent);
                                &modify_field($child,4,$string1,$sent);
                            }
                            elsif(($lcat[0] eq "unk")&&(($pos=~/NN/)||($posh=~/VGNF/))) { 
                                $new_lcat[0]="n";
                                $new_gen[0]="n";
                                $new_num[0]="sg";
                                $new_per[0]="3";

                                $new_vib[0]=~s/.*/0/;
#print "iam here with $pdgm $key \n";
                                if($root[0]=~/lone$/) { 
                                    $root[0]=~s/lone$//g;
                                    $new_vib[0]="lone"; 
                                }
                                if($root[0]=~/nenA$/) {  ##harinenA => hariwAnYA
                                    $root[0]=~s/nenA$//g;
                                    $new_vib[0]="nenA"; 
                                }
                                if($root[0]=~/loki$/) { 
                                    $root[0]=~s/loki$//g;
                                    $new_vib[0]="loki"; 
                                }
                                if($root[0]=~/lo$|lopal[A-z]*$/) { 
                                    $root[0]=~s/lo.*$//g;
                                    $new_vib[0]="lo"; 
                                    ##print "new_vib=$new_vib[0]\n";
                                }
                                if($root[0]=~/guriwo$/) {  ##Aruguriwo
                                    $root[0]=~s/guriwo$/guru/g;
                                    $new_vib[0]="wo"; 
                                    ##print "new_vib=$new_vib[0]\n";
                                }

                                if($root[0]=~/([0-9]+)lak[iu]$/) { 
#$root[0]=~s/k[iu]$//g;
                                    $root[0]=~s/([0-9]+)lak[iu]$/$1/g;  
                                    #$new_gen[0]="n";
                                    ##$new_num[0]="pl";
                                    $new_num[0]="sg";
                                    $new_lcat[0]="num";
                                    $new_vib[0]="ki"; 
                                }
                                if($root[0]=~/([0-9]+)k[iu]$/) { 
#$root[0]=~s/k[iu]$//g;
                                    $root[0]=~s/([0-9]+)k[iu]$/$1/g;  
                                    #$new_gen[0]="n";
                                    ##$new_num[0]="pl";
                                    $new_num[0]="sg";
                                    $new_lcat[0]="num";
                                    $new_vib[0]="ki"; 
                                }
                                if($root[0]=~/Aniki$/) { ##SawAbxAniki
                                    $root[0]=~s/Aniki$/aM/g;
                                    $new_vib[0]="ki"; 
                                }

                                if($root[0]=~/([A-z]+)k[iu]$/) { 
                                    $root[0]=~s/k[iu]$//g;
                                    $new_vib[0]="ki"; 
                                }
                                if($root[0]=~/[^BGCJN][AIUEVO]n[iu]$/) { 
                                    $root[0]=~s/n[iu]$//g;
                                    $new_vib[0]="nu"; 
                                }
                                if($root[0]=~/loni$/) { 
                                    $root[0]=~s/loni$//g;
                                    $new_vib[0]="loni"; 
                                }
                                if($root[0]=~/[^aAe]n[iu]$/) { 
                                    $root[0]=~s/n[iu]$//g;
                                    $new_vib[0]="nu"; 
                                }
                                if($root[0]=~/([0-9]+)(la)*n[iu]$/) { 
#$root[0]=~s/k[iu]$//g; ### 
                                    $root[0]=~s/([0-9]+)(la)*n[iu]$/$1/g;  
                                    $new_num[0]="pl";
                                    $new_vib[0]="ni"; 
                                }

                                if($root[0]=~/([A-z])lanu$/) { 
                                    $root[0]=~s/lanu//g;  
                                    $new_num[0]="pl";
                                    $new_vib[0]="ni"; 
                                }
                                if($root[0]=~/elYlanuMdI$/) { #elYlanuMdI
                                    $root[0]=~s/elYlanuMdI/edu/g;  
                                    $new_num[0]="pl";
                                    $new_vib[0]="nuMdI"; 
                                }
                                if($root[0]=~/[^aAiIuUooeEV]xi$/) { 
                                    $root[0]=~s/xi//g;
                                    $new_vib[0]="xi"; 
                                }
                                if($root[0]=~/wo$/) { 
                                    $root[0]=~s/wo//g;
                                    $new_vib[0]="wo"; 
                                }
                                if($root[0]=~/wobAtu$/) { 
                                    $root[0]=~s/wobAtu//g;
                                    $new_vib[0]="wobAtu"; 
                                }

                                if($root[0]=~/n[ui]M[cd]i$/) {
                                    $root[0]=~s/n[iu]M[cd]i$//;
                                    $new_vib[0]="nuMdi"; 
                                }
                                if($root[0]=~/kosaM$|karaku$/) { 
                                    $root[0]=~s/kosaM$|karaku$//g;
                                    $new_vib[0]="kosaM"; 
                                }
                                if($root[0]=~/kiMx[A-z]*$/) { 
                                    $root[0]=~s/kiMx[A-z]*$//g;
                                    $new_vib[0]="kiMxa"; 
                                }
                                if($root[0]=~/([A-z]+)pE[A-z]*$/) { 
                                    $root[0]=~s/pE[A-z]*$//g;
                                    $new_vib[0]="pEna"; 
                                }
#PARAMESH 17_02_10 word like "raMXramani"
                                if($root[0]=~/amani$/) { 
                                    $root[0]=~s/amani/aM/g;
                                    $new_vib[0]="ani"; 
                                }
                                if($root[0]=~/lu$/) { 
                                    $root[0]=~s/lu//g;
                                    $new_vib[0]="0"; 
                                    $new_num[0]="pl"; 
                                }
                                if($root[0]=~/vu$/) { 
                                    $root[0]=~s/vu//g;
                                    $new_vib[0]="0"; 
                                    $new_num[0]="sg"; 
                                    $new_gen[0]="any"; 
                                    $new_per[0]="2"; 
                                }
                                if($root[0]=~/Mcabadina$/) {  ##'nirmiMcabadina
                                    $root[0]=~s/Mcabadina/Mcu/g;
                                    $new_lcat[0]="v";
                                    $new_vib[0]="a_badu_ina"; 
                                    $new_num[0]="any"; 
                                    $new_gen[0]="any";
                                    $new_per[0]="any";
                                }
                                #	if($root[0] ne "") { 
                                #		$new_vib[0]="0"; 
                                #	}
                                #else{$new_vib[0]="0"; }

                                &update_attr_val("lex",\@root,$fs_array,$sent);
                                &update_attr_val("tam",\@new_vib,$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);
                                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 "pn")&&($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=~/Q[C|O]/)) 
                            { 
                                $new_lcat[0]="num"; 
                                if($root[0]=~/([A-z]*)/)
                                {
                                    $root[0]=~/([0-9]*)(.*)/;
                                    $new_root[0]=$1;
                                    $new_vib[0]=$2;
                                    &update_attr_val("lex",\@new_root,$fs_array,$sent);
                                    &update_attr_val("vib",\@new_vib,$fs_array,$sent);
                                    my $string1 = &make_string($fs_array,$sent);
                                    &modify_field($child,4,$string1,$sent);
                                }
                            }


                            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="";
                        }


#The chunk change takes place.
#############################################################################################
#Blocked by PARAMESH 210111,since the following VGNN is chnged in2 NP
#4	((	VGNN	
#4.1	addukovadaM	VM	<fs af='adduko,v,any,any,any,,adaM,adaM'>
#4.2	valla	PSP	<fs af='valla,avy,,,,,0,0_avy' poslcat="NM">
#	))
                        #
                        if(($posh ne "NP")&&($lcat[0] eq "n")&&($pos=~/NN|UT|JJ|CC|PSP|Q[CF]|VM/)) {
                            if(($posh=~/BLK|GNN/)) {
                                $posh="NP"; &modify_field($node,3,$posh,$sent);
                                if(($pos=~/V/)&&($lcat[0] eq "n")){$pos="NN"; &modify_field($child,3,$pos,$sent); }
                            }
                        }

                        if(($posh eq "NP")&&($lcat[0] eq "adj")&&($pos=~/NN|UT|CC|PSP|Q[CF]|VM/)) {
                            if(($pos=~/N|V|P/)&&($lcat[0] eq "adj")){$pos="JJ"; &modify_field($child,3,$pos,$sent); }
                        }
##############################################################################################
#elsif(($posh ne "VGF" or $posh ne "VGNF" or $posh ne "VGNN")&&($lcat[0] eq "v" or $lcat[0] eq "pn")&&($pos=~/VM|VAUX|RB/)) {
#$new_posh="VGF"; }
                        #
#elsif(($posh ne "JJP")&&($lcat[0] eq "adj")&&($pos=~/NN|JJ/)) {
#$new_posh="JJP"; }
#elsif(($posh ne "CCP")&&($lcat[0] eq "avy")&&($pos=~/CC/)) {
#$new_posh="CCP"; }
                        else { $new_posh=$posh; }
##if($new_posh ne ""){
##&modify_field($node,3,$new_posh,$sent);}
                        $posh=""; $pos="";
                    }

                }

            }
        }
    }
    open OUTFILE, '>', \$result  or die $!;
    select(OUTFILE);
    printstory();
    select(STDOUT);
    return $result;
}

preprocess();

1;