| 1 | package Search::Fulltext::Tokenizer::Ngram; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Character n-gram tokenizer for Search::Fulltext | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util qw/looks_like_number/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = 0.01; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 32 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 32 | my ($class, $token_length) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 32 | ▶ | unless (looks_like_number $token_length and $token_length > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_number($token_length) and $token_length > 0
MC/DC0%0/2
&looks_like_number($token_length) and $token_length > 0
&looks_like_number($token_length)
$token_length > 0
Truth table33%1/3
A and B
A= &looks_like_number($token_length)B= $token_length > 0
| |||||||||||||||||||||||||||||
| 16 | 0 | Carp::croak('Token length must be 1+.'); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 32 | bless +{ token_length => $token_length } => $class; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 32 | ▶ | sub create_token_iterator { | ||||||||||||||||||||||||||
|
Subroutine
create_token_iterator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 32 | my ($self, $text) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 32 | my $token_index = -1; | |||||||||||||||||||||||||||
| 26 | 32 | my $n = $self->token_length; | |||||||||||||||||||||||||||
| 27 | 218 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 28 | GET_NEXT_TOKEN: | ||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 218 | ++$token_index; | |||||||||||||||||||||||||||
| 31 | 242 | ▶ | return if $token_index + $n > length($text); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 221 | my $token = substr $text, $token_index, $n; | |||||||||||||||||||||||||||
| 33 | 221 | ▶ | redo GET_NEXT_TOKEN if $token =~ /\s/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 197 | return ($token, $n, $token_index, $token_index + $n, $token_index); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 32 | }; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 32 | ▶ | sub token_length { $_[0]->{token_length} } | ||||||||||||||||||||||||||
|
Subroutine
token_length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | __END__ | ||||||||||||||||||||||||||||