|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use utf8; |
|
use open ':utf8'; |
|
binmode(STDIN, ':utf8'); |
|
binmode(STDOUT, ':utf8'); |
|
binmode(STDERR, ':utf8'); |
|
|
|
my $ud_folder = '/home/zeman/unidep'; |
|
my $validate_script = "/usr/bin/python3 $ud_folder/tools/validate.py"; |
|
my $collapse_script = "/usr/bin/perl $ud_folder/tools/enhanced_collapse_empty_nodes.pl"; |
|
|
|
my $task_folder = "/home/zeman/iwpt2020"; |
|
my $gold_treebanks_folder = "$task_folder/_private/data"; |
|
my $cut_script = "/usr/bin/perl $task_folder/_private/tools/match_and_split_conllu_by_input_text.pl"; |
|
my $eval_script = "/usr/bin/python3 $task_folder/iwpt20_xud_eval.py"; |
|
my $system_tgz_folder = "$task_folder/_private/data/sysoutputs"; |
|
my $system_unpacked_folder = "$task_folder/_private/data/sysoutputs"; |
|
my $archived_submissions_folder = "$task_folder/_private/data/archive/sysoutputs"; |
|
|
|
|
|
my %treebanks = |
|
( |
|
'ar' => ['Arabic-PADT'], |
|
'bg' => ['Bulgarian-BTB'], |
|
'cs' => ['Czech-FicTree', 'Czech-CAC', 'Czech-PDT', 'Czech-PUD'], |
|
'nl' => ['Dutch-Alpino', 'Dutch-LassySmall'], |
|
'en' => ['English-EWT', 'English-PUD'], |
|
'et' => ['Estonian-EDT', 'Estonian-EWT'], |
|
'fi' => ['Finnish-TDT', 'Finnish-PUD'], |
|
'fr' => ['French-Sequoia', 'French-FQB'], |
|
'it' => ['Italian-ISDT'], |
|
'lv' => ['Latvian-LVTB'], |
|
'lt' => ['Lithuanian-ALKSNIS'], |
|
'pl' => ['Polish-LFG', 'Polish-PDB', 'Polish-PUD'], |
|
'ru' => ['Russian-SynTagRus'], |
|
'sk' => ['Slovak-SNK'], |
|
'sv' => ['Swedish-Talbanken', 'Swedish-PUD'], |
|
'ta' => ['Tamil-TTB'], |
|
'uk' => ['Ukrainian-IU'] |
|
); |
|
|
|
my %enhancements = |
|
( |
|
'Arabic-PADT' => '4', |
|
'Bulgarian-BTB' => '0', |
|
'Czech-FicTree' => '0', |
|
'Czech-CAC' => '0', |
|
'Czech-PDT' => '0', |
|
'Czech-PUD' => '3', |
|
'Dutch-Alpino' => '0', |
|
'Dutch-LassySmall' => '0', |
|
'English-EWT' => '0', |
|
'English-PUD' => '0', |
|
'Estonian-EDT' => '4', |
|
'Estonian-EWT' => '34', |
|
'Finnish-TDT' => '0', |
|
'Finnish-PUD' => '34', |
|
'French-Sequoia' => '156', |
|
'French-FQB' => '156', |
|
'Italian-ISDT' => '0', |
|
'Latvian-LVTB' => '0', |
|
'Lithuanian-ALKSNIS' => '0', |
|
'Polish-LFG' => '1', |
|
'Polish-PDB' => '0', |
|
'Polish-PUD' => '0', |
|
'Russian-SynTagRus' => '3', |
|
'Slovak-SNK' => '0', |
|
'Swedish-Talbanken' => '0', |
|
'Swedish-PUD' => '0', |
|
'Tamil-TTB' => '145', |
|
'Ukrainian-IU' => '0', |
|
); |
|
|
|
if(scalar(@ARGV)!=3) |
|
{ |
|
die("Three arguments expected: team name, submission id, and dev|test"); |
|
} |
|
my $team_name = $ARGV[0]; |
|
my $submission_id = $ARGV[1]; |
|
my $portion = $ARGV[2]; |
|
if($team_name !~ m/^[a-z0-9_]+$/) |
|
{ |
|
die("Invalid team name '$team_name': must be [a-z0-9_]+"); |
|
} |
|
if($submission_id !~ m/^[a-z0-9_]+$/) |
|
{ |
|
die("Invalid submission id '$submission_id': must be [a-z0-9_]+"); |
|
} |
|
if($portion !~ m/^(dev|test)$/) |
|
{ |
|
die("Unknown data portion '$portion', should be 'dev' or 'test'"); |
|
} |
|
my $gold_languages_folder = "$gold_treebanks_folder/$portion-gold"; |
|
my $system_tgz = "$system_tgz_folder/$team_name-$submission_id.tgz"; |
|
my $system_folder = "$system_unpacked_folder/$team_name/$submission_id"; |
|
|
|
if(!-e $system_tgz) |
|
{ |
|
die("Archive '$system_tgz' not found"); |
|
} |
|
|
|
|
|
if(-e $system_folder) |
|
{ |
|
my $archive_number = 1; |
|
my $archive_name = sprintf("$archived_submissions_folder/$team_name-$submission_id-%02d", $archive_number); |
|
while(-e $archive_name) |
|
{ |
|
$archive_number++; |
|
$archive_name = sprintf("$archived_submissions_folder/$team_name-$submission_id-%02d", $archive_number); |
|
} |
|
print("$system_folder already exists. Archiving as $archive_name\n"); |
|
system("mv $system_folder $archive_name"); |
|
} |
|
|
|
if(!-d "$system_unpacked_folder/$team_name") |
|
{ |
|
mkdir("$system_unpacked_folder/$team_name") or die ("Cannot create folder '$system_unpacked_folder/$team_name': $!"); |
|
} |
|
if(!-d "$system_unpacked_folder/$team_name/$submission_id") |
|
{ |
|
mkdir("$system_unpacked_folder/$team_name/$submission_id") or die ("Cannot create folder '$system_unpacked_folder/$team_name/$submission_id': $!"); |
|
} |
|
my $command = "cd $system_folder && /bin/gunzip -c $system_tgz | /bin/tar xf -"; |
|
print STDERR ("Executing: $command\n"); |
|
system($command); |
|
my $system_metadata = $system_tgz; |
|
$system_metadata =~ s/\.tgz$/-metadata.txt/; |
|
if(-f $system_metadata) |
|
{ |
|
system("/bin/cp $system_metadata $system_folder/metadata.txt"); |
|
} |
|
|
|
my %score; |
|
my @languages = sort(keys(%treebanks)); |
|
my %errlang; |
|
foreach my $language (@languages) |
|
{ |
|
my $gold = "$gold_languages_folder/$language.conllu"; |
|
my $sys = "$system_folder/$language.conllu"; |
|
if(!-e $gold) |
|
{ |
|
die("Missing gold file '$gold'"); |
|
} |
|
if(!-e $sys) |
|
{ |
|
print("Missing system file '$sys'\n"); |
|
next; |
|
} |
|
print("$sys\n"); |
|
print("Validating on level 2...\n"); |
|
if(!saferun("$validate_script --level 2 --lang ud $sys")) |
|
{ |
|
|
|
$errlang{$language}++; |
|
next; |
|
} |
|
print("Collapsing empty nodes...\n"); |
|
my $goldnen = $gold; |
|
$goldnen =~ s/\.conllu$/.gold.nen.conllu/; |
|
|
|
|
|
$goldnen =~ s/$gold_languages_folder/$system_folder/; |
|
my $sysnen = $sys; |
|
$sysnen =~ s/\.conllu$/.nen.conllu/; |
|
system("$collapse_script < $gold > $goldnen"); |
|
system("$collapse_script < $sys > $sysnen"); |
|
print("Evaluating against gold standard...\n"); |
|
system("$eval_script -v $goldnen $sysnen > $system_folder/$language.eval.log"); |
|
|
|
open(EVAL, "$system_folder/$language.eval.log") or die("Cannot read '$system_folder/$language.eval.log': $!"); |
|
while(<EVAL>) |
|
{ |
|
s/\r?\n$//; |
|
if(m/^\w+.*\|.*\d+/) |
|
{ |
|
my @f = split(/\s*\|\s*/, $_); |
|
my $metric = shift(@f); |
|
my $p = shift(@f); |
|
my $r = shift(@f); |
|
my $f = shift(@f); |
|
my $a = shift(@f); |
|
$score{language}{$language}{$metric} = |
|
{ |
|
'p' => $p, |
|
'r' => $r, |
|
'f' => $f, |
|
'a' => $a |
|
}; |
|
} |
|
} |
|
close(EVAL); |
|
} |
|
|
|
my $pertreebank = $system_folder.'/pertreebank'; |
|
system("/bin/rm -rf $pertreebank"); |
|
mkdir($pertreebank) or die("Cannot create folder '$pertreebank': $!"); |
|
foreach my $language (@languages) |
|
{ |
|
|
|
|
|
next if($errlang{$language}); |
|
system("/bin/cp $system_folder/$language.conllu $pertreebank/rest.conllu"); |
|
my @treebanks = @{$treebanks{$language}}; |
|
foreach my $treebank (@treebanks) |
|
{ |
|
my $treebank_folder = $gold_treebanks_folder.'/UD_'.$treebank; |
|
my ($langname, $tbkname) = split(/-/, $treebank); |
|
my $tcode = lc($tbkname); |
|
my $treebank_file = $language.'_'.$tcode.'-ud-'.$portion; |
|
my $treebank_enhancements = exists($enhancements{$treebank}) ? "--enhancements $enhancements{$treebank}" : ''; |
|
|
|
if(-e "$treebank_folder/$treebank_file.conllu") |
|
{ |
|
print("$treebank_file\n"); |
|
system("$cut_script $treebank_folder/$treebank_file.txt $pertreebank/rest.conllu $pertreebank/$treebank_file-sys.conllu $pertreebank/rest2.conllu"); |
|
system("/bin/mv $pertreebank/rest2.conllu $pertreebank/rest.conllu"); |
|
system("$collapse_script < $treebank_folder/$treebank_file.conllu > $pertreebank/$treebank_file-gold.nen.conllu"); |
|
system("$collapse_script < $pertreebank/$treebank_file-sys.conllu > $pertreebank/$treebank_file-sys.nen.conllu"); |
|
system("$eval_script -v $treebank_enhancements $pertreebank/$treebank_file-gold.nen.conllu $pertreebank/$treebank_file-sys.nen.conllu > $pertreebank/$treebank_file.eval.log"); |
|
} |
|
} |
|
} |
|
|
|
print("\nELAS F1-score Summary\n"); |
|
print( "---------------------\n"); |
|
my $sum = 0; |
|
my $n = scalar(@languages); |
|
foreach my $language (@languages) |
|
{ |
|
my $score = $score{language}{$language}{ELAS}{f}; |
|
print("$language\t$score\n"); |
|
$sum += $score; |
|
} |
|
print( "---------------------\n"); |
|
printf( "AVG\t%.2f\n", $sum/$n); |
|
print("\n"); |
|
print("Finished processing $team_name $submission_id $portion.\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub saferun |
|
{ |
|
my $command = join(' ', @_); |
|
|
|
|
|
system($command); |
|
|
|
if($?==-1) |
|
{ |
|
die("ERROR: Failed to execute: $command\n $!\n"); |
|
} |
|
|
|
elsif($? & 127) |
|
{ |
|
printf STDERR ("ERROR: Execution of: $command\n died with signal %d, %s coredump\n", |
|
($? & 127), ($? & 128) ? 'with' : 'without'); |
|
die; |
|
} |
|
|
|
|
|
else |
|
{ |
|
my $exitcode = $? >> 8; |
|
print STDERR ("Exit code: $exitcode\n") if($exitcode); |
|
|
|
|
|
|
|
|
|
|
|
return ! $exitcode; |
|
} |
|
} |
|
|