| 1 | package Lingua::LA::Stemmer; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | our $VERSION = '0.01'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | our %que_words = map {$_=>1} qw( atque quoque neque itaque absque apsque abusque | |||||||||
| 7 | adaeque adusque denique deque susque oblique peraeque plenisque | ||||||||||
| 8 | quandoque quisque quaeque cuiusque cuique quemque quamque quaque | ||||||||||
| 9 | quique quorumque quarumque quibusque quosque quasque quotusquisque | ||||||||||
| 10 | quousque ubique undique usque uterque utique utroque utribique torque | ||||||||||
| 11 | coque concoque contorque detorque decoque excoque extorque obtorque | ||||||||||
| 12 | optorque retorque recoque attorque incoque intorque praetorque ); | ||||||||||
| 13 | |||||||||||
| 14 | 1 | our @noun_adj_suffix = qw( ibus ius ae am as em es ia is nt os ud um | |||||||||
| 15 | us a e i o u ); | ||||||||||
| 16 | |||||||||||
| 17 | 1 | our @verb_suffix = qw( iuntur beris erunt untur iunt mini ntur stis | |||||||||
| 18 | bor ero mur mus ris sti tis tur unt bo ns nt ri m r s t ); | ||||||||||
| 19 | |||||||||||
| 20 | 1 | our %verb_suffix_transform_dict = qw( iuntur i erunt i untur i iunt i | |||||||||
| 21 | unt i beris bi bor bi bo bi ero eri ); | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub stem { | ||||||||
|
Subroutine
stem: called CC=15 SCAR=31.7
Pod
undocumented
| |||||||||||
| 24 | 0 | ▶ | my @words = ref($_[0]) ? @{$_[0]} : @_ ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 1 | my @stems; | |||||||||
| 26 | my $suffix; | ||||||||||
| 27 | |||||||||||
| 28 | STEM: | ||||||||||
| 29 | 1 | foreach my $word ( @words ){ | |||||||||
| 30 | |||||||||||
| 31 | # converts jv to iu | ||||||||||
| 32 | 9 | $word =~ tr/jv/iu/; | |||||||||
| 33 | |||||||||||
| 34 | # removes '-que' | ||||||||||
| 35 | 9 | ▶ | if( $word =~ /que$/o ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | if( $que_words{$word} ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | push @stems, $word; | |||||||||
| 38 | 0 | next STEM; | |||||||||
| 39 | } | ||||||||||
| 40 | else{ | ||||||||||
| 41 | 0 | $word =~ s/que$//o; | |||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 9 | for $suffix ( @noun_adj_suffix ){ | |||||||||
| 46 | 125 | ▶ | if( $word =~ /$suffix$/ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 7 | ▶ | if(length( $word ) - length ($suffix) >= 2){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 7 | $word =~ s/$suffix$//; | |||||||||
| 49 | 7 | push @stems, $word; | |||||||||
| 50 | } | ||||||||||
| 51 | else { | ||||||||||
| 52 | 0 | push @stems, $word; | |||||||||
| 53 | } | ||||||||||
| 54 | 7 | next STEM; | |||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 2 | for $suffix ( @verb_suffix ){ | |||||||||
| 59 | 50 | ▶ | if( $word =~ /$suffix$/ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | ▶ | if( $word =~ /$suffix$/ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 1 | foreach my $term (keys %verb_suffix_transform_dict){ | |||||||||
| 62 | 9 | ▶ | if( $word =~ s/$term$/$verb_suffix_transform_dict{$term}/ ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | last; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | 1 | ▶ | if(length( $word ) - length ($suffix) >= 2){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 1 | $word =~ s/$suffix$//; | |||||||||
| 68 | 1 | push @stems, $word; | |||||||||
| 69 | } | ||||||||||
| 70 | else { | ||||||||||
| 71 | 0 | push @stems, $word; | |||||||||
| 72 | } | ||||||||||
| 73 | 1 | next STEM; | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | } | ||||||||||
| 77 | 1 | push @stems, $word; | |||||||||
| 78 | } | ||||||||||
| 79 | 1 | ▶ | wantarray ? @stems : \@stems; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 1 | 1; | |||||||||
| 83 | __END__ | ||||||||||