sub oldscore { my $chunk = shift; my $pattern = shift; $pattern =~ s|(?codechunks($code); my @ncc; my($match, $nmatch, $ymatch) = (0,0,0); return undef unless @codechunks; unless (overlap($chunk->begin, $chunk->begin, $codechunks[0]->{chunk}->begin, $codechunks[0]->{chunk}->end)) { push(@ncc, new Textchunk ($chunk->project, $chunk->begin, $codechunks[0]->{chunk}->begin -1)); } for ($try = 1; $try <= $#codechunks; $try++) { push(@ncc, new Textchunk ($chunk->project, $codechunks[$try-1]->{chunk}->end + 1, $codechunks[$try]->{chunk}->begin - 1)); } unless (overlap($chunk->end, $chunk->end, $codechunks[$#codechunks]->{chunk}->begin, $codechunks[$#codechunks]->{chunk}->end)) { push(@ncc, new Textchunk ($chunk->project, $codechunks[$#codechunks]->{chunk}->end + 1, $chunk->end)); } #at this point we should have everything either in @ncc (not coded) or # @codechunks (coded) foreach (@ncc) { my $string = join(' ', $_->words); $match = 1; foreach (@patterns) { unless ($string =~ /$_/) { $match = 0; last; } } $nmatch += $match; } foreach (@codechunks) { my $string = join(' ', $_->{chunk}->words); $match = 1; foreach (@patterns) { unless ($string =~ /$_/) { $match = 0; last; } } $ymatch += $match; } return ($ymatch / @codechunks, 1 - ($nmatch / @ncc)); } sub score { my $chunk = shift; my $pattern = shift; $pattern = qr/$pattern/; my $code = shift; my ($ycc, $ncc); print STDERR ctime(time), " Textchunk::score $pattern $code\n" if $Main::debug; my @codechunks = $chunk->codechunks($code); my @ncc; my($match, $nmatch, $ymatch) = (0,0,0); return undef unless @codechunks; unless (overlap($chunk->begin, $chunk->begin, $codechunks[0]->{chunk}->begin, $codechunks[0]->{chunk}->end)) { push(@ncc, new Textchunk ($chunk->project, $chunk->begin, $codechunks[0]->{chunk}->begin -1)); } for ($try = 1; $try <= $#codechunks; $try++) { push(@ncc, new Textchunk ($chunk->project, $codechunks[$try-1]->{chunk}->end + 1, $codechunks[$try]->{chunk}->begin - 1)); } unless (overlap($chunk->end, $chunk->end, $codechunks[$#codechunks]->{chunk}->begin, $codechunks[$#codechunks]->{chunk}->end)) { push(@ncc, new Textchunk ($chunk->project, $codechunks[$#codechunks]->{chunk}->end + 1, $chunk->end)); } #at this point we should have everything either in @ncc (not coded) or # @codechunks (coded). foreach (@ncc) { my $string = join(' ', $_->words); $nmatch++ if $string =~ /$pattern/; } foreach (@codechunks) { my $string = join(' ', $_->{chunk}->words); $ymatch++ if $string =~ /$pattern/; } if (@codechunks) { $ycc = $ymatch / @codechunks; } else { $ycc = 0; } if (@ncc) { $ncc = 1 - ($nmatch / @ncc); } else { $ncc = 1; } return ($ycc, $ncc); }