grammar function

Discussion in 'Perl Misc' started by Ken Sington, Dec 8, 2004.

  1. Ken Sington

    Ken Sington Guest

    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;
    }
    Ken Sington, Dec 8, 2004
    #1
    1. Advertising

  2. Ken Sington <ken_sington@nospam_abcdefg.com> wrote in
    news::

    > 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
    A. Sinan Unur, Dec 8, 2004
    #2
    1. Advertising

  3. Ken Sington

    Matt Garrish Guest

    "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
    news:...
    > 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
    Matt Garrish, Dec 8, 2004
    #3
  4. Ken Sington

    Ken Sington Guest

    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.
    Ken Sington, Dec 8, 2004
    #4
  5. Ken Sington

    Ken Sington Guest

    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).
    Ken Sington, Dec 8, 2004
    #5
  6. Ken Sington

    Matt Garrish Guest

    "A. Sinan Unur" <> wrote in message
    news:Xns95B8DA527694Dasu1cornelledu@132.236.56.8...
    > Ken Sington <ken_sington@nospam_abcdefg.com> wrote in
    > news::
    >
    >> 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
    Matt Garrish, Dec 8, 2004
    #6
  7. 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.
    Christopher Nehren, Dec 8, 2004
    #7
  8. Ken Sington

    Ken Sington Guest

    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".
    Ken Sington, Dec 8, 2004
    #8
  9. Ken Sington

    Paul Lalli Guest

    Re: grammar function [OT - English Grammar]

    "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
    news:...
    >
    > 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
    Paul Lalli, Dec 8, 2004
    #9
  10. Ken Sington

    Uri Guttman Guest

    >>>>> "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 ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Dec 8, 2004
    #10
  11. Ken Sington

    Ala Qumsieh Guest

    Ken Sington wrote:

    > 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
    Ala Qumsieh, Dec 8, 2004
    #11
  12. Ken Sington

    Ben Morrow Guest

    Quoth Uri Guttman <>:
    > >>>>> "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. :)


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

    :)

    Ben

    --
    perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
    qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
    1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
    2047502190/' #
    Ben Morrow, Dec 9, 2004
    #12
  13. Ken Sington

    Matt Garrish Guest

    Re: grammar function [OT - English Grammar]

    "? the Platypus {aka David Formosa}" <> wrote in message
    news:...
    > "Paul Lalli" <> writes:
    >
    >> "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
    >> news:...
    >> >
    >> > 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.

    >
    > I have three chairs.
    > I have two chairs.
    > I have I chair;
    > I have no chairs;
    >
    >> Singular is used for one item.
    >> Plural is used for not-one items.

    >
    > Looks like it.
    >


    Looks are always deceiving:

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

    Matt
    Matt Garrish, Dec 11, 2004
    #13
  14. Re: grammar function [OT - English Grammar]

    On Sat, 11 Dec 2004 13:23:11 -0500, "Matt Garrish"
    <> wrote:

    >"? the Platypus {aka David Formosa}" <> wrote in message
    >news:...
    >> "Paul Lalli" <> writes:
    >>
    >>> "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
    >>> news:...
    >>> >
    >>> > 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.

    >>
    >> I have three chairs.
    >> I have two chairs.
    >> I have I chair;
    >> I have no chairs;
    >>
    >>> Singular is used for one item.
    >>> Plural is used for not-one items.

    >>
    >> Looks like it.

    >
    >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 :)

    --
    mvh/Regards Kåre Olai Lindbach
    (News: Remove '_delete_' and '.invalid')
    (HTML-written email from unknown will be discarded)
    Kåre Olai Lindbach, Dec 11, 2004
    #14
  15. Ken Sington

    Bart Lateur Guest

    Ala Qumsieh wrote:

    >Ken Sington wrote:


    >> } elsif ($word =~ m/ey$/){
    >> $returnIt = $word =~ s/ey$/ies/; # monkey -> monkies

    >
    >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+%28animal%29>


    --
    Bart.
    Bart Lateur, Dec 13, 2004
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhupesh Naik
    Replies:
    2
    Views:
    3,840
    Bhupesh Naik
    Aug 7, 2003
  2. exits funnel

    Java Grammar Parser?

    exits funnel, Jul 15, 2003, in forum: Java
    Replies:
    3
    Views:
    8,577
    Roedy Green
    Jul 19, 2003
  3. Iván Roca

    Java Grammar

    Iván Roca, Aug 5, 2003, in forum: Java
    Replies:
    3
    Views:
    1,904
    Larry Coon
    Aug 8, 2003
  4. Paulo Matos
    Replies:
    4
    Views:
    400
    Gilles =?UTF-8?B?Si4gU8OpZ3Vpbg==?=
    Nov 19, 2006
  5. Replies:
    3
    Views:
    456
Loading...

Share This Page