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