Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there any module to check files(or strings) for proper grammer format(of the english language, of course)?

Replies are listed 'Best First'.
Re: English/Language/Grammar
by Tiefling (Monk) on Jun 05, 2001 at 13:48 UTC
    The problem with grammar checkers in general is that they can't distinguish between:

    Atlantis flies like a 'plane.
    Time flies like an arrow.
    Fruit flies like a banana.

    (Apologies to gumpu, whose answer I hadn't seen when I wrote this - this is clearly a good example :-)

    And indeed, code to distinguish between generalisations of those three examples alone would be more trouble to code than it's worth (unles you're being paid to research natural language, in which case you're lucky). There are modules to conjugate English verbs and decline English nouns, but this will only help your program to write simple grammatical sentences, such as Colourless green ideas sleep furiously. :-)

    M$'s grammar checkers commit further errors by producing entirely spurious queries, such as 'passive voice' (one of the few parts of speech their system usually spots), which it regards as wrong! The same system also routinely argues 'subject-verb agreement' errors where none exist, and (if the right 'feature' is enabled) can prevent you using any gender-specific language.

    Tiefling (and remember - verbing weirds language)

      It a very good example :) I 'borrowed' it from a really wonderful book called "The Language Instinct" by Steven Pinkerton. Well worth a read! It explains in vividly how wonderful flexible natural languages are, and how complex the machinery (the brain) is to process it.

      Have Fun

        Curious - I got the 'Time flies...' and 'Fruit flies...' elements from Bill Bryson's Mother Tongue. The bit about Atlantis was my idea, as I was struck by the thought that 'Time flies like an arrow' is not actually a canonical use of the verb 'to fly'.

        Tiefling (who flies like a brick)
Re: English/Language/Grammer
by myocom (Deacon) on Jun 05, 2001 at 01:51 UTC

    In a nutshell, no. Parsing natural language is a herculean effort that researchers have been working on for years (do a Google search on "natural language" and it reports 496,000 hits).

    Word processors have so-called grammar checkers now, but they're (way) far from perfect.

Re: English/Language/Grammer
by chipmunk (Parson) on Jun 05, 2001 at 08:24 UTC
    You might be interested in the Lingua::LinkParser module. I don't know if it can be used to determine whether a sentence is grammatically correct, but it's a fascinating module nonetheless.

    Dan Brian had an article on the module in issue #19 of http://www.tpj.com. (Past articles are not back up on the TPJ website yet.)

Re: English/Language/Grammer
by Beatnik (Parson) on Jun 05, 2001 at 01:55 UTC
    Sidenote: grammer wouldn't be listed, since it's with 2 a's :)

    grammar

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: English/Language/Grammer
by gumpu (Friar) on Jun 05, 2001 at 10:42 UTC

    The problem is (if I remember correctly) that if you want to check the grammar of a sentence you have to understand the sentence. The meaning and how a word is used determines if the chosen grammer is correct. Computers are rather bad at understanding natural language because it is very ambigious.

    It's easy to come up with sentences that can put even humans on the wrong path, for instance: "Time flies like an arrow and fruit flies like a banana.". Here flies can be either a noun or a verb.

    Have Fun

Re: English/Language/Grammer
by Beatnik (Parson) on Jun 06, 2001 at 02:25 UTC
Re: English/Language/Grammer
by mattr (Curate) on Jun 05, 2001 at 12:56 UTC
    Basically no, although there are modules to help you stem words and do little bits of grammar. What do you need this for?

    If a dictionary lookup is what you need, that is in the realm of reality.

Re: English/Language/Grammer
by sierrathedog04 (Hermit) on Jun 05, 2001 at 06:12 UTC
    You mean like Kelsey Grammer the actor? Does he do Perl programming too?