in reply to term weighting :convert python to perl
Update: Fixed logic error in setting of $locations{ $row->[0] }. I've taken a little liberty with the logic. To make it conform strictly with the original python coding, just addsub locationscore { my $self = shift; my $rows = shift; my %locations; for my $row (@$rows) { my $sum = 0; for (1..$#$row) { $sum += $row->[$_] }; if (!defined($locations{ $row->[0] } || $sum < $locations{ $row->[ +0] } ) { $locations{ $row->[0] } = $sum; } } $self->normalizescores(\%locations, ...); }
right before the for loop.$locations{ $_->[0] } = 1_000_000 for (@$rows);
|
|---|