| 1 | package Plucene::Analysis::Standard::StandardTokenizer; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Plucene::Analysis::Standard::StandardTokenizer - standard tokenizer | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | # isa Plucene::Analysis::CharTokenizer | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This is the standard tokenizer. | ||||||||||
| 14 | |||||||||||
| 15 | This should be a good tokenizer for most European-language documents. | ||||||||||
| 16 | |||||||||||
| 17 | =head1 METHODS | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | use base 'Plucene::Analysis::CharTokenizer'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | # Don't blame me, blame the Plucene people! | ||||||||||
| 27 | 2 | my $alpha = qr/\p{IsAlpha}+/; | |||||||||
| 28 | 2 | my $apostrophe = qr/$alpha('$alpha)+/; | |||||||||
| 29 | 2 | my $acronym = qr/$alpha\.($alpha\.)+/; | |||||||||
| 30 | 2 | my $company = qr/$alpha(&|\@)$alpha/; | |||||||||
| 31 | 2 | my $hostname = qr/\w+(\.\w+)+/; | |||||||||
| 32 | 2 | my $email = qr/\w+\@$hostname/; | |||||||||
| 33 | 2 | my $p = qr/[_\/.,-]/; | |||||||||
| 34 | 2 | my $hasdigit = qr/\w*\d\w*/; | |||||||||
| 35 | 2 | my $num = qr/\w+$p$hasdigit|$hasdigit$p\w+ | |||||||||
| 36 | |\w+($p$hasdigit$p\w+)+ | ||||||||||
| 37 | |$hasdigit($p\w+$p$hasdigit)+ | ||||||||||
| 38 | |\w+$p$hasdigit($p\w+$p$hasdigit)+ | ||||||||||
| 39 | |$hasdigit$p\w+($p$hasdigit$p\w+)+/x; | ||||||||||
| 40 | |||||||||||
| 41 | =head2 token_re | ||||||||||
| 42 | |||||||||||
| 43 | The regular expression for tokenising. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub token_re { | ||||||||
|
Subroutine
token_re: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 0 | qr/ | |||||||||
| 49 | $apostrophe | $acronym | $company | $hostname | $email | $num | ||||||||||
| 50 | | \w+ | ||||||||||
| 51 | /x; | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | =head2 normalize | ||||||||||
| 55 | |||||||||||
| 56 | Remove 's and . | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 1 | ▶ | sub normalize { | ||||||||
|
Subroutine
normalize: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||
| 61 | 1 | my $class = shift; | |||||||||
| 62 | |||||||||||
| 63 | # These are in the StandardFilter in Java, but Perl is not Java. | ||||||||||
| 64 | # Thankfully. | ||||||||||
| 65 | 1 | local $_ = shift; | |||||||||
| 66 | 0 | ▶ | if (/$apostrophe/) { s/'s//; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | ▶ | if (/$company/) { s/\.//g; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 1 | return $_; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 2 | 1; | |||||||||