#!usr/bin/perl sub modify_tree_rhs { my $ref_nodes=$_[0]; my $index=$_[1]; my $sent=$_[2]; my $ref_rule=$_[3]; #print ERR "modify-->",$$ref_rhs->[1]->{"chunk"},"\n"; my @nodes=@$ref_nodes; my @_rule_=($$ref_rule); my @_lhs_= @_rule_[0]->[0]; my @_rhs_= @_rule_[0]->[1]; #print ERR "index-->",$index,"\n"; #print ERR "nodes->",@nodes[$index],"\n"; #print ERR "modify-->",$$ref_rhs,"\n"; # print "ARRAY---???",@_rule_[0]->[0]->[0]->{"chunk"},"\n"; # print "ARRAY---???",@_rule_[0]->[1]->[0]->{"chunk"},"\n"; # print "ARRAY---???",@_rule_[0]->[0]->[0]->{"chunk"},"\n"; my $i=$index; my $k=0; #print ERR "$k,",$#$_rhs_[0],",ARRAY_RHS_FS-->",@_rhs_[0]->[$k]->{"chunk"},"\n"; #print ERR "$k,",$#_rhs_,",ARRAY_RHS_FS-->",@_rhs_[0]->[$k]->{"chunk"},"\n"; my $delete=0; #print "LHS--",@_lhs_[0]->[$k]->{"chunk"},"\n"; #&print_tree($sent); ########### DELETING The Chunks ####################### for($k=0;@_lhs_[0]->[$k]->{"chunk"} ne "";$k++) { if(@_lhs_[0]->[$k]->{"drop"}==1) { my @children=&get_children($nodes[$i]-$delete,$sent); my $num_childs=@children+2; print ERR $nodes[$i],"-delete-",$delete,"\n"; &delete_node($nodes[$i]-$delete,$sent); $delete=$delete+$num_childs; } $i++; } @nodes=&get_children(0,$sent); ######################################################## # print "TREE--------\n"; # &print_tree($sent); # print "TREE--------OUT\n"; ##### REORDER OF THE NODES ##################### my $l=0; my $i=$index; my $cflag=0; my $add_count=0; my $drop_count=0; my @address_nodes; my $add_ind=0; my @mod_nodes=&get_children(0,$sent); my @move_lhs; my @move_rhs; for($k=0;@_lhs_[0]->[$k]->{"chunk"} ne "";$k++) { if(@_lhs_[0]->[$k]->{"drop"}==1) { $drop_count++; next; } else { @move_lhs[$add_ind]=$lhs_node=@_lhs_[0]->[$k]->{"chunk"}."~".@_lhs_[0]->[$k]->{"token_id"}; @address_nodes[$add_ind]=$mod_nodes[$i]; $add_ind++; $i++; } } my $add_ind=0; for($l=0;@_rhs_[0]->[$l]->{"chunk"} ne "";$l++) { if(@_rhs_[0]->[$l]->{"add"} eq 1) { $add_count++; next; } else { @move_rhs[$add_ind]=@_rhs_[0]->[$l]->{"chunk"}."~".@_rhs_[0]->[$l]->{"token_id"}; $add_ind++; } } ################ my $i=$index; my $pos_count=0; my $shift_count=0; my $l=0; for($k=0;@move_lhs[$k] ne "";) { print ERR "MOVING LHS--@move_lhs[$k]--\n"; $pos_count=0; for(;$l<=@move_rhs;$l++) { print ERR "checking--@move_lhs[$k]--@move_rhs[$l]\n"; if(@move_lhs[$k] eq @move_rhs[$l]) { print ERR "EQUAL\n"; if($pos_count==0) { print ERR "POSITION COUNT ZERO\n"; $k++; $l++; last; } else { &move_node(@address_nodes[$k-$shift_count],@address_nodes[$k-$shift_count+$pos_count],1,$sent); push(@move_lhs,"dummy"); print ERR "lenght of @move_lhs\n"; print ERR "k val--$k,count--$pos_count\n"; for($shift=@move_lhs-1;($shift)!=($k+$pos_count);$shift--) { print ERR $shift,"--",$k+$pos_count,"--",$move_lhs[$shift-1],"-to-",$move_lhs[$shift],"\n"; $move_lhs[$shift]=$move_lhs[$shift-1]; } print ERR "shift value--,",$shift+1,"\n"; $move_lhs[$shift+1]=$move_lhs[$k]; print ERR "mod lenght of @move_lhs\n"; my @mod_nodes=&get_children(0,$sent); $add_ind=0; $i=$index; print ERR "OUT value-@move_rhs\n"; while($add_ind<=@move_rhs) { print ERR "IN\n"; @address_nodes[$add_ind]=$mod_nodes[$i]; $add_ind++; $i++; } $k++; $l=0; $shift_count++; last; } } else { $pos_count++; } } } ####################################################### print ERR "Modifying the RHS\n"; my $i=$index; for($k=0;@_rhs_[0]->[$k]->{"chunk"} ne "";$k++) { print ERR "IAM IN\n"; print ERR "print $nodes[$i]--$k--ARRAY_RHS_FS-->",@_rhs_[0]->[$k]->{"chunk"},"\n"; print ERR "$k-head_val-->",@_rhs_[0]->[$k]->{"head_val"},"\n"; my ($f0,$f1,$f2,$f3,$f4)=&get_fields($nodes[$i],$sent); if(@_rhs_[0]->[$k]->{"head_val"} eq 1) { # print "HEAD--$f2--$f3\n"; $sent=&head_modify($nodes[$i],$sent,\@_rhs_[0]->[$k]->{"head_fs"}); } if(@_rhs_[0]->[$k]->{"add"} eq 1) { print ERR "ADDING FUNC\n"; $sent=&add_function($nodes[$i],$sent,\@_rhs_[0]->[$k]); print ERR "ADD COUNT ",@_rhs_[0]->[$k]->{"add_val"},"\n"; @nodes=&get_children(0,$sent); $i=$i+@_rhs_[0]->[$k]->{"add_val"}; printf ERR "check node index--",$i,"\n"; next; } else { print ERR "ARRAY_RHS_FS-->",@_rhs_[0]->[$k]->{"fs"},"\n"; if(@_rhs_[0]->[$k]->{"add_childs"}->[0] ne "") { $sent=&add_children($nodes[$i],$sent,\@_rhs_[0]->[$k]->{"add_childs"},\@_rhs[0]->[$k]); @nodes=&get_children(0,$sent); } if(@_rhs_[0]->[$k]->{"drop_childs"}->[0] ne "") { $sent=&delete_children($nodes[$i],$sent,\@_rhs_[0]->[$k]->{"drop_childs"}); @nodes=&get_children(0,$sent); } print ERR "check1\n"; $sent=&children_modify($nodes[$i],$sent,\@_rhs_[0]->[$k]->{"fs"}); $i++; } } #&print_tree($sent); } sub add_function { my $index=@_[0]; my $sent=@_[1]; my $ref_rhs_chunk=@_[2]; #print ERR "REFERENCE --> $$ref_rhs_chunk\n"; my @temp_array_rhs1=($$ref_rhs_chunk); undef(my @_small_TREE_); my $k; $_small_TREE_[0][1]="0"; $_small_TREE_[0][2]="(("; #print ERR "CHUNK-->",$$ref_rhs_chunk->{"chunk"},"\n"; $_small_TREE_[0][3]=$$ref_rhs_chunk->{"chunk"}; #print ERR "WORD---->",@temp_array_rhs1[0]->{"fs"}->[$k]->{"word"},"\n"; for($k=0;@temp_array_rhs1[0]->{"fs"}->[$k]->{"word"} ne "";$k++) { $_small_TREE_[$k+1][1]=$k+1; # print ERR "WORD---->",@temp_array_rhs1[0]->{"fs"}->[$k]->{"word"},"\n"; # print ERR "POS---->",@temp_array_rhs1[0]->{"fs"}->[$k]->{"pos"},"\n"; print ERR "ROOT---->",@temp_array_rhs1[0]->{"fs"}->[$k]->{"root"},"\n"; print ERR "LCAT---->",@temp_array_rhs1[0]->{"fs"}->[$k]->{"lcat"},"\n"; $_small_TREE_[$k+1][2]=@temp_array_rhs1[0]->{"fs"}->[$k]->{"word"},"\n"; $_small_TREE_[$k+1][3]=@temp_array_rhs1[0]->{"fs"}->[$k]->{"pos"},"\n"; my $root=@temp_array_rhs1[0]->{"fs"}->[$k]->{"root"}; my $lcat=@temp_array_rhs1[0]->{"fs"}->[$k]->{"lcat"}; my $num=@temp_array_rhs1[0]->{"fs"}->[$k]->{"num"}; my $gend=@temp_array_rhs1[0]->{"fs"}->[$k]->{"gend"}; my $pers=@temp_array_rhs1[0]->{"fs"}->[$k]->{"pers"}; my $case=@temp_array_rhs1[0]->{"fs"}->[$k]->{"case"}; my $cm=@temp_array_rhs1[0]->{"fs"}->[$k]->{"cm"}; my $suff=@temp_array_rhs1[0]->{"fs"}->[$k]->{"tam"}; if($cm eq "") { $_small_TREE_[$k+1][4]=""; } else { $_small_TREE_[$k+1][4]=""; } } $_small_TREE_[$k+1][2]="))"; $_small_TREE_[0][0]=$k+2; print ERR "INDEX $index,nodes added--$k-\n"; &add_node(\@_small_TREE_,$index,0,$sent); return ($sent); #&print_tree($sent); } sub head_modify { my $node=@_[0]; my $sent=@_[1]; my $ref_temp_fs_hash=@_[2]; #print ERR "node--",$node,"\n"; #print ERR "hello--",$ref_temp_fs_array,"\n"; my $ref_temp_hash=$$ref_temp_fs_hash; my %temp_hash=%$ref_temp_hash; my ($f0,$f1,$f2,$f3,$f4)=&get_fields($node,$sent); my $fs_head_array = &read_FS($f4,$sent); #print ERR "f4---",$f4,"\n"; #print ERR "check val---",$temp_array[$l],"\n"; my @lex=(),@cat=(),@num=(),@gen=(),@per=(),@tam=(),@cas=(); foreach(keys(%temp_hash)) { if($temp_hash{$_} ne "") { #print "1--$node--HEAD-$_---$temp_hash{$_}\n"; if($_ eq "word") { $word=$temp_hash{$_}; &modify_field($node,2,$word,$sent); } if($_ eq "pos") { $pos=$temp_hash{$_}; &modify_field($node,3,$pos,$sent); } if($_ eq "root") { #lex[0]=$temp_hash{$_}; if($temp_hash{$_}=~/([^\$]*\.)?(\$[a-zA-Z])\.(.*)?/) { my $temp1=$1; my $var1=$2; my $temp2=$3; $lex[0]=$temp1."$var_hash{$var1}".$temp2; } else { @lex[0]=$temp_hash{$_}; } &update_attr_val("lex", \@lex, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); # print "STRING-$string-\n"; &modify_field($node,4,$string,$sent); } if($_ eq "lcat") { @cat[0]=$temp_hash{$_}; &update_attr_val("cat", \@cat, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } if($_ eq "num") { @num[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @num[0]=""; } &update_attr_val("num", \@num, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } if($_ eq "gend") { @gen[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @gen[0]=""; } &update_attr_val("gen", \@gen, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } if($_ eq "pers") { @per[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @per[0]=""; } &update_attr_val("per", \@per, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } if($_ eq "case") { @cas[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @cas[0]=""; } &update_attr_val("cas", \@cas, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } if($_ eq "tam" or $_ eq "cm") { if($temp_hash{$_}=~/([^\$]*)?(\$[a-zA-Z])(.*)?/) { #print "-$1,$2,$3-\n"; my $temp1=$1; my $var1=$2; my $temp2=$3; $tam[0]=$temp1."$var_hash{$var1}".$temp2; #print ERR "tam var-$tam[0]\n"; } else { @tam[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @tam[0]=""; } } #print ERR "my tam--",$tam[0],"\n"; &update_attr_val("vib", \@tam,$fs_head_array); my ($f0,$f1,$f2,$f3,$f4)=&get_fields($children[$l],$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($node,4,$string,$sent); } } } return $sent; } sub add_children { my $node=@_[0]; my $sent=@_[1]; my $ref_temp_children_array=@_[2]; my $ref_temp_array=$$ref_temp_children_array; my @temp_array=@$ref_temp_array; my $ref_rhs_chunk=@_[3]; print ERR "ADDING CHILDREN\n"; my @temp_array_rhs1=($$ref_rhs_chunk); # my @sort_add=sort{$a <=> $b} @temp_array; my $add=0; foreach (@temp_array) { my $root=@temp_array_rhs1[0]->{"fs"}->[$_]->{"root"}; my $lcat=@temp_array_rhs1[0]->{"fs"}->[$_]->{"lcat"}; my $num=@temp_array_rhs1[0]->{"fs"}->[$_]->{"num"}; my $gend=@temp_array_rhs1[0]->{"fs"}->[$_]->{"gend"}; my $pers=@temp_array_rhs1[0]->{"fs"}->[$_]->{"pers"}; my $case=@temp_array_rhs1[0]->{"fs"}->[$_]->{"case"}; my $cm=@temp_array_rhs1[0]->{"fs"}->[$_]->{"cm"}; my $suff=@temp_array_rhs1[0]->{"fs"}->[$_]->{"tam"}; my $fs=""; print ERR "$_--@temp_array_rhs1[0]->{\"fs\"}->[$_]->{\"word\"},--$fs---\n"; &add_leaf($node+$_+$add,0,@temp_array_rhs1[0]->{"fs"}->[$_]->{"word"},@temp_array_rhs1[0]->{"fs"}->[$_]->{"pos"},$fs,$sent); $add++; } return ($sent); } sub delete_children { my $node=@_[0]; my $sent=@_[1]; my $ref_temp_children_array=@_[2]; #print ERR "node--",$node,"\n"; #print ERR "hello--",$ref_temp_fs_array,"\n"; my $ref_temp_array=$$ref_temp_children_array; my @temp_array=@$ref_temp_array; my $delete=0; my @sort_remove=sort{$a <=> $b} @temp_array; my $delete=0; foreach (@sort_remove) { &delete_node($node+$_-$delete,$sent); $delete++; } return ($sent); } sub children_modify { my $node=@_[0]; my $sent=@_[1]; my $ref_temp_fs_array=@_[2]; my $ref_temp_array=$$ref_temp_fs_array; my @temp_array=@$ref_temp_array; my @children=&get_children($node,$sent); print ERR "HELLO\n"; for($l=0;$l<=$#children;$l++) { my ($f0,$f1,$f2,$f3,$f4)=&get_fields($children[$l],$sent); my $fs_head_array = &read_FS($f4,$sent); print ERR "SRC side---",$f4,"\n"; #print ERR "check val---",$temp_array[$l],"\n"; my $ref_temp_hash=$temp_array[$l]; my %temp_hash=%$ref_temp_hash; my $word,$pos,@lex=(),@cat=(),@num=(),@gen=(),@per=(),@tam=(),@cas=(); foreach(keys(%temp_hash)) { if($temp_hash{$_} ne "") { print ERR "CHILD--$temp_hash{$_}---$_\n"; if($_ eq "word") { $word=$temp_hash{$_}; &modify_field($children[$l],2,$word,$sent); } if($_ eq "pos") { $pos=$temp_hash{$_}; &modify_field($children[$l],3,$pos,$sent); } if($_ eq "root") { if($temp_hash{$_}=~/([^\$]*\.)?(\$[a-zA-Z])\.(.*)?/) { my $temp1=$1; my $var1=$2; my $temp2=$3; $lex[0]=$temp1."$var_hash{$var1}".$temp2; } else { @lex[0]=$temp_hash{$_}; } &update_attr_val("lex", \@lex,$fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "lcat") { @cat[0]=$temp_hash{$_}; &update_attr_val("cat", \@cat, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "num") { @num[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @num[0]=""; } &update_attr_val("num", \@num, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "gend") { @gen[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @gen[0]=""; } &update_attr_val("gen", \@gen, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "pers") { @per[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @per[0]=""; } &update_attr_val("per", \@per, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "case") { @cas[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @cas[0]=""; } &update_attr_val("cas", \@cas, $fs_head_array,$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } if($_ eq "tam" or $_ eq "cm") { if($temp_hash{$_}=~/([^\$]*)?(\$[a-zA-Z])(.*)?/) { #print "check-$1,$2,$3-\n"; my $temp1=$1; my $var1=$2; my $temp2=$3; $tam[0]=$temp1."$var_hash{$var1}".$temp2; #print ERR "tam var-$tam[0]\n"; } else { @tam[0]=$temp_hash{$_}; if($temp_hash{$_} eq "NULL") { @tam[0]=""; } } print ERR "my tam--",$tam[0],"\n"; &update_attr_val("vib", \@tam,$fs_head_array); my ($f0,$f1,$f2,$f3,$f4)=&get_fields($children[$l],$sent); my $string=&make_string($fs_head_array,$sent); &modify_field($children[$l],4,$string,$sent); } } } } return $sent; } 1;