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

Oh wise monks, some advice please... We've a database of questions; currently they address the user in the 2nd person. ("Do you ...", "If you have...", "Are you...", etc.) A new requirement is that the questions be properly tweaked if the user is calling about their child. ("Does the child...", "If the child has...", "Is the child...", etc.). Handling the object of the sentence via a variable is the easy part, but adjusting the verb is proving more difficult. Damian Conway's written a wonderful module called Lingua::EN::Inflect; it does singular/plural changes, but doesn't seem to offer the switch from 2nd person to 3rd. Do you know of any modules/snippets which can do that?

Replies are listed 'Best First'.
Re: verb conjugation
by TGI (Parson) on Oct 25, 2000 at 05:23 UTC
    Try storing your third person verbs in a hash, keyed to their second person version.
    %verbs = { are => 'is', do => 'does', have => 'has', }
    If the verb doesn't change then leave it out. You should be able to do a simple replacement of the changed verbs (assuming that you don't change objects in the sentence). I doubt there are many verbs that change based on their object, especially since you're just working from a db of questions.
      As an extension to the parent post, why do you actually store the second person in plain text?
      If you have multiple hashes/arrays for each conjugation, you can easily splice the correct one in, without translation/possible translation errors.
      All that's then needed is the initial declaration about which conjugation you require, and voila, the rest should run sweetly.
      Unless, of course that's outside the scope of what you're able to do with the database to to commercial constraints.

      Just a thought

      Malk
      *I lost my .sig. Do you have a spare?*
        The questions are in plain text because it's (very) legacy data. At this moment my developers are currently leaning toward making the maintainers of questions use a tailor-made markup; as the dba, I was hoping to ride to the rescue yelling "but wait - there's no need to go to all that hassle since Perl can seamlessly translate the question on the fly!". Lingua::EN::Inflect got me part of the way there - an already existing markup syntax & decoder would carry a lot of weight - but without a 2nd=>3rd person verb translation tool I'm stuck. Sounds like a fun module to write, but I'm one of the last guys you'd want writing a Lingua::EN module. :-) Since I'm one of the few Perl proponants at my company, I probably won't win the fight to have CGI generate the pages, and thus a nice perl syntax for the markup (like $to_be{first}{singular}{present}) probably won't happen. I agree English is contorted - check out the exceptions Damian mentions in his module & it's hard to argue the man isn't a saint for such an extraordinary job. (Yup, this does sound like a homework question, but it isn't. We do ask-a-nurse telephone triage, and we're moving to having the patients triage themselves via the web. Presentation means a lot, or so I'm told.) Thanks, everybody. Your help is appreciated.
Re: verb conjugation
by FouRPlaY (Monk) on Oct 25, 2000 at 03:29 UTC
    My suggestion is that you give up on English. It was WAY to many exceptions to a rule (which, BTW, is why it's considered the third hardest language to learn. Behing Chinese and Japanese). Try Sandskrit. I understand all it's rules are followed with out exception. That'll make what you change the verb to much easier.
Re: verb conjugation
by Anonymous Monk on Oct 25, 2000 at 02:56 UTC
    May I ask if this is a homework question?
      Yes, apparently you may.

      UPDATE: Read the parent post. I answered a stupid rhetorical question with a stupid rhetorical answer.

      ALL HAIL BRAK!!!