line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::Suggest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use 5.008008; |
4
|
1
|
|
|
1
|
|
37076
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
102
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
1594
|
use AutoLoader; |
|
1
|
|
|
|
|
9510
|
|
|
1
|
|
|
|
|
23
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use Statistics::Suggest ':all'; |
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
19
|
|
|
|
|
|
|
# will save memory. |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
21
|
|
|
|
|
|
|
) ] ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT = qw( |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub AUTOLOAD { |
32
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
33
|
|
|
|
|
|
|
# XS function. |
34
|
2
|
|
|
2
|
|
3
|
my $constname; |
35
|
2
|
|
|
|
|
2
|
our $AUTOLOAD; |
36
|
2
|
|
|
|
|
11
|
($constname = $AUTOLOAD) =~ s/.*:://; |
37
|
2
|
100
|
|
|
|
203
|
croak "&Statistics::Suggest::constant not defined" if $constname eq 'constant'; |
38
|
1
|
|
|
|
|
7
|
my ($error, $val) = constant($constname); |
39
|
0
|
0
|
|
|
|
0
|
if ($error) { croak $error; } |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
{ |
41
|
1
|
|
|
1
|
|
233
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
829
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
# Fixed between 5.005_53 and 5.005_61 |
43
|
|
|
|
|
|
|
#XXX if ($] >= 5.00561) { |
44
|
|
|
|
|
|
|
#XXX *$AUTOLOAD = sub () { $val }; |
45
|
|
|
|
|
|
|
#XXX } |
46
|
|
|
|
|
|
|
#XXX else { |
47
|
0
|
|
|
0
|
|
0
|
*$AUTOLOAD = sub { $val }; |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
#XXX } |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
goto &$AUTOLOAD; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
require XSLoader; |
54
|
|
|
|
|
|
|
XSLoader::load('Statistics::Suggest', $VERSION); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Preloaded methods go here. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
61
|
1
|
|
|
1
|
|
12
|
my $class = shift; |
62
|
1
|
|
|
|
|
7
|
my $self = bless { |
63
|
|
|
|
|
|
|
RType => 2, |
64
|
|
|
|
|
|
|
NNbr => 20, |
65
|
|
|
|
|
|
|
Alpha => 0.4, |
66
|
|
|
|
|
|
|
@_ |
67
|
|
|
|
|
|
|
}, $class; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
8
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub load_trans { |
73
|
1
|
|
|
1
|
|
3
|
my ($self, $trans) = @_; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
2
|
my $nusers = 0; |
76
|
1
|
|
|
|
|
2
|
my $nitems = 0; |
77
|
1
|
|
|
|
|
2
|
my $ntrans = 0; |
78
|
1
|
|
|
|
|
2
|
my @userid; |
79
|
|
|
|
|
|
|
my @itemid; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
for (@$trans) { |
82
|
18
|
|
|
|
|
22
|
my ($u, $i) = @$_; |
83
|
18
|
|
|
|
|
15
|
$ntrans ++; |
84
|
18
|
100
|
|
|
|
35
|
$nusers = $u if $u > $nusers; |
85
|
18
|
100
|
|
|
|
29
|
$nitems = $i if $i > $nitems; |
86
|
18
|
|
|
|
|
32
|
push @userid, $u; |
87
|
18
|
|
|
|
|
26
|
push @itemid, $i; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
2
|
$self->{nusers} = $nusers; |
91
|
1
|
|
|
|
|
3
|
$self->{nitems} = $nitems; |
92
|
1
|
|
|
|
|
2
|
$self->{ntrans} = $ntrans; |
93
|
1
|
|
|
|
|
4
|
$self->{userid} = \@userid; |
94
|
1
|
|
|
|
|
20
|
$self->{itemid} = \@itemid; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub init { |
98
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
33
|
|
|
34
|
croak "necessary params not set" unless ( |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
101
|
|
|
|
|
|
|
defined($self->{nusers}) and defined($self->{nitems}) and defined($self->{ntrans}) |
102
|
|
|
|
|
|
|
and defined($self->{userid}) and defined($self->{itemid}) |
103
|
|
|
|
|
|
|
and defined($self->{RType}) and defined($self->{NNbr}) |
104
|
|
|
|
|
|
|
and ($self->{NNbr} != 2 or defined($self->{Alpha})) |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
15
|
$self->{RcmdHandle} = _SUGGEST_Init( |
108
|
|
|
|
|
|
|
map $self->{$_}, qw(nusers nitems ntrans userid itemid RType NNbr Alpha) |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub estimate_alpha { |
113
|
0
|
|
|
0
|
|
0
|
my ($self, $nrcmd) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
0
|
|
|
0
|
croak "necessary params not set" unless ( |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
116
|
|
|
|
|
|
|
defined($self->{nusers}) and defined($self->{nitems}) and defined($self->{ntrans}) |
117
|
|
|
|
|
|
|
and defined($self->{RType}) and defined($self->{NNbr}) |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
0
|
|
|
0
|
$self->{NRcmd} = ($nrcmd || $self->{NRcmd}); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
0
|
$self->{Alpha} = _SUGGEST_EstimateAlpha( |
123
|
|
|
|
|
|
|
map $self->{$_}, qw(nusers nitems ntrans userid itemid NNbr NRcmd) |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub top_n { |
128
|
0
|
|
|
0
|
|
0
|
my ($self, $itemids, $nrcmd, $rcmds) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
0
|
croak "should init first" unless $self->{RcmdHandle}; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
0
|
|
|
0
|
$self->{NRcmd} = ($nrcmd || $self->{NRcmd}); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
return _SUGGEST_TopN( |
135
|
|
|
|
|
|
|
$self->{RcmdHandle}, scalar @$itemids, $itemids, $self->{NRcmd}, $$rcmds |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub DESTROY { |
140
|
1
|
|
|
1
|
|
137
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
1
|
50
|
|
|
|
105
|
if ($self->{RcmdHandle}) { |
143
|
0
|
|
|
|
|
|
_SUGGEST_Clean($self->{RcmdHandle}); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |