| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Text::NSP::Measures::2D::Dice::jaccard - Perl module that implements |
|
4
|
|
|
|
|
|
|
the jaccard coefficient. |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head3 Basic Usage |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Text::NSP::Measures::2D::Dice::jaccard; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $npp = 60; my $n1p = 20; my $np1 = 20; my $n11 = 10; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$jaccard_value = calculateStatistic( n11=>$n11, |
|
15
|
|
|
|
|
|
|
n1p=>$n1p, |
|
16
|
|
|
|
|
|
|
np1=>$np1, |
|
17
|
|
|
|
|
|
|
npp=>$npp); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if( ($errorCode = getErrorCode())) |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
|
|
|
|
|
|
print STDERR $errorCode." - ".getErrorMessage()."\n""; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
else |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
|
|
|
|
|
|
print getStatisticName."value for bigram is ".$jaccard_value."\n""; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Assume that the frequency count data associated with a bigram |
|
32
|
|
|
|
|
|
|
is stored in a 2x2 contingency table: |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
word2 ~word2 |
|
35
|
|
|
|
|
|
|
word1 n11 n12 | n1p |
|
36
|
|
|
|
|
|
|
~word1 n21 n22 | n2p |
|
37
|
|
|
|
|
|
|
-------------- |
|
38
|
|
|
|
|
|
|
np1 np2 npp |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
where n11 is the number of times occur together, and |
|
41
|
|
|
|
|
|
|
n12 is the number of times occurs with some word other than |
|
42
|
|
|
|
|
|
|
word2, and n1p is the number of times in total that word1 occurs as |
|
43
|
|
|
|
|
|
|
the first word in a bigram. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The Jaccard Coefficient is the ratio of number of times the words |
|
46
|
|
|
|
|
|
|
occur together to the number of times atleast any one of the words |
|
47
|
|
|
|
|
|
|
occur. It is defined as: |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
n11 |
|
50
|
|
|
|
|
|
|
--------------- |
|
51
|
|
|
|
|
|
|
n11 + n12 + n21 |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The Jaccard coefficient can also be computed by applying a |
|
54
|
|
|
|
|
|
|
transformation to the dice coefficient: |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$jaccard = $dice/(2-$dice) |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
We use this computation of jaccard in our implementation. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 Methods |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
package Text::NSP::Measures::2D::Dice::jaccard; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
1
|
|
|
1
|
|
1633
|
use Text::NSP::Measures::2D::Dice; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
68
|
|
|
71
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
17
|
|
|
72
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
44
|
|
|
73
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
74
|
1
|
|
|
1
|
|
4
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
180
|
|
|
75
|
|
|
|
|
|
|
require Exporter; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
our ($VERSION, @EXPORT, @ISA); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
@EXPORT = qw(initializeStatistic calculateStatistic |
|
82
|
|
|
|
|
|
|
getErrorCode getErrorMessage getStatisticName); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$VERSION = '0.97'; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item calculateStatistic() - method to calculate the jaccard coefficient value |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
INPUT PARAMS : $count_values .. Reference of an hash containing |
|
90
|
|
|
|
|
|
|
the count values computed by the |
|
91
|
|
|
|
|
|
|
count.pl program. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
RETURN VALUES : $jaccard .. Jaccard Coefficient value for this bigram. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub calculateStatistic |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
11
|
|
|
11
|
|
2063
|
my %values = @_; |
|
100
|
11
|
|
|
|
|
12
|
my $dice; |
|
101
|
|
|
|
|
|
|
my $jaccard; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#compute the dice coefficient |
|
104
|
11
|
100
|
|
|
|
39
|
if( !($dice = Text::NSP::Measures::2D::Dice::computeVal(\%values)) ) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
10
|
|
|
|
|
25
|
return; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#compute the jaccard coefficient from the dice coefficient |
|
110
|
1
|
|
|
|
|
3
|
$jaccard = $dice/(2-$dice); |
|
111
|
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
3
|
return ($jaccard); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item getStatisticName() - Returns the name of this statistic |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
INPUT PARAMS : none |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
RETURN VALUES : $name .. Name of the measure. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub getStatisticName |
|
126
|
|
|
|
|
|
|
{ |
|
127
|
0
|
|
|
0
|
|
|
return "Jaccard Coefficient"; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
|
133
|
|
|
|
|
|
|
__END__ |