| 1 | package Treex::Block::W2A::TokenizeOnWhitespace; | ||||||||||
| 2 | BEGIN { | ||||||||||
| 3 | 2 | ▶ | $Treex::Block::W2A::TokenizeOnWhitespace::VERSION = '0.06903_1'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | } | ||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Treex::Core::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | extends 'Treex::Core::Block'; | |||||||||
| 8 | |||||||||||
| 9 | sub tokenize_sentence { | ||||||||||
| 10 | 0 | ▶ | my ( $self, $sentence ) = @_; | ||||||||
|
Subroutine
tokenize_sentence: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 11 | 0 | return $sentence; | |||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | sub process_zone { | ||||||||||
| 15 | 0 | ▶ | my ( $self, $zone ) = @_; | ||||||||
|
Subroutine
process_zone: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | # create a-tree | ||||||||||
| 18 | 0 | my $a_root = $zone->create_atree(); | |||||||||
| 19 | |||||||||||
| 20 | # get the source sentence and tokenize | ||||||||||
| 21 | 0 | my $sentence = $zone->sentence; | |||||||||
| 22 | 0 | $sentence =~ s/^\s+//; | |||||||||
| 23 | 0 | ▶ | log_fatal("No sentence to tokenize!") if !defined $sentence; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | my @tokens = split( /\s/, $self->tokenize_sentence($sentence) ); | |||||||||
| 25 | |||||||||||
| 26 | 0 | foreach my $i ( ( 0 .. $#tokens ) ) { | |||||||||
| 27 | 0 | my $token = $tokens[$i]; | |||||||||
| 28 | |||||||||||
| 29 | # delete the token from the begining of the sentence | ||||||||||
| 30 | 0 | $sentence =~ s/^\Q$token\E//; | |||||||||
| 31 | |||||||||||
| 32 | # if there are no spaces left, the parameter no_space_after will be set to 1 | ||||||||||
| 33 | 0 | ▶ | my $no_space_after = $sentence =~ /^\s/ ? 0 : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | # delete this spaces | ||||||||||
| 36 | 0 | $sentence =~ s/^\s+//; | |||||||||
| 37 | |||||||||||
| 38 | # create new a-node | ||||||||||
| 39 | 0 | $a_root->create_child( | |||||||||
| 40 | form => $token, | ||||||||||
| 41 | no_space_after => $no_space_after, | ||||||||||
| 42 | ord => $i + 1, | ||||||||||
| 43 | ); | ||||||||||
| 44 | } | ||||||||||
| 45 | 0 | return 1; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | 1; | |||||||||
| 49 | |||||||||||
| 50 | __END__ | ||||||||||
| 51 | |||||||||||
| 52 | =encoding utf-8 | ||||||||||
| 53 | |||||||||||
| 54 | =head1 NAME | ||||||||||
| 55 | |||||||||||
| 56 | Treex::Block::W2A::TokenizeOnWhitespace - Base tokenizer, splits on whitespaces, fills no_space_after | ||||||||||
| 57 | |||||||||||
| 58 | =head1 VERSION | ||||||||||
| 59 | |||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||
| 61 | |||||||||||
| 62 | Each sentence is split into a sequence of tokens. | ||||||||||
| 63 | Flat a-tree is built and attributes C<no_space_after> are filled. | ||||||||||
| 64 | This class tokenizes only on whitespaces, | ||||||||||
| 65 | but it can be used as an ancestor for more apropriate tokenization | ||||||||||
| 66 | by overriding the method C<tokenize_sentence>. | ||||||||||
| 67 | |||||||||||
| 68 | =head1 METHODS | ||||||||||
| 69 | |||||||||||
| 70 | =over 4 | ||||||||||
| 71 | |||||||||||
| 72 | =item tokenize_sentence() | ||||||||||
| 73 | |||||||||||
| 74 | this method can be overridden in more advanced tokenizers | ||||||||||
| 75 | |||||||||||
| 76 | =item process_zone() | ||||||||||
| 77 | |||||||||||
| 78 | this method does all work of this tokenizer | ||||||||||
| 79 | |||||||||||
| 80 | =back | ||||||||||
| 81 | |||||||||||
| 82 | =head1 AUTHOR | ||||||||||
| 83 | |||||||||||
| 84 | David Mareček <marecek@ufal.mff.cuni.cz> | ||||||||||
| 85 | |||||||||||
| 86 | Martin Popel <popel@ufal.mff.cuni.cz> | ||||||||||
| 87 | |||||||||||
| 88 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 89 | |||||||||||
| 90 | Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague | ||||||||||
| 91 | |||||||||||
| 92 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||