line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Text::NSP::Measures::2D::Dice::dice - Perl module to compute Dice coefficient |
4
|
|
|
|
|
|
|
for bigrams. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head3 Basic Usage |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Text::NSP::Measures::2D::Dice::dice; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $npp = 60; my $n1p = 20; my $np1 = 20; my $n11 = 10; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$dice_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 ".$dice_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 Dice Coefficient is defined as : |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
2 * n11 |
48
|
|
|
|
|
|
|
--------- |
49
|
|
|
|
|
|
|
np1 + n1p |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The Jaccard coefficient can also be computed by applying a |
52
|
|
|
|
|
|
|
transformation to the dice coefficient: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$jaccard = $dice/(2-$dice) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 Methods |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
package Text::NSP::Measures::2D::Dice::dice; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
|
1651
|
use Text::NSP::Measures::2D::Dice; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
67
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
68
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
69
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
70
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
179
|
|
71
|
|
|
|
|
|
|
require Exporter; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
our ($VERSION, @EXPORT, @ISA); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
@EXPORT = qw(initializeStatistic calculateStatistic |
78
|
|
|
|
|
|
|
getErrorCode getErrorMessage getStatisticName); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$VERSION = '0.97'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item calculateStatistic() - method to calculate the dice coefficient value |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
INPUT PARAMS : $count_values .. Reference of an hash containing |
86
|
|
|
|
|
|
|
the count values computed by the |
87
|
|
|
|
|
|
|
count.pl program. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
RETURN VALUES : $dice .. Dice Coefficient value for this bigram. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub calculateStatistic |
94
|
|
|
|
|
|
|
{ |
95
|
28
|
|
|
28
|
|
3607
|
my %values = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#compute and return the dice coefficient. |
98
|
28
|
|
|
|
|
77
|
return Text::NSP::Measures::2D::Dice::computeVal(\%values); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item getStatisticName() - Returns the name of this statistic |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
INPUT PARAMS : none |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
RETURN VALUES : $name .. Name of the measure. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub getStatisticName |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
0
|
|
|
my ($self)=@_; |
113
|
0
|
|
|
|
|
|
return "Dice Coefficient"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
__END__ |