tam-suff.pl 3.56 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
#!/usr/bin/perl

use Log::Log4perl;
use Getopt::Long;
GetOptions("help"=>\$oHelp,"input=s"=>\$filename,"path=s"=>\$path);
$SEN_GEN_HOME = $path;

if($oHelp or $path eq "")
{
	print "Usage : perl tam-suff.pl -i input_SSF --path=/home/tamsuff --input= db path\n";
	exit(0);
}
if($version)
{
	print "tam suff v1.1\n";
	exit(0);
}

require "$path/API/shakti_tree_api.pl";
require "$path/API/feature_filter.pl";

open(TAMDICT,"$path/tam.txt");
@TAMS = <TAMDICT>;
chomp(@TAMS);

%tam_hash = ();
foreach $tam_1 (@TAMS)
{
        ($tam,$teltam) = split(/\,/,$tam_1);
        $key = $tam;
        $tam_hash{ $key } = $teltam;
}

open(NOUNDICT,"$path/noun.txt");
@NOUNS = <NOUNDICT>;
chomp(@NOUNS);

%noun_hash = ();
foreach $noun_1 (@NOUNS)
{
        ($root,$tnoun) = split(/\,/,$noun_1);
        $key1 = $root;
        $noun_hash{ $key1 } = $tnoun;
}

sub sen_gen()
{

	&read_story($filename);

	$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++)
			{
				my($sent) = &get_sent($para,$j1);
				@nodes1 = &get_leaves($sent);

				 my @childNodes=&get_children(1,$sent);
				 @nodes = (@childNodes,@nodes1);

				foreach $node (@nodes)
				{
					my $pos=&get_field($node, 3,$sent);
					$child = $node; 
					my $pos=&get_field($child, 3,$sent);
					my $tep=&get_field($child, 2,$sent);
					my $temp_fs_4 = &get_field($child, 4,$sent);
					my $temp_fs = &read_FS($temp_fs_4,$sent);
					my @root = &get_values("lex",$temp_fs,$sent);
					my @gen = &get_values("gen",$temp_fs,$sent);
					my @lcat = &get_values("cat",$temp_fs,$sent);
					my @suff = &get_values("tam",$temp_fs,$sent);
					my @tam = &get_values("vib",$temp_fs,$sent);
					my $temp_fs_2=&get_field($child, 2,$sent);

					#$tam[0]=~s/^@://g;
					$tam[0]=~s/\+/_/g;
					
					if($gen[0] eq "num")	{
						$root_new=$root[0].",".$lcat[0];
						&modify_field($child, 2,$root_new, $sent);
					}
					

					if(($tam[0]=~/@/)&&($tam[0]!~/\^/)) {
							$tam[0]=~s/@//g;
							$tam[0]=~s/^0_//g;
							$key = $tam[0];
							$new_tam[0] = $tam_hash{$key};
							if($new_tam[0] ne "")
							{
								$new_tam[0]="@".$new_tam[0];
								&update_attr_val("vib",\@new_tam,$temp_fs,$sent);
								my $ret_string = &make_string($temp_fs,$sent);
								&modify_field($child,4,$ret_string,$sent);
							}
							if(($tam[0] eq "ने")&&($suff[0]!~/^ne_/)){
								$tam[0]="ne";
								&update_attr_val("tam",\@tam,$temp_fs,$sent);
								my $ret_string = &make_string($temp_fs,$sent);
								&modify_field($child,4,$ret_string,$sent);

							}
					}
					else{
						if($tam[0] ne "")
						{
							$tam[0]=~s/\^//g;
							&update_attr_val("vib",\@tam,$temp_fs,$sent);
							my $ret_string = &make_string($temp_fs,$sent);
							&modify_field($child,4,$ret_string,$sent);
						}
					}
					if(($root[0]=~/@/)&&($pos=~/^N/)) {
						$root[0]=~s/@//g;
						$root[0]=~s/^0_//g;
						$key1 = $root[0];
						$new_root[0] = $noun_hash{$key1};
						if($new_root[0] ne "") {
							$new_root[0]="@".$new_root[0];
							&update_attr_val("lex",\@new_root,$temp_fs,$sent);
							my $ret_string = &make_string($temp_fs,$sent);
							&modify_field($child,4,$ret_string,$sent);
							if($tep!~/\(/){
							&modify_field($child,2,$new_root[0],$sent);
							}
						}
					}
				}
			}
		}
	}
}
&sen_gen;
if($output eq "" )
{
	        &printstory();
}

else
{
	        &printstory_file("$output");
}