| 1 | package Grapheme::Ngram; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.006'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 10 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||
| 11 | # uncoverable condition false | ||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/3
ref $class || $class
MC/DC100%0/2
ref $class || $class
ref $class
$class
Truth table100%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | sub ngram { | ||||||||||||||||||||||||||||||
|
Subroutine
ngram: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 16 | 14 | my ($self, $word, $width) = @_; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 14 | ▶ | return [] unless (length($word)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 11 | return $self->from_tokens( | |||||||||||||||||||||||||||||||
| 21 | $self->_tokenize($word), | ||||||||||||||||||||||||||||||||
| 22 | $width | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 11 | ▶ | sub from_tokens { | ||||||||||||||||||||||||||||||
|
Subroutine
from_tokens: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 27 | 11 | my ($self, $tokens, $width) = @_; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 11 | ▶ | $width = 1 unless ($width && $width =~ m/^[1-9][0-9]*$/x); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$width and $width =~ /^[1-9][0-9]*$/x
MC/DC100%2/2
$width and $width =~ /^[1-9][0-9]*$/x
$width
$width =~ /^[1-9][0-9]*$/x
Truth table100%3/3
A and B
A= $widthB= $width =~ /^[1-9][0-9]*$/x
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | return [join('',@$tokens)] unless ($width <= scalar @$tokens); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 10 | my @ngrams; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 10 | for my $i (0..scalar(@$tokens)-$width) { | |||||||||||||||||||||||||||||||
| 36 | 13 | my $ngram = join('',@$tokens[$i..$i+$width-1]); | |||||||||||||||||||||||||||||||
| 37 | 13 | push @ngrams,$ngram; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 10 | return \@ngrams; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | sub _tokenize { [$_[1] =~ m/(\X)/g] } | ||||||||||||||||||||||||||||||
|
Subroutine
_tokenize: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 1 | 1; | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||||||