repair.pl 3.15 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
#!/usr/bin/perl
use Getopt::Long;
use Log::Log4perl;

GetOptions("help!"=>\$help,"version"=>\$version,"path=s"=>\$transfer_home,"log=s"=>\$logFile,"resource=s"=>\$rule_file,"input=s"=>\$input,"output=s",\$output);

print "Unprocessed by Getopt::Long\n" if $ARGV[0];
foreach (@ARGV) {
        print "$_\n";
        exit(0);
}

if($help eq 1)
{
        print "Repair  - Repair 2.4.2\n(6 Mar 2009)\n\n";
        print "usage : ./repair.pl --path=/home/repair-2.4.2 --log=logfile --resource=Rules [-i inputfile|--input=\"input_file\"] [-o outputfile|--output=\"output_file\"] \n";
        print "\tIf the output file is not mentioned then the output will be printed to STDOUT\n";
        exit(0);
}
if($version eq 1)
{
	print "Repair , VERSION - 2.4.2\n(Last Updated 6th Mar 2009)\n\n";
	exit(0);
}

if($transfer_home eq "")
{
        print "Please Specify the Path as defined in --help\n";
        exit(0);

}
if($rule_file eq "")
{
        print "Please Specify the Path of the RULE FILE as in --help\n";
        exit(0);

}


my $logfile = "$transfer_home/common/log.conf";
Log::Log4perl->init($logfile);

sub logfile {
	if($logFile ne "")
	{

		if (-e "$logFile") {
			system("rm -f $logFile");
		}
	}
	else
	{

		$logFile="transfer.log";
		if (-e "$transfer_home/$logFile") {
			system("rm -f $transfer_home/$logFile");
		}
	}
	my $myLog = "$logFile" || "$transfer_home/transfer.log";
	return $myLog;
}
$log = Log::Log4perl->get_logger;


my $src=$transfer_home . "/src";
require "$src/load.pl";
require "$src/rule_match.pl";
require "$src/copy_np_head.pl";
require "$src/copy_vg_head.pl";
require "$src/modify.pl";
require "$transfer_home/API/shakti_tree_api.pl";
require "$transfer_home/API/feature_filter.pl";


sub main
{
	undef (@_RULE_TREE_);

	$log->info("##ENTERING LOAD RULE FUNC\n\n");
	my $ref_RULE_TREE_=&load($rule_file,\@_RULE_TREE_);
	$log->info("##OUT OF LOAD RULE FUNC\n");
	
	if ($input eq "")
	{
	  $input="/dev/stdin";
	}

	&read_story($input);

	$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);
			# print STDERR "\n $i no.of sent $numSent";
			#print STDERR "Para Number $i, Num Sentences $numSent\n";
			#print $numSent."\n";
			# Iterate through sentences in the paragraph
			for(my($j)=1;$j<=$numSent;$j++)
			{
				#print " ... Processing sent $j\n";
				# Read the sentence which is in SSF format
				my($sent) = &get_sent($para,$j);
				#print STDERR "$sent";
#				
				$log->info("##ENTERING RULE MATCH func\n\n");
				&rule_match($sent,$ref_RULE_TREE_);
				$log->info("##OUT of RULE MATCH func\n\n");
#				&copy_np_head($sent,$transfer_home);
#				&copy_vg_head($sent,$transfer_home);
			}
		}
	}

	if($output eq "")
	{
		#&print_tree();
		&printstory();
	}
	if($output ne "")
	{
		#&print_tree_file("$output1");
		&printstory_file("$output");
	}

}
&main;