package ILMT::KAN::HIN::ComputeVibhakti; #use strict; #use warnings; use Dir::Self; use Data::Dumper; use ILMT::KAN::HIN::SSFAPI::feature_filter; use ILMT::KAN::HIN::SSFAPI::shakti_tree_api; use ILMT::KAN::HIN::ComputeVibhakti::ComputeTAM; sub process { my %par = @_; my $input = $par{'data'}; read_story(\$input); my $keep = $par{'keep'}; my $body; my $numbody = get_bodycount(); for(my($bodynum)=1;$bodynum<=$numbody;$bodynum++) { $body = get_body($bodynum,$body); # count the number of paragraphs in the story my($numpara) = get_paracount($body); #print stderr "paras : $numpara\n"; # iterate through paragraphs in the story for(my($i)=1;$i<=$numpara;$i++) { my($para); # read paragraph $para = get_para($i); # count the number of sentences in this paragraph my($numsent) = get_sentcount($para); # iterate through sentences in the paragraph for(my($j)=1;$j<=$numsent;$j++) { # read the sentence which is in ssf format my($sent) = get_sent($para,$j); #copy vibhakti info ComputeVibhakti($sent, $keep); #compute tam ComputeTAM($sent, $keep); } } } open OUTFILE, '>', \$result or die $!; select(OUTFILE); printstory(); select(STDOUT); return $result; } #the module prunes multiple feature structure (NN, NNP, PRP at present), it also removes the parsarg node in the NP and adds it to its noun fs. #$&compute_vibhakti; sub ComputeVibhakti { my $sent=@_[0]; my $vibh_home = @_[1]; #my $delete; #keeps count of all the deleted node, helps in locating node obtained before deletion. #get all the noun nodes in the tree, the noun will be case marked '1' if a vibhakti is present, else case is '0' #my @all_leaves = &get_leaves(); #&read(@_[0]); my @all_children_NP =&get_nodes(3,"NP",$sent); #gets all the NP nodes my @all_children_RBP =&get_nodes(3,"RBP",$sent); #gets all the RBP nodes my @all_children = (@all_children_NP , @all_children_RBP); #contains all the NP and RBP nodes my @all_children = sort { $a <=> $b } @all_children; foreach $node(@all_children) { my @node_leaves=&get_leaves_child($node,$sent); #gets leaf nodes of NP or RBP node $position=""; $nhead=0; $f4=&get_field($node,4,$sent); # gets feature structure my $string_fs = &read_FS($f4, $sent); #gets head and vibhakti values my @head_value = &get_values("head", $string_fs, $sent); my @vibh_value=&get_values("vib", $string_fs, $sent); $vibh_chunk=$vibh_value[0]; #iterates through each leaf node and gets postag, word, fs foreach $NP_child(@node_leaves) { my $pos = &get_field($NP_child,3,$sent); my $word = &get_field($NP_child,2,$sent); my $fs = &get_field($NP_child,4,$sent); my $str_fs=&read_FS($fs,$sent); my @name_value=&get_values("name",$str_fs,$sent); if($pos eq "NN" or $pos eq "NNP" or $pos eq "PRP") { $nhead=1; $flag=0; $prev_RB=0; $flag_NN=1 } if($pos eq "RB") { $flag=1; $prev_RB = 1; $flag_NN=0 } if($head_value[0] eq $name_value[0]) { $num=$NP_child-$node; #gives position of the leaf with respect to the node # modifies the value of vpos(position) in a chunk if($position ne "") {$position=$position."_"."vib$num";} if($position eq "") {$position="vib$num";} } #Adds the RP vibhakti to vpos if($pos eq "RP") { if($position ne "") { $position=$position."_"."RP"; } else { next; } } if($pos eq "PSP" or $pos eq "NST" and $nhead==1) { #Adds position of vibhakti in vpos(position) value if($position ne "") { $num=$NP_child-$node; $position=$position."_".$num; } else { $position=$NP_child-$node; } my $val_fs=&get_field($NP_child, 4,$sent); $FSreference = &read_FS($val_fs,$sent); #reads feature structure of the leaf my @cur_vibhakti = &get_values("lex",$FSreference); #fetches the lexical value of vibhakti my @cur_vib_vib = &get_values("vib",$FSreference); #adds the lexical value of vibhakti to vibh_chunk if($vibh_chunk ne "") { $vibh_chunk=$vibh_chunk . "_" . $cur_vibhakti[0]; } else { $vibh_chunk="0_".$cur_vibhakti[0]; } push(@remove,$NP_child); } } if($vibh_chunk) { my @vibh_chunk_arr=(); push @vibh_chunk_arr,$vibh_chunk; #pushes the value of vibh_chunk in vibh_chunk_arr my $head_node=&get_field($node,4,$sent); my $FSreference1 = &read_FS($head_node,$sent); #gets FS value &update_attr_val("vib", \@vibh_chunk_arr,$FSreference1,$sent); #updates value of attribute vib # Modifies the value of fs by adding new attribute vpos that will be in output. my $string=&make_string($FSreference1,$sent); my ($x,$y)=split(/>/,$string); my $new_head_fs=$x." vpos=\"$position\">"; &modify_field($node,4,$new_head_fs,$sent); undef $head_word; undef $new_string; } } #Deletes the leaves containing vibhakti. $delete=0; foreach (@remove) { &delete_node($_-$delete,$sent); $delete++; } delete @remove[0..$#remove]; } 1;