K
Ken Sington
I've been working on a simple one word grammar checker.
I'm hoping other's can add ideas to it.
you access the function like this:
my $word = grammarAdjust("command", "word", <quantity>);
so table becomes tables if there are more than one.
chair remains chair if there are one or zero.
if there are more than one james, we get jameses. and if something belongs to them, it's
jameses'
etc...
# grammarAdjust #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# takes single word and determines proper word grammar
# to use:
# grammarAdjust("command", "word", <quantity>);
# commands:
# ("plural", "word", <qty>)
# ("possessive", "word", <qty>)
sub grammarAdjust {
my ($command, $word, $qty) = @_;
my ($returnIt, $s)=();
if ($command eq "plural"){
if ($qty > 1){
if (1 == 10){
# 1 is not 10 of course
} elsif ($word =~ m/es$/){
$returnIt = $word ."es"; # james -> jameses
} elsif ($word =~ m/x$/){
$returnIt = $word . "es"; # box -> boxes
} elsif ($word =~ m/ey$/){
$returnIt = $word =~ s/ey$/ies/; # monkey -> monkies
} elsif ($word =~ m/oy$/){
$returnIt = $word . "s"; # boy -> boys
} elsif ($word =~ m/^(woman|man)$/){
$word =~ s/an$/en/; # (wo)man -> (wo)men
$returnIt = $word;
} elsif ($word !~ m/s$/){
$returnIt = $word ."s"; # word -> words
}
} else {
$returnIt = $word;
}
}
elsif ($command eq "possessive") {
if ($qty > 1){
$s = $word =~ m/s$/ ? "\'" : "s\'" unless ($word =~ m/es$/);
$word =~ s/es$/eses\'/ if ($word =~ m/es$/);
} else {
$s = $word =~ m/s$/ ? "\'" : "\'s" unless ($word =~ m/es$/);
$word =~ s/es$/es\'s/ if ($word =~ m/es$/);
}
$returnIt = "$word$s";
}
return $returnIt;
}
I'm hoping other's can add ideas to it.
you access the function like this:
my $word = grammarAdjust("command", "word", <quantity>);
so table becomes tables if there are more than one.
chair remains chair if there are one or zero.
if there are more than one james, we get jameses. and if something belongs to them, it's
jameses'
etc...
# grammarAdjust #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# takes single word and determines proper word grammar
# to use:
# grammarAdjust("command", "word", <quantity>);
# commands:
# ("plural", "word", <qty>)
# ("possessive", "word", <qty>)
sub grammarAdjust {
my ($command, $word, $qty) = @_;
my ($returnIt, $s)=();
if ($command eq "plural"){
if ($qty > 1){
if (1 == 10){
# 1 is not 10 of course
} elsif ($word =~ m/es$/){
$returnIt = $word ."es"; # james -> jameses
} elsif ($word =~ m/x$/){
$returnIt = $word . "es"; # box -> boxes
} elsif ($word =~ m/ey$/){
$returnIt = $word =~ s/ey$/ies/; # monkey -> monkies
} elsif ($word =~ m/oy$/){
$returnIt = $word . "s"; # boy -> boys
} elsif ($word =~ m/^(woman|man)$/){
$word =~ s/an$/en/; # (wo)man -> (wo)men
$returnIt = $word;
} elsif ($word !~ m/s$/){
$returnIt = $word ."s"; # word -> words
}
} else {
$returnIt = $word;
}
}
elsif ($command eq "possessive") {
if ($qty > 1){
$s = $word =~ m/s$/ ? "\'" : "s\'" unless ($word =~ m/es$/);
$word =~ s/es$/eses\'/ if ($word =~ m/es$/);
} else {
$s = $word =~ m/s$/ ? "\'" : "\'s" unless ($word =~ m/es$/);
$word =~ s/es$/es\'s/ if ($word =~ m/es$/);
}
$returnIt = "$word$s";
}
return $returnIt;
}