line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Set::Similarity::BV::Cosine; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
730
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
451
|
use parent 'Set::Similarity::BV'; |
|
1
|
|
|
|
|
284
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
643
|
use Data::Dumper; |
|
1
|
|
|
|
|
5143
|
|
|
1
|
|
|
|
|
123
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub from_integers { |
13
|
9
|
|
|
9
|
1
|
10
|
my ($self, $v1, $v2) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#print Dumper($v1, $v2); |
16
|
|
|
|
|
|
|
#print 'from_integers() $v1: ',$v1->[0],' $v2: ',$v2->[0],"\n"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#print 'from_integers: ',"\n"; |
19
|
|
|
|
|
|
|
#print ' $self->bits($v1): ',$self->bits($v1),' ',"\n"; |
20
|
|
|
|
|
|
|
#print ' $self->bits($v2): ',$self->bits($v2),' ',"\n"; |
21
|
|
|
|
|
|
|
#print ' $self->intersection($v1,$v2): ',$self->intersection($v1,$v2),' ',"\n"; |
22
|
|
|
|
|
|
|
#print ' $self->bits($v2): ',$self->bits($v2),' ',"\n"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# it is so simple because the vectors contain only 0 and 1 |
25
|
|
|
|
|
|
|
return ( |
26
|
9
|
|
|
|
|
23
|
$self->intersection($v1,$v2) / ( |
27
|
|
|
|
|
|
|
sqrt($self->bits($v1)) * sqrt($self->bits($v2)) |
28
|
|
|
|
|
|
|
) |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__END__ |