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