Block/W2A/TokenizeOnWhitespace.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 70.0% 7 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 90.1% 55 / 61 CC 8 SCAR 16.3
CC
8
Cov
90%
process_zone
8.1
tokenize_sentence
2.0
BEGIN
1.0
CRAP 5.1
« Block/W2A/SegmentOnNewlines.pm ↑ Summary Block/Read/BaseAlignedTextReader.pm »
1 package Treex::Block::W2A::TokenizeOnWhitespace;
2 3 $Treex::Block::W2A::TokenizeOnWhitespace::VERSION = '2.20151102';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 extends 'Treex::Core::Block';
9  
10 0 ▶sub tokenize_sentence {
Subroutine tokenize_sentence: not called CC=1 SCAR=6.9
Pod documented
11 0 my ( $self, $sentence ) = @_;
12 0 return $sentence;
13 }
14  
15 1 ▶sub process_zone {
Subroutine process_zone: called CC=8 SCAR=20.9
Pod documented
16 1 my ( $self, $zone ) = @_;
17  
18 # create a-tree
19 1 my $a_root = $zone->create_atree();
20  
21 # get the source sentence and tokenize
22 1 my $sentence = $zone->sentence;
23 1 $sentence =~ s/^\s+//;
24 1 ▶ log_fatal("No sentence to tokenize!") if !defined $sentence;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sentence 0 1 1
25 1 my @tokens = split( /\s/, $self->tokenize_sentence($sentence) );
26  
27 # Create a-nodes and detect the no_space_after attribute.
28 1 foreach my $i ( ( 0 .. $#tokens ) ) {
29 4 my $token = $tokens[$i];
30  
31 # By default, there is a space after each token.
32 4 my $no_space_after = 0;
33  
34 # Delete the token from the begining of the sentence.
35 4 ▶ if ($sentence =~ s/^\Q$token\E//){
Branch: 2 branches
BranchTrueFalseTotal
if ($sentence =~ s/^\Q$token\E//) { } 3 1 4
elsif ($i < $#tokens) { } 1 0 1
36 # This is the expected case. The sentence starts with the $token.
37 # If it is followed by a space, delete the space and set no_space_after=1.
38 3 ▶ $no_space_after = 1 if length($sentence) && $sentence !~ s/^\s+//;
Branch: 1 branch
BranchTrueFalseTotal
if length $sentence and not $sentence =~ s/^\s+// 1 2 3
Condition100%3/3
length $sentence and not $sentence =~ s/^\s+//
!ll&&!rl&&r
111
MC/DC100%2/2
length $sentence and not $sentence =~ s/^\s+//
length $sentence not $sentence =~ s/^\s+//
Truth table100%3/3
A and not(B)
A= length $sentenceB= not $sentence =~ s/^\s+//
ABresult
0X0
100
111
39 } elsif ($i < $#tokens) {
40 # The token (returned from tokenization) does not match the start of sentence.
41 # E.g. '. . . word' is tokenized as '... word'.
42 # Let's delete the start of sentence anyway,
43 # using a non-greedy regex and the expected next token returned from the tokenization.
44 1 my $next_token = $tokens[$i+1];
45 1 my ($first, $rest) = ($sentence =~ /^(.*?)(\Q$next_token\E.*)$/);
46 1 ▶ $no_space_after = 1 if $first !~ /\s$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $first =~ /\s$/ 0 1 1
47 1 $sentence = $rest;
48 }
49  
50 # create new a-node
51 $a_root->create_child(
52 4 form => $token,
53 no_space_after => $no_space_after,
54 ord => $i + 1,
55 );
56 }
57 1 return 1;
58 }
59  
60 3 1;
61  
62 __END__
« Block/W2A/SegmentOnNewlines.pm ↑ Summary Block/Read/BaseAlignedTextReader.pm »