Plucene/Analysis/CharTokenizer.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 94.8% 55 / 58 CC 6 SCAR 12.2
CC
6
Cov
96%
next
6.0
token_re
2.0
BEGIN
1.0
CRAP 3.4
« Plucene/Search/Hits.pm ↑ Summary Plucene/Search/BooleanScorer.pm »
1 package Plucene::Analysis::CharTokenizer;
2  
3 =head1 NAME
4  
5 Plucene::Analysis::CharTokenizer - base class for character tokenisers
6  
7 =head1 SYNOPSIS
8  
9 # isa Plucene::Analysis::Tokenizer
10  
11 my $next = $chartokenizer->next;
12
13 =head1 DESCRIPTION
14  
15 This is an abstract base class for simple, character-oriented tokenizers.
16  
17 =head1 METHODS
18  
19 =cut
20  
21 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 19 ▶use Plucene::Analysis::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 19 ▶use base 'Plucene::Analysis::Tokenizer';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 =head2 token_re
31  
32 This should be defined in subclasses.
33  
34 =cut
35  
36 # And here we deviate from the script
37 0 ▶sub token_re { die "You should define this" }
Subroutine token_re: not called CC=1 SCAR=6.9
Pod documented
38  
39 # Class::Virtually::Abstract doesn't like being called twice.
40  
41 =head2 normalize
42  
43 This will normalise the character before it is added to the token.
44  
45 =cut
46  
47 402 ▶sub normalize { return $_[1] }
Subroutine normalize: called CC=1 SCAR=0.0
Pod documented
48  
49 =head2 next
50  
51 my $next = $chartokenizer->next;
52  
53 This will return the next token in the string, or undef at the end
54 of the string.
55
56 =cut
57  
58 144605 ▶sub next {
Subroutine next: called CC=6 SCAR=17.9
Pod documented
59 144605 my $self = shift;
60 144605 my $re = $self->token_re();
61 144605 my $fh = $self->{reader};
62 retry:
63 159746 ▶ if (!defined $self->{buffer} or !length $self->{buffer}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"buffer"} and length $self->{"buffer"}) 16278 143468 159746
Condition100%3/3
defined $self->{"buffer"} and length $self->{"buffer"}
!ll&&!rl&&r
59515683143468
MC/DC100%2/2
defined $self->{"buffer"} and length $self->{"buffer"}
defined $self->{"buffer"} length $self->{"buffer"}
Truth table100%3/3
A and B
A= defined $self->{"buffer"}B= length $self->{"buffer"}
ABresult
0X0
100
111
64 16278 ▶ return if eof($fh);
Branch: 1 branch
BranchTrueFalseTotal
if eof $fh 595 15683 16278
65 15683 $self->{start} = tell($fh);
66 15683 $self->{buffer} .= <$fh>;
67 }
68 159151 ▶ return unless length $self->{buffer};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"buffer"} 0 159151 159151
69  
70 159151 ▶ if ($self->{buffer} =~ s/(.*?)($re)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"buffer"} =~ s/(.*?)($re)//) 144010 15141 159151
71 144010 $self->{start} += length $1;
72 144010 my $word = $self->normalize($2);
73 my $rv = Plucene::Analysis::Token->new(
74 text => $word,
75 start => $self->{start},
76 144010 end => ($self->{start} + length($word)));
77 144010 $self->{start} += length($word);
78 144010 return $rv;
79 }
80  
81 # No match, rest of buffer is useless.
82 15141 $self->{buffer} = "";
83  
84 # But we should try for some more text
85 15141 goto retry;
86 }
87  
88 19 1;
« Plucene/Search/Hits.pm ↑ Summary Plucene/Search/BooleanScorer.pm »