Block/W2A/EN/Tokenize.pm

filter: Statementstmt 39.3% 13 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 44.7% 17 / 38 CC 1 SCAR 1.8
CC
1
Cov
39%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Block/W2A/EN/Lemmatize.pm ↑ Summary Tool/Segment/EN/RuleBased.pm »
1 package Treex::Block::W2A::EN::Tokenize;
2 BEGIN {
3 1 ▶ $Treex::Block::W2A::EN::Tokenize::VERSION = '0.06903_1';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 extends 'Treex::Block::W2A::Tokenize';
10  
11 override 'tokenize_sentence' => sub {
12 0 ▶ my ( $self, $sentence ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 0 $sentence = super();
14 0 $sentence =~ s/^(.*)$/ $1 /;
15  
16 # it's, I'm, we'd, we're, you'll, I've, Peter's
17 0 $sentence =~ s/([\'’])(s|m|d|ll|re|ve|S|M|D|LL|RE|VE)\s/ $1$2 /g;
18  
19 # don't
20 0 $sentence =~ s/(n[\'’]t\s)/ $1 /g;
21 0 $sentence =~ s/(N[\'’]T\s)/ $1 /g;
22  
23 # cannot, wanna ...
24 0 $sentence =~ s/ ([Cc])annot / $1an not /g;
25 0 $sentence =~ s/ ([Dd])'ye / $1' ye /g;
26 0 $sentence =~ s/ ([Gg])imme / $1im me /g;
27 0 $sentence =~ s/ ([Gg])onna / $1on na /g;
28 0 $sentence =~ s/ ([Gg])otta / $1ot ta /g;
29 0 $sentence =~ s/ ([Ll])emme / $1em me /g;
30 0 $sentence =~ s/ ([Mm])ore'n / $1ore 'n /g;
31 0 $sentence =~ s/ '([Tt])is / '$1 is /g;
32 0 $sentence =~ s/ '([Tt])was / '$1 was /g;
33 0 $sentence =~ s/ ([Ww])anna / $1an na /g;
34  
35 # clean out extra spaces
36 0 $sentence =~ s/\s+/ /g;
37 0 $sentence =~ s/^\s*//g;
38 0 $sentence =~ s/\s*$//g;
39  
40 0 return $sentence;
41 1 };
42  
43 1 1;
44  
45 __END__
46  
47 =over
48  
49 =item Treex::Block::W2A::EN::Tokenize
50  
51 Each sentence is split into a sequence of tokens using a series of regexs.
52 Flat a-tree is built and attributes C<no_space_after> are filled.
53 This class uses English specific regex rules for tokenization
54 of contractions like I<He's, we'll, they've, don't> etc.
55  
56 =back
57  
58 =cut
59  
60 # Copyright 2011 David Marecek, Martin Popel
61 # This file is distributed under the GNU General Public License v2. See $TMT_ROOT/README.
« Block/W2A/EN/Lemmatize.pm ↑ Summary Tool/Segment/EN/RuleBased.pm »