RSLP

Run Settings
LanguageRaku
Language Version
Run Command
use RSLP; my RSLP $rslp .= new; say do for lines.map: |*.lc.comb(/\w+/) -> $word { $rslp($word) }.Bag
unit class RSLP is Routine; use RSLP::Step; method new {::?CLASS.bless} my RSLP::Step $step1 .= new: :name<plural> :suffixes["s"]; $step1.add-rule: :suffix<ns> :1min-size :add-suffix<m>; $step1.add-rule: :suffix<ões> :3min-size :add-suffix<ão>; $step1.add-rule: :suffix<ais> :1min-size :add-suffix<al> :exceptions<cais mais>; $step1.add-rule: :suffix<eis> :2min-size :add-suffix<el>; $step1.add-rule: :suffix<ois> :2min-size :add-suffix<ol>; $step1.add-rule: :suffix<is> :2min-size :add-suffix<il> :exceptions< lápis cais mais crúcis biquínis pois depois dois leis >; $step1.add-rule: :suffix<les> :3min-size :add-suffix<l>; $step1.add-rule: :suffix<res> :3min-size :add-suffix<r>; $step1.add-rule: :suffix<ães> :1min-size :add-suffix<ão> :exceptions<mães>; $step1.add-rule: :suffix<s> :2min-size :add-suffix("") :exceptions< aliás pires lápis cais mais férias fezes pêsames crúcis gás atrás moisés através convés ês país após ambas ambos messias mas menos >; has Routine @!steps = $step1, #$step2, #$step3, #$step4, #$step5, #$step6, #$step7, sub ($_) { .samemark("a") } ; method CALL-ME($word) { my $stem = $word; for @!steps -> &step { $stem = step($stem) } $stem }
unit class RSLP::Step is Routine; use RSLP::Rule; has Str $.name is required; has Int $.min-size is default(0); has Bool $.full-word-compare = False; has Junction $.suffix; has RSLP::Rule @.rules handles "push"; method new(::?CLASS:U: *%params) { %params<suffix> = any %params<suffixes>; %params<min-size> = %params<rules>.map({.min-size}).min if %params<rules>:exists and not %params<min-size>:exists; self.bless: |%params } method add-rule(::?CLASS::D: *%params) { $.push(RSLP::Rule.new: |%params); $!min-size min= %params<min-size> } multi method CALL-ME(Str:D $word) {$word ~ "" but False} multi method CALL-ME( Str:D $word where { .chars >= $!min-size and $!full-word-compare ?? $_ eq $!suffix !! .ends-with($!suffix) } ) { my $stem = $word; for @!rules -> &rule { #note $stem.perl; $stem = rule($stem); last if $stem } $stem ~ "" but True }
unit class RSLP::Rule is Routine; has Str $.suffix; has Int $.min-size is default(0); has Str $.add-suffix; has Junction $.exception = any(); method gist {"RULE: <$!suffix - $!min-size - $!add-suffix - $!exception>"} method new(::?CLASS:U: *%params) { %params<exception> = any %params<exceptions>.map: *.samemark("a") if %params<exceptions>:exists; self.bless: |%params } multi method CALL-ME(Str:D $word) {$word ~ "" but False} multi method CALL-ME( Str:D $word where { .chars >= $!min-size and .ends-with($!suffix) and not $_ eq $!exception } ) { my ($remove, $add) = $!suffix, $!add-suffix; S:ignoremark/$remove $/$add/ but True given $word }
Editor Settings
Theme
Key bindings
Full width
Lines