#!/usr/bin/perl
use warnings;
use Time::Stopwatch; 

################################################################
#
# must have     script_rachid.pl in same directory
#
################################################################

tie my $timer, 'Time::Stopwatch'; #start counting time

#printing usage if no argument set
if (!$ARGV[0] or !$ARGV[1]){
  $0 =~ s/.*\\(.*)/$1/; #name of this script without path
  print "\nUSAGE:\nperl $0 <directory containing results> <fichier avec patrons>\n";
  exit;
}

#openning the dir. with extracted titles and description
$dir = $ARGV[0];
$patrons = $ARGV[1];

opendir(DIR, $dir) or die "I cannot open dir: $dir";

while (my $file = readdir(DIR)) { #open directory
   next unless ($file =~ m/_t.xml$/); #open each file.txt
	
	my $file = $dir."/".$file;
	
	print "\nprocessing to xml : $file\n";
   
   #run treetagger using terminal
   system("script_rachid.pl $file $patrons");    
  
}

closedir(DIR);

print "\n\n === DONE in $timer s ===\n"; #printing time
