-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscorer.pl
60 lines (51 loc) · 1.14 KB
/
scorer.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
=comment
The goal of this script is to compare the output of decision-tree.pl with the key file.
Usage: perl scorer.pl **TEST FILE** **KEY FILE**
=cut
#We assume here that the lines are in one to one correspondence(which they are)
main();
sub main
{
#Grabs the input params
my $testFile = $ARGV[0];
my $keyFile = $ARGV[1];
#Get all of the senseids from the test file:
@testAnswers = ();
open(MYFILE, $testFile);
my $lines = <MYFILE>;
$_ = $lines;
for (<MYFILE>)
{
if (m/senseid=(".*")/gms)
{
push @testAnswers, $1;
}
}
close(MYFILE);
#Get all of the senseids from the test file:
@keyAnswers = ();
open(MYFILE, $keyFile);
$lines = <MYFILE>;
$_ = $lines;
for (<MYFILE>)
{
if (m/senseid=(".*")/gms)
{
push @keyAnswers, $1;
}
}
close(MYFILE);
my $right;
my $total;
my $arrSize = @testAnswers;
for (my $i = 0; $i < $arrSize; $i++)
{
if ($testAnswers[$i] eq $keyAnswers[$i])
{
$right++;
}
$total++;
}
my $accuracy = $right/$total;
print "This decision tree got $right correct out of $total total giving an overall accuracy of $accuracy%.";
}