Block/W2A/EN/FixTokenization.pm

filter: Statementstmt 45.7% 16 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 46.6% 21 / 45 CC 5 SCAR 28.4
CC
5
Cov
41%
process_atree
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 17.1
« Block/W2A/EN/FixTagsAfterParse.pm ↑ Summary Block/W2A/EN/NormalizeForms.pm »
1 package Treex::Block::W2A::EN::FixTokenization;
2 1 $Treex::Block::W2A::EN::FixTokenization::VERSION = '2.20151102';
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 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 extends 'Treex::Core::Block';
8  
9 1 my %MERGE_FOR = (
10 'a . m .' => 'a. m.',
11 'p . m .' => 'p. m.',
12 'U . S .' => 'U. S.',
13 'e . g .' => 'e. g.',
14 'i . e .' => 'i. e.',
15 'Mrs .' => 'Mrs.',
16 'Mr .' => 'Mr.',
17 'Ms .' => 'Ms.',
18 'Dr .' => 'Dr.',
19 'km / h' => 'km/h',
20 'm / s' => 'm/s',
21 );
22  
23 #TODO (MP): rewrite this block
24  
25 0 ▶sub process_atree {
Subroutine process_atree: not called CC=5 SCAR=34.0
Pod documented
26 0 my ( $self, $atree ) = @_;
27  
28 0 my @nodes = $atree->get_children();
29 0 my @forms = map { $_->form } @nodes;
30 0 my $max_length = 3;
31 0 push @forms, map {'dummy'} ( 1 .. $max_length );
32  
33 # NB: do not rewrite this cycle to foreach, $i is also changed inside the cycle
34 # (whenever a match is found)
35 TOKEN:
36 0 ▶ for (my $i = 0; $i < $#nodes; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#nodes) 0 0 0
37  
38 # No more needed with SEnglishW_to_SEnglishM::Tokenization
39 # "10 th" -> "10th" (one token is better for parser and transfer)
40 #if ( $forms[ $i + 1 ] =~ /^(st|nd|rd|th)$/ && $forms[$i] =~ /^\d+$/ ) {
41 # ##warn "merging $forms[$i]th\n";
42 # $nodes[$i]->set_form($forms[$i] . 'th' );
43 # $nodes[$i]->set_attr( 'gloss', 'merged' );
44 # $nodes[ $i + 1 ]->remove();
45 # $i += 1;
46 # next TOKEN;
47 #}
48  
49 LENGTH:
50 0 foreach my $length ( reverse( 1 .. $max_length ) ) {
51 0 my $string = join ' ', @forms[ $i .. $i + $length ];
52 0 my $merged = $MERGE_FOR{$string};
53  
54 0 ▶ next LENGTH if !defined $merged;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $merged 0 0 0
55  
56 #warn "merging $merged\n";
57 0 $nodes[$i]->set_form($merged);
58 0 $nodes[$i]->set_attr( 'gloss', 'merged' );
59 0 $nodes[$i]->set_no_space_after( $nodes[ $i + $length ]->no_space_after );
60  
61 0 foreach my $node ( @nodes[ $i + 1 .. $i + $length ] ) {
62 0 $node->remove();
63 }
64 0 $i += $length;
65 }
66 }
67 0 return 1;
68 }
69  
70 1 1;
71  
72 __END__
« Block/W2A/EN/FixTagsAfterParse.pm ↑ Summary Block/W2A/EN/NormalizeForms.pm »