#!/usr/bin/perl %var_hash=(); sub transfer_grammar { my $sent=@_[0]; my $ref_RULE_TREE_=@_[1]; @_RULE_TREE_=@$ref_RULE_TREE_; my $count=0; my @nodes=&get_children(0,$sent); my $flag=0; for(my $i=0;$i<=$#nodes;) { print ERR "NODE-$nodes[$i]\n"; for(my $j=0;$j<=$#_RULE_TREE_;$j++) { my ($f0,$f1,$f2,$f3,$f4)=&get_fields($nodes[$i],$sent); my $temp_i=$i; my $old_i=$i; my @array_lhs1=$_RULE_TREE_[$j]->[0]; for(my $k=0;$_RULE_TREE_[$j]->[0]->[$k]->{"chunk"} ne "";) { print ERR "RULE AT-$f3\n"; print ERR "Rule No--$_RULE_TREE_[$j]->[2]->[0]\n"; print ERR "Pos in Rule--",$k+1,"\n"; print ERR "Rule Chunk Tag:",$_RULE_TREE_[$j]->[0]->[$k]->{"chunk"},"\n"; if($f3 eq $_RULE_TREE_[$j]->[0]->[$k]->{"chunk"}) { #print ERR "in\n"; if($_RULE_TREE_[$j]->[0]->[$k]->{"drop"}==1) { print ERR "DROP YES\n"; } if($_RULE_TREE_[$j]->[0]->[$k]->{"head_val"} eq 0) { $flag=&children_fs_match($nodes[$temp_i],$sent,\$_RULE_TREE_[$j]->[0]->[$k]->{"fs"}); } if($_RULE_TREE_[$j]->[0]->[$k]->{"head_val"} eq 1) { print ERR "HeadVALUE=1\n"; $flag=&head_fs_match($nodes[$temp_i],$sent,\$_RULE_TREE_[$j]->[0]->[$k]->{"head_fs"}); } print ERR "flag val--",$flag,"\n"; if($flag ne "1") { print ERR "FLAG 1\n"; $i=$old_i; last; } else { $temp_i++; $k++; print ERR "temp-->$temp_i--nodes-->$#nodes\n"; if($temp_i>$#nodes and $_RULE_TREE_[$j]->[0]->[$k]->{"chunk"} eq "") { $i=$old_i; last; } if($temp_i>$#nodes) { $flag=0; $i=$old_i; last; } ($f0,$f1,$f2,$f3,$f4)=&get_fields($nodes[$temp_i],$sent); next; } } else { $flag=0; print ERR "VALUE--->$i--->$old_i\n"; $i=$old_i; last; } } if($flag eq 1) { my %temp_array_rhs=$_RULE_TREE_[$j]->[1]->[0]; print ERR "Applying Rule number=",$_RULE_TREE_[$j]->[2]->[0],"\@ $nodes[$i]\n"; print ERR "MODIFY USING RULE\n"; &modify_tree_rhs(\@nodes,$i,$sent,\$_RULE_TREE_[$j]); @nodes=&get_children(0,$sent); $flag=0; next; } } $i++; } } sub head_fs_match { my $node=@_[0]; my $sent=@_[1]; my $ref_temp_fs_hash=@_[2]; # print ERR "hello--",$$ref_temp_fs_array,"\n"; my $ref_temp_hash=$$ref_temp_fs_hash; my %temp_hash=%$ref_temp_hash; my $flag=1; my ($f0,$f1,$f2,$f3,$f4)=&get_fields($node,$sent); my $fs_array = &read_FS($f4,$sent); my @lex = &get_values("lex", $fs_array); my @cat = &get_values("cat", $fs_array); my @gen = &get_values("gen", $fs_array); my @num = &get_values("num", $fs_array); my @per = &get_values("per", $fs_array); my @cas = &get_values("cas", $fs_array); my @tam = &get_values("vib", $fs_array); my @suff = &get_values("tam", $fs_array); print ERR "lex-",@lex[0],"\n"; print ERR "cat-",@cat[0],"\n"; print ERR "gen-",@gen[0],"\n"; print ERR "num-",@num[0],"\n"; print ERR "per-",@per[0],"\n"; print ERR "cas-",@cas[0],"\n"; print ERR "tam-",@tam[0],"\n"; print ERR "vib-",@suff[0],"\n"; #print ERR "attr-vals\n"; #print ERR "f4--$f4\n"; #print ERR "$lex[0],$cat[0],$gen[0],$num[0],$per[0],$cas[0],-$tam[0]-\n"; #print ERR "check val---",$temp_array[$l],"\n"; foreach(keys(%temp_hash)) { print ERR "key-->>",$_,"-",$temp_hash{$_},"-\n"; if($temp_hash{$_} ne "") { if($_ eq "word") { if($f2 ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "pos") { if($f3 ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "root") { if($temp_hash{$_}=~/([^\$]*)?(\$[a-zA-Z]+)\.(.*)?/) { print ERR "-$1,$2,$3-\n"; my $temp1=$1; my $var1=$2; my $temp2=$3; #print ERR "tam var-$tam[0]\n"; if($lex[0]=~/$temp1(.*)$temp2/) { $var_hash{$var1}=$1; next; #print ERR "x-var-$1\n"; } else { $flag=0; return $flag; } } if($lex[0] eq $temp_hash{$_}) { print ERR "WE ARE EQUAL\n"; } elsif($lex[0] ne $temp_hash{$_}) { print ERR "IAM IN FLAG 0\n"; $flag=0; return $flag; } } if($_ eq "lcat") { if($cat[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "num") { if($num[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "gend") { if($gen[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "pers") { if($per[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "tam" or $_ eq "cm") { print ERR "<<<>",$_,"-$f2-",$temp_hash{$_},"-\n"; if($temp_hash{$_} ne "") { if($_ eq "word") { if($temp_hash{$_}=~/([^\$]*)?(\$[a-zA-Z]+)\.(.*)?/) { # print ERR "-$1,$2,$3-\n"; my $temp1=$1; my $var1=$2; my $temp2=$3; print ERR "word var $temp1,$var1,$temp2\n"; if($f2=~/$temp1(.*)$temp2/) { print ERR "x-var-$1\n"; $var_hash{$var1}=$1; next; } else { $flag=0; return $flag; } } if($f2 eq $temp_hash{$_}) { print ERR "WE ARE EQUAL\n"; } if($f2 ne $temp_hash{$_}) { print ERR "IAM IN FLAG 0\n"; $flag=0; return $flag; } } if($_ eq "pos") { if($f3 ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "root") { if($temp_hash{$_}=~/([^\$]*)?(\$[a-zA-Z])\.(.*)?/) { # print ERR "-$1,$2,$3-\n"; my $temp1=$1; my $var1=$2; my $temp2=$3; print ERR "word var $temp1,$var1,$temp2\n"; if($lex[0]=~/$temp1(.*)$temp2/) { print ERR "x-var-$1\n"; $var_hash{$var1}=$1; next; } else { $flag=0; return $flag; } } if($lex[0] eq $temp_hash{$_}) { print ERR "WE ARE EQUAL\n"; } if($lex[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "lcat") { if($cat[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "num") { if($num[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "gend") { if($gen[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "pers") { if($per[0] ne $temp_hash{$_}) { $flag=0; return $flag; } } if($_ eq "tam" or $_ eq "cm") { print ERR "<<<$#temp_array\n"; if($#children<$#temp_array) { return 0; } return $flag; } 1;