package ILMT::HIN::PAN::Root2Infinity; use strict; use warnings; use Dir::Self; use Data::Dumper; use ILMT::HIN::PAN::SSFAPI::feature_filter; use ILMT::HIN::PAN::SSFAPI::shakti_tree_api; sub process { my %args = @_; my $input = $args{'data'}; read_story(\$input); my $result; 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); root_to_infinity($sent); } } } open OUTFILE, '>', \$result or die $!; select(OUTFILE); printstory(); select(STDOUT); return $result; } sub root_to_infinity { my $sent=$_[0]; my @children = get_children(0,$sent); foreach my $child (@children) { change_fs($child,$sent); my @lc = get_leaves_child($child,$sent); foreach my $c (@lc) { change_fs($c,$sent); } } return; } sub change_fs { my $node = $_[0]; my $sent = $_[1]; my $fs = get_field($node, 4,$sent); my $arr_fs = read_FS($fs,$sent); my @cat = get_values("cat", $arr_fs,$sent); if($cat[0] eq "v") { my @root = get_values("lex", $arr_fs,$sent); if($root[0] eq "hE" or $root[0] eq "WA") { return; } $root[0] = $root[0]."nA"; update_attr_val("lex", \@root, $arr_fs,$sent); } my $new_fs = make_string($arr_fs,$sent); modify_field($node, 4, $new_fs,$sent); } 1;