grammar function

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;
}
 
M

Matt Garrish

Ken Sington said:
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>);
[snip]
$returnIt = $word =~ s/ey$/ies/; # monkey -> monkies
^^^^^^^

There's one good reason not to venture into computerized grammar checking.
Take a look at how bad most spell checkers are and you'll find ample reason
not to follow this road to madness... : )

Matt
 
K

Ken Sington

Matt said:
^^^^^^^

There's one good reason not to venture into computerized grammar checking.
Take a look at how bad most spell checkers are and you'll find ample reason
not to follow this road to madness... : )

Matt
too late, I'm already a lunatic.
I went nuts years ago.
 
C

Christopher Nehren

I'm hoping other's can add ideas to it.
^^^^^^^
Do you perhaps mean "others"? Writing a grammar checker is a laudible
goal, but you only add to the mess of bad grammar checkers (I offer the
grammar check in MS Word as a prime example) if you write one without
full mastery of the target language(s).

/me adds yet another item to the list of statements made by others
wherein they make statements claiming to be authoritative sources of
information on particular languages and coincidentally make grammar
mistakes in those same declarations of authority (this actually happens
a *lot* more often than one would think).
$returnIt = $word . "es"; # box -> boxes

I disagree with this, for two separate but related reasons. First,
there's "boxen", which could be the ancient dual number (i.e., there
used to be three separate noun numbers in English: singular, dual, and
plural). Second, why box -> boxes but ox -> oxen? One of the reasons
that English is so difficult is because of its inconsistencies.

Best Regards,
Christopher Nehren
 
K

Ken Sington

Christopher said:
On 2004-12-08, Ken Sington scribbled these
curious markings:

Do you perhaps mean "others"? Writing a grammar checker is a laudible
*smack* arrrg!
I was just smacking some else about that. He put up a sign in the toilet "wash your hand's"
goal, but you only add to the mess of bad grammar checkers (I offer the
grammar check in MS Word as a prime example) if you write one without
full mastery of the target language(s).
I was hoping for something simple. a simple checker where you'd feed a number to it.

But I soon realized I'd have a very long list of rules.

so everyone's (is...) telling me I should give up I guess.
plural). Second, why box -> boxes but ox -> oxen? One of the reasons
that English is so difficult is because of its inconsistencies.
And I'm using American English where colour became color and centre became center.
Or worst, "culla" "centa".
 
P

Paul Lalli

Ken Sington said:
chair remains chair if there are one or zero.

You have "zero chair"? "zero desk"? That doesn't especially sound like
correct (American) English to me. Singular is used for one item.
Plural is used for not-one items.

Paul Lalli
 
U

Uri Guttman

KS> And I'm using American English where colour became color and
KS> centre became center.

KS> Or worst, "culla" "centa".

s/t/e/ since we are being grammar pedants in this thread. :)

uri
 
A

Ala Qumsieh

Ken said:
I've been working on a simple one word grammar checker.

Simple is a good description. Unfortunately, the problem you are seeking
to solve is a hard one, and has been a topic of AI research for years.
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'

Alas, life is not that easy. Perhaps with other languages this might
work, but English, although has a relatively simple grammar, has way too
many special cases.
# 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

Why do you need this test, if I may ask?
} elsif ($word =~ m/es$/){
$returnIt = $word ."es"; # james -> jameses
} elsif ($word =~ m/x$/){
$returnIt = $word . "es"; # box -> boxes

What about "index"? -> indices.
} elsif ($word =~ m/ey$/){
$returnIt = $word =~ s/ey$/ies/; # monkey -> monkies

What about "key"? -> keys.
} elsif ($word =~ m/oy$/){
$returnIt = $word . "s"; # boy -> boys
} elsif ($word =~ m/^(woman|man)$/){
$word =~ s/an$/en/; # (wo)man -> (wo)men

It's "cleaner" not to use capturing parentheses, if you don't need them:

$word =~ /^(?:wo)?man$/

Speaking of which, you don't handle the word "parenthesis" correctly.
$returnIt = $word;
} elsif ($word !~ m/s$/){
$returnIt = $word ."s"; # word -> words
}

What about "class"? -> classes.

Other inconsistencies off the top of my head:

datum -> data.
information -> information.
news -> news.
stigma -> stigmata.

There are many, many more of course. Hypothetically, you can handle
everything with a sufficient number of elsifs, but I don't see the point
in this.

Good luck :)

--Ala
 
B

Ben Morrow

Quoth Uri Guttman said:
KS> And I'm using American English where colour became color and
KS> centre became center.

KS> Or worst, "culla" "centa".

s/t/e/ since we are being grammar pedants in this thread. :)

s/ea/\x{0294}\x{0259}/ while we're about it (to be applied after Uri's).

:)

Ben
 
M

Matt Garrish

? the Platypus {aka David Formosa} said:
I have three chairs.
I have two chairs.
I have I chair;
I have no chairs;


Looks like it.

Looks are always deceiving:

You have no senses at all
You have no sense at all

Matt
 
K

Kåre Olai Lindbach

Looks are always deceiving:

You have no senses at all
You have no sense at all

Strange things also happens when one also deals with non-whole
numbers:

I now have 2 1/2 (two-and-a-half) chair, after you partyed here last
night.
I now have 2.5 chairs, after you partyed here last night.

(At least so it goes in Norwegian :)
 
B

Bart Lateur

Ala said:
Ken Sington wrote:

What about "key"? -> keys.

Webster (USA) says the plural of "monkey" is "monkeys", which makes more
sense to me anyway. Ditto with the other online dict.

<http://www.webster.com/cgi-bin/dictionary?va=monkey>
<http://dictionary.reference.com/search?q=monkey>


What dialect is "monkies" supposed to be, anyway?

"Freesearch", a UK based site, mentions "monkeys" too, though not so
explicitely: "Monkeys are primates"

<http://www.freesearch.co.uk/dictionary/monkey+(animal)>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top