Skip to content

Commit

Permalink
removing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
moosavne committed Jul 25, 2016
1 parent 3340858 commit e51ad65
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
100 changes: 51 additions & 49 deletions lib/CorScorer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package CorScorer;
# Revised in March, 2014 by Sameer Pradhan (sameer.pradhan <at> childrens.harvard.edu)
# to implement the BLANC metric for predicted mentions


use strict;
use Algorithm::Munkres;
use Data::Dumper;
Expand All @@ -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";

##
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -234,7 +233,7 @@ sub GetCoreference {
my @sentId;
while (my $l = <F>) {
chomp($l);
$l =~ s/^\s+$//;
$l =~ s/^\s+$//;
next if ($l eq '');
if ($l =~ /\#\s*end document/) {
foreach my $h (@half) {
Expand Down Expand Up @@ -340,7 +339,7 @@ sub GetFileNames {
}

sub IdentifMentions {
my ($keys, $response, $totals) = @_;
my ($keys, $response, $totals) = @_;
my @kChains;
my @kChainsWithSingletonsFromResponse;
my @rChains;
Expand Down Expand Up @@ -370,21 +369,21 @@ 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] ",
$map{"$mention->[0],$mention->[1]"},
$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]"})
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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++;
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion scorer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e51ad65

Please sign in to comment.