Block/W2A/EN/FixTokenization.pm

filter: Statementstmt 35.7% 10 / 28 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 40.0% 14 / 35 CC 5 SCAR 29.5
CC
5
Cov
33%
process_atree
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 19.1
« Block/W2A/EN/FixTags.pm ↑ Summary Block/W2A/EN/NormalizeForms.pm »
1 package Treex::Block::W2A::EN::FixTokenization;
2 BEGIN {
3 1 ▶ $Treex::Block::W2A::EN::FixTokenization::VERSION = '0.06903_1';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
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 'Mrs .' => 'Mrs.',
15 'Mr .' => 'Mr.',
16 'Ms .' => 'Ms.',
17 'Dr .' => 'Dr.',
18 'km / h' => 'km/h',
19 'm / s' => 'm/s',
20 );
21  
22 #TODO (MP): rewrite this block
23  
24 sub process_atree {
25 0 ▶ my ( $self, $atree ) = @_;
Subroutine process_atree: not called CC=5 SCAR=34.0
Pod documented
26  
27 0 my @nodes = $atree->get_children();
28 0 my @forms = map { $_->form } @nodes;
29 0 my $max_length = 3;
30 0 push @forms, map {'dummy'} ( 1 .. $max_length );
31  
32 TOKEN:
33 0 foreach my $i ( 0 .. $#nodes - 1 ) {
34  
35 # No more needed with SEnglishW_to_SEnglishM::Tokenization
36 # "10 th" -> "10th" (one token is better for parser and transfer)
37 #if ( $forms[ $i + 1 ] =~ /^(st|nd|rd|th)$/ && $forms[$i] =~ /^\d+$/ ) {
38 # ##warn "merging $forms[$i]th\n";
39 # $nodes[$i]->set_form($forms[$i] . 'th' );
40 # $nodes[$i]->set_attr( 'gloss', 'merged' );
41 # $nodes[ $i + 1 ]->remove();
42 # $i += 1;
43 # next TOKEN;
44 #}
45  
46 LENGTH:
47 0 foreach my $length ( reverse( 1 .. $max_length ) ) {
48 0 my $string = join ' ', @forms[ $i .. $i + $length ];
49 0 my $merged = $MERGE_FOR{$string};
50  
51 0 ▶ next LENGTH if !defined $merged;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $merged 0 0 0
52  
53 #warn "merging $merged\n";
54 0 $nodes[$i]->set_form($merged);
55 0 $nodes[$i]->set_attr( 'gloss', 'merged' );
56 0 foreach my $node ( @nodes[ $i + 1 .. $i + $length ] ) {
57 0 $node->remove();
58 }
59 0 $i += $length;
60 }
61 }
62 0 return 1;
63 }
64  
65 1 1;
66  
67 __END__
68  
69 =encoding utf-8
70  
71 =head1 NAME
72  
73 Treex::Block::W2A::EN::FixTokenization - fix some issues in output of tokenizer
74  
75 =head1 VERSION
76  
77 version 0.06903_1
78  
79 =head1 DESCRIPTION
80  
81 Some abbreviations (with periods) are merged into one token.
82 For example I<"e. g."> is in Penn Treebank one token (with tag FW).
83 Using only L<SEnglishW_to_SEnglishM::Penn_style_tokenization>
84 we get four tokens: I<e . g .> which may be distributed by the parser
85 into different clauses. And this is hard to fix afterwards.
86  
87 =head1 OVERRIDEN METHODS
88  
89 =head2 from C<Treex::Core::Block>
90  
91 =over 4
92  
93 =item process_atree
94  
95 =back
96  
97 =head1 AUTHOR
98  
99 Martin Popel <popel@ufal.mff.cuni.cz>
100  
101 =head1 COPYRIGHT AND LICENSE
102  
103 Copyright © 2009 - 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
104  
105 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« Block/W2A/EN/FixTags.pm ↑ Summary Block/W2A/EN/NormalizeForms.pm »