[KinoSearch] Subclassable Highlighter

Marvin Humphrey marvin at rectangular.com
Sun Jan 27 17:34:39 PST 2008




On Jan 27, 2008, at 1:49 PM, Father Chrysostomos wrote:

>  I’ve noticed what I believe to be a couple of bugs in  
> _calc_best_location, but I want to check with you to make sure:
>
> sub _calc_best_location {
> ...
>     for my $loc_index ( 0 .. $#$posits ) {
>         # only score positions that are in range
>         my $location        = $posits->[$loc_index][0];
>         my $other_loc_index = $loc_index - 1;
>         while ( $other_loc_index > 0 ) {
>
> Should this not be >= ?

Oof.  Coming back to it, this code is kind of hard to grok.  :\  And  
test (so there are no tests for it).

I think you're right.

>
>             my $diff = $location - $posits->[$other_loc_index][0];
>             last if $diff > $window;
>             my $num_tokens_at_pos = $posits->[$other_loc_index][2];
>             $locations{$location}
>                 += ( 1 / ( 1 + log($diff) ) ) * $num_tokens_at_pos;
>             --$other_loc_index;
>         }
>         $other_loc_index = $loc_index + 1;
>         while ( $other_loc_index <= $#$posits ) {
>             my $diff = $posits->[$other_loc_index] - $location;
>
> Shouldn’t $posits->[$other_loc_index] have [0] on the end?

Yes.

Existing high-level tests for Highlighter still pass after making  
these changes, so I've commited them as r2956.  Thank you for finding  
the bugs.

This code will end up in HeatMap.  I look forward to refactoring it  
for clarity and writing up some tests for it.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/



_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch




More information about the kinosearch mailing list