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

################################################################
#
# requires
#	tagged files by script-tagging-with-treetagger-txt.pl
#	treetagger2xml-utf8.pl in same directory
#
################################################################

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

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

#opening the dir. with extracted titles and description
$dir = $ARGV[0];
opendir(DIR, $dir) or die "I cannot open dir: $dir";

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

closedir(DIR);

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