| 1 | package Lingua::Stem::Patch::IO; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use v5.8.1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use parent 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | our $VERSION = '0.05'; | |||||||||
| 10 | 4 | our @EXPORT_OK = qw( stem stem_io stem_aggressive stem_io_aggressive ); | |||||||||
| 11 | |||||||||||
| 12 | 4 | *stem_io = \&stem; | |||||||||
| 13 | 4 | *stem_io_aggressive = \&stem_aggressive; | |||||||||
| 14 | |||||||||||
| 15 | my %protect = ( | ||||||||||
| 16 | 4 | root => { map { $_ => 1 } qw( | |||||||||
| 17 | la li me ni on vi | ||||||||||
| 18 | ) }, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | sub stem { | ||||||||||
| 22 | 117 | ▶ | my $word = lc shift; | ||||||||
|
Subroutine
stem: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | 117 | for ($word) { | |||||||||
| 25 | # standalone roots | ||||||||||
| 26 | 117 | ▶ | last if $protect{root}{$word}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | # nouns: -on -i -in → -o | ||||||||||
| 29 | 103 | ▶ | last if s{ (?: on | in? ) $}{o}x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | # remove -u from pronouns: elu ilu olu onu | ||||||||||
| 32 | 97 | ▶ | last if s{ (?<= ^ [eio] l | on ) u $}{}x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | # pariciple adjectives: -inta -anta -onta -ita -ata -ota → -ar | ||||||||||
| 35 | 89 | ▶ | last if s{ (?: [aio] n? t ) a $}{ar}x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | # verbs: -ir -or -is -as -os -us -ez → -ar | ||||||||||
| 38 | 77 | s{ (?: [io] r | [aiou] s | ez ) $}{ar}x; | |||||||||
| 39 | |||||||||||
| 40 | # remove -ab- from verbs | ||||||||||
| 41 | 77 | s{ ab (?= ar $ ) }{}x; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 117 | return $word; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub stem_aggressive { | ||||||||||
| 48 | 58 | ▶ | my $word = stem(shift); | ||||||||
|
Subroutine
stem_aggressive: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | 58 | for ($word) { | |||||||||
| 51 | # standalone roots | ||||||||||
| 52 | 58 | ▶ | last if $protect{root}{$word}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | # remove final suffix | ||||||||||
| 55 | 50 | s{ (?: [aeo] | ar ) $}{}x; | |||||||||
| 56 | |||||||||||
| 57 | # remove -u from pronouns: elu ilu olu onu | ||||||||||
| 58 | 50 | ▶ | last if s{ (?<= ^ [eio] l | on ) u $}{}x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 58 | return $word; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 4 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||