![]() |
grammar function
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; } |
Re: grammar function
Ken Sington <ken_sington@nospam_abcdefg.com> wrote in
news:HJmdnb8C-OEc-CvcRVn-pw@speakeasy.net: > 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. Have you looked at Lingua::EN::Inflect? http://search.cpan.org/~dconway/Lingua-EN-Inflect-1.88/ Sinan |
Re: grammar function
"Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message news:HJmdnb8C-OEc-CvcRVn-pw@speakeasy.net... > 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 |
Re: grammar function
Matt Garrish wrote:
> ^^^^^^^ > > 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. |
Re: grammar function
A. Sinan Unur wrote:
> Have you looked at Lingua::EN::Inflect? > > http://search.cpan.org/~dconway/Lingua-EN-Inflect-1.88/ > > Sinan Lingua? Mr. conway, I saw live in person. so many possibilities. I would never have guessed. I searched only "spell" and "grammar" and pretty much found nothing (... that I want). |
Re: grammar function
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:Xns95B8DA527694Dasu1cornelledu@132.236.56.8.. . > Ken Sington <ken_sington@nospam_abcdefg.com> wrote in > news:HJmdnb8C-OEc-CvcRVn-pw@speakeasy.net: > >> 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. > > Have you looked at Lingua::EN::Inflect? > > http://search.cpan.org/~dconway/Lingua-EN-Inflect-1.88/ > At least he has a sense of humour about it... : ) <doc quote> BUGS AND IRRITATIONS The endless inconsistencies of English. </doc quote> Matt |
Re: grammar function
On 2004-12-08, Ken Sington scribbled these
curious markings: > 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 -- I abhor a system designed for the "user", if that word is a coded pejorative meaning "stupid and unsophisticated". -- Ken Thompson If you ask the wrong questions, you get answers like "42" and "God". Unix is user friendly. However, it isn't idiot friendly. |
Re: grammar function
Christopher Nehren wrote:
> 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". |
Re: grammar function [OT - English Grammar]
"Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
news:HJmdnb8C-OEc-CvcRVn-pw@speakeasy.net... > > 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 |
Re: grammar function
>>>>> "KS" == Ken Sington <ken_sington@nospam_abcdefg.com> writes:
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 -- Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org |
| All times are GMT. The time now is 12:24 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.