User:Jimregan/Misc
Jump to navigation
Jump to search
stem-splitter.pl
#!/usr/bin/perl
use warnings;
use strict;
use String::Diff qw/diff_fully/;
while(<>)
{
s/,\W+$//;
my $endings = $_;
my @a = split/, /;
my $stem = find_stem(@a);
$endings =~ s/$stem//g;
print $stem;
if ($endings =~ /owie/) {print ":n.m1:";}
else {print ":n.??:";}
print join(',', sort split/, /, $endings), "\n";
}
sub find_stem()
{
my @in = @_;
my ($r, $l, $cur, $last);
my $i=0;
while ($i<($#in))
{
($r, $l) = diff_fully($in[$i], $in[$i+1]);
$cur = $r->[0]->[1];
$last = $cur if (!$last);
if ($cur ne $last) {
($r, $l) = diff_fully($last, $cur);
$last = $r->[0]->[1];
}
$i++;
}
return $last;
}
hotel, hoteli, hotelowi, hotelem, hotelu, hotelach, hotelami, hotelom, hotelów, hotele, pies, psa, psie, psem, psu, psy, psach, psami, psom, psów, stół, stole, stołowi, stołem, stołu, stoły, stołach, stołami, stołom, stołów, gołąb, gołębie, gołębiach, gołębi, gołębiami, gołębiom, gołębia, gołębiem, gołębiowi, gołębiu, kot, kota, kocie, kotowi, kotem, kotach, kotami, kotom, kotów, koty, dzień, dnia, dniowi, dniem, dniu, dniach, dniami, dni, dniom, dnie, tydzień, tygodni, tygodnia, tygodniach, tygodniami, tygodnie, tygodniem, tygodniom, tygodniowi, tygodniu, miesiąc, miesiąca, miesiącowi, miesiącem, miesiącu, miesiącach, miesiącami, miesiącom, miesięcy, miesiące, student, studenta, studencie, studentowi, studentem, studenci, studentach, studentami, studentom, studenty, studentów, brat, braci, braty, bracia, braciach, bracie, braciom, braćmi, brata, bratem, bratu,