| 1 | package Hailo::Role::Tokenizer; | ||||||||||
| 2 | 30 | our $AUTHORITY = 'cpan:AVAR'; | |||||||||
| 3 | 30 | $Hailo::Role::Tokenizer::VERSION = '0.73'; | |||||||||
| 4 | 30 | ▶ | use v5.28.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 30 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 30 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | has spacing => ( | ||||||||||
| 9 | isa => 'HashRef[Int]', | ||||||||||
| 10 | is => 'rw', | ||||||||||
| 11 | default => sub { { | ||||||||||
| 12 | 260 | ▶ | normal => 0, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 13 | prefix => 1, | ||||||||||
| 14 | postfix => 2, | ||||||||||
| 15 | infix => 3, | ||||||||||
| 16 | } }, | ||||||||||
| 17 | 30 | ); | |||||||||
| 18 | |||||||||||
| 19 | sub BUILD { | ||||||||||
| 20 | 260 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | # This performance hack is here because calling | ||||||||||
| 23 | # $self->spacing->{...} was significant part Tokenizer execution | ||||||||||
| 24 | # time (~20s / ~1200s) since we're doing one method call and a | ||||||||||
| 25 | # hash dereference | ||||||||||
| 26 | |||||||||||
| 27 | 260 | my $spacing = $self->spacing; | |||||||||
| 28 | 260 | ▶ | while (my ($k, $v) = each %$spacing) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1040 | $self->{"_spacing_$k"} = $v; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 260 | return; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 30 | requires 'make_tokens'; | |||||||||
| 36 | 30 | requires 'make_output'; | |||||||||
| 37 | |||||||||||
| 38 | 30 | 1; | |||||||||
| 39 | |||||||||||
| 40 | =encoding utf8 | ||||||||||
| 41 | |||||||||||
| 42 | =head1 NAME | ||||||||||
| 43 | |||||||||||
| 44 | Hailo::Role::Tokenizer - A role representing a L<Hailo|Hailo> tokenizer | ||||||||||
| 45 | |||||||||||
| 46 | =head1 METHODS | ||||||||||
| 47 | |||||||||||
| 48 | =head2 C<new> | ||||||||||
| 49 | |||||||||||
| 50 | This is the constructor. It takes no arguments. | ||||||||||
| 51 | |||||||||||
| 52 | =head2 C<make_tokens> | ||||||||||
| 53 | |||||||||||
| 54 | Takes a line of input and returns an array reference of tokens. A token is | ||||||||||
| 55 | an array reference containing two elements: a I<spacing attribute> and the | ||||||||||
| 56 | I<token text>. The spacing attribute is an integer which will be stored along | ||||||||||
| 57 | with the token text in the database. The following values are currently being | ||||||||||
| 58 | used: | ||||||||||
| 59 | |||||||||||
| 60 | =over | ||||||||||
| 61 | |||||||||||
| 62 | =item C<0> - normal token | ||||||||||
| 63 | |||||||||||
| 64 | =item C<1> - prefix token (no whitespace follows it) | ||||||||||
| 65 | |||||||||||
| 66 | =item C<2> - postfix token (no whitespace precedes it) | ||||||||||
| 67 | |||||||||||
| 68 | =item C<3> - infix token (no whitespace follows or precedes it) | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =head2 C<make_output> | ||||||||||
| 73 | |||||||||||
| 74 | Takes an array reference of tokens and returns a line of output. A token is | ||||||||||
| 75 | an array reference as described in L<C<make_tokens>|/make_tokens>. The tokens | ||||||||||
| 76 | will be joined together into a sentence according to the whitespace | ||||||||||
| 77 | attributes associated with the tokens, as well as any formatting provided by | ||||||||||
| 78 | the tokenizer implementation. | ||||||||||
| 79 | |||||||||||
| 80 | =head1 AUTHORS | ||||||||||
| 81 | |||||||||||
| 82 | Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com | ||||||||||
| 83 | |||||||||||
| 84 | E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||||||||||
| 85 | |||||||||||
| 86 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 87 | |||||||||||
| 88 | Copyright 2010 Hinrik E<Ouml>rn SigurE<eth>sson and | ||||||||||
| 89 | E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> | ||||||||||
| 90 | |||||||||||
| 91 | This program is free software, you can redistribute it and/or modify | ||||||||||
| 92 | it under the same terms as Perl itself. | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||