From e51ad65f96be48095dd497ad045a0f0f21c92234 Mon Sep 17 00:00:00 2001 From: moosavne Date: Mon, 25 Jul 2016 15:37:23 +0200 Subject: [PATCH] removing tabs --- lib/CorScorer.pm | 100 ++++++++++++++++++++++++----------------------- scorer.pl | 2 +- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/lib/CorScorer.pm b/lib/CorScorer.pm index 5ceeb92..5fa07cc 100644 --- a/lib/CorScorer.pm +++ b/lib/CorScorer.pm @@ -24,7 +24,6 @@ package CorScorer; # Revised in March, 2014 by Sameer Pradhan (sameer.pradhan childrens.harvard.edu) # to implement the BLANC metric for predicted mentions - use strict; use Algorithm::Munkres; use Data::Dumper; @@ -33,8 +32,7 @@ use Data::Dumper; use Math::Combinatorics; use Cwd; - -our $VERSION = '8.01'; +our $VERSION = '9.0'; print "version: " . $VERSION . " " . Cwd::realpath(__FILE__) . "\n"; ## @@ -95,7 +93,7 @@ my $KEY_COLUMN = -1; # F1 = 2 * Recall * Precision / (Recall + Precision) sub Score { my ($metric, $kFile, $rFile, $name) = @_; - our $repeated_mentions = 0; + our $repeated_mentions = 0; if (lc($metric) eq 'blanc') { return ScoreBLANC($kFile, $rFile, $name); @@ -129,7 +127,8 @@ sub Score { foreach my $iname (keys(%{$kIndexNames})) { my $keys = GetCoreference($kFile, $KEY_COLUMN, $iname, $kIndexNames->{$iname}); - my $response = GetCoreference($rFile, $RESPONSE_COLUMN, $iname, + my $response = + GetCoreference($rFile, $RESPONSE_COLUMN, $iname, $rIndexNames->{$iname}); print "$iname:\n" if ($VERBOSE); @@ -234,7 +233,7 @@ sub GetCoreference { my @sentId; while (my $l = ) { chomp($l); - $l =~ s/^\s+$//; + $l =~ s/^\s+$//; next if ($l eq ''); if ($l =~ /\#\s*end document/) { foreach my $h (@half) { @@ -340,7 +339,7 @@ sub GetFileNames { } sub IdentifMentions { - my ($keys, $response, $totals) = @_; + my ($keys, $response, $totals) = @_; my @kChains; my @kChainsWithSingletonsFromResponse; my @rChains; @@ -370,7 +369,7 @@ sub IdentifMentions { my $i = 0; my @remove; - + foreach my $mention (@$entity) { if (defined($map{"$mention->[0],$mention->[1]"})) { print "Repeated mention in the response: $mention->[0], $mention->[1] ", @@ -378,13 +377,13 @@ sub IdentifMentions { $id{"$mention->[0],$mention->[1]"}, "\n"; push(@remove, $i); - $main::repeated_mentions++; + $main::repeated_mentions++; - if ($main::repeated_mentions > 10) - { - print STDERR "Found too many repeated mentions (> 10) in the response, so refusing to score. Please fix the output.\n"; - exit 1; - } + if ($main::repeated_mentions > 10) { + print STDERR +"Found too many repeated mentions (> 10) in the response, so refusing to score. Please fix the output.\n"; + exit 1; + } } elsif (defined($id{"$mention->[0],$mention->[1]"}) @@ -404,25 +403,21 @@ sub IdentifMentions { } } + # now, lets remove any empty elements in the response array after removing + # potential repeats + my @another_remove = (); + my $ii; - # now, lets remove any empty elements in the response array after removing - # potential repeats - my @another_remove = (); - my $ii; - - foreach my $eentity (@$response) - { - if ( @$eentity == 0) - { - push(@another_remove, $ii); - } - $ii++; - } - - foreach my $iii (sort { $b <=> $a } (@another_remove)) { - splice(@$response, $iii, 1); - } + foreach my $eentity (@$response) { + if (@$eentity == 0) { + push(@another_remove, $ii); + } + $ii++; + } + foreach my $iii (sort { $b <=> $a } (@another_remove)) { + splice(@$response, $iii, 1); + } # Partial identificaiton: Inside bounds and including the head my $part = 0; @@ -710,10 +705,12 @@ sub BCUBED { return ($acumR, $keymentions, $acumP, $resmentions); } -sub LEA{ +sub LEA { my ($keys, $responses) = @_; + # Computing recall my ($acumR, $keysImportance) = LEASUB($keys, $responses); + # Computing precision my ($acumP, $responsesImportance) = LEASUB($responses, $keys); @@ -722,26 +719,30 @@ sub LEA{ } -sub LEASUB{ +sub LEASUB { my ($keys, $responses) = @_; my $rIndex = Indexa($responses); - my $leaScore = 0; + my $leaScore = 0; my $importance = 0; foreach my $kEntity (@$keys) { next if (!defined($kEntity)); my $entitySize = scalar(@$kEntity); - my $resolvedLinks = 0; + my $resolvedLinks = 0; my @mappedEntities = (); - if ($entitySize == 1){ #singletons + if ($entitySize == 1) { #singletons my $cMention = $kEntity->[0]; - my $rEntity = (defined($rIndex->{$cMention})) ? $responses->[$rIndex->{$cMention}] : []; + my $rEntity = + (defined($rIndex->{$cMention})) + ? $responses->[$rIndex->{$cMention}] + : []; my $rEntitySize = scalar(@$rEntity); - - if ($rEntitySize == 1){ #the source singleton mention is also a singleton in the target entities + + if ($rEntitySize == 1) + { #the source singleton mention is also a singleton in the target entities $resolvedLinks++; } } @@ -761,24 +762,23 @@ sub LEASUB{ } my $entityLinks; - if ($entitySize == 1){ + if ($entitySize == 1) { $entityLinks = 1; } else { - $entityLinks = ($entitySize * ($entitySize-1)/2) if ($entitySize); + $entityLinks = ($entitySize * ($entitySize - 1) / 2) if ($entitySize); } - + my $resolutionScore = 0; $resolutionScore = $resolvedLinks / $entityLinks if ($entityLinks); - $leaScore += ($resolutionScore * $entitySize); + $leaScore += ($resolutionScore * $entitySize); $importance += $entitySize; } - + return ($leaScore, $importance); } - # type = 0: Entity-based # type = 1: Mention-based sub CEAF { @@ -863,9 +863,10 @@ sub SIMEntityBased { } } } -# if ($intersection == 1){ -# $intersection = 0 -# } + + # if ($intersection == 1){ + # $intersection = 0 + # } my $r = 0; my $d = scalar(@$a) + scalar(@$b); if ($d != 0) { @@ -944,7 +945,8 @@ sub ScoreBLANC { foreach my $iname (keys(%{$kIndexNames})) { my $keys = GetCoreference($kFile, $KEY_COLUMN, $iname, $kIndexNames->{$iname}); - my $response = GetCoreference($rFile, $RESPONSE_COLUMN, $iname, + my $response = + GetCoreference($rFile, $RESPONSE_COLUMN, $iname, $rIndexNames->{$iname}); print "$name:\n" if ($VERBOSE); diff --git a/scorer.pl b/scorer.pl index b0ef98f..2bc0eee 100755 --- a/scorer.pl +++ b/scorer.pl @@ -48,7 +48,7 @@ BEGIN } if ($metric eq 'all') { - foreach my $m ('muc', 'bcub', 'ceafm', 'ceafe', 'blanc', 'lea') { + foreach my $m ('muc', 'bcub', 'ceafe', 'lea') { print "\nMETRIC $m:\n"; &CorScorer::Score($m, @ARGV); }