Pronoun subsitution

860 Views Asked by At

Has anyone got advice about pronoun substitution? I'd like to make this easy for users, using form %keywords% that will get substituted with a php str_replace array. But it's tough in English.

Example:

$input='%his% house is %his%, and you can visit %him% there.';
$from[]='%his%';$from[]='%him%';
if($gender=='male'){
  $to[]='his';$to[]='him';
}
else{
  to[]='hers';$to[]='her';
}
echo str_replace($from, $to, $input);

outputs:

his house is his and you can visit him there <<= OK!

hers house is hers and you can visit her there <<==SUCKS!!

Example2:

$input='%her% house is %hers%, and you can visit %her% there.';
$from[]='%hers%';$from[]='%her%';
if($gender=='male'){
  $to[]='his';$to[]='him';
}
else{
  to[]='hers';$to[]='her';
}
echo str_replace($from, $to, $input);

outputs:

him house is his and you can visit him there <<= SUCKS!!

her house is hers and you can visit her there <<==OK!!

Sometimes I hate english. Any ideas on how to manage this?

FYI, this answer produces the same bad output.

3

There are 3 best solutions below

0
On BEST ANSWER

On further review, I think I have found a simpler approach that will satisfy all cases and be fairly simple for users to understand. I'll use the 3rd person plural for keywords

  • they > he / she
  • them > him /her
  • their > his / her
  • theirs > his / hers

Thanks for helping me think this through Jerry and Markus AO.

3
On

Your placeholders will need to also record the inflection of the pronoun: nominative, genitive, possessive, etc. One of the few places where English still has inflections is in pronouns, and 'who' vs. 'whom' is on the way out.

Unfortunately, English speakers really aren't good at getting the rules right even in everyday speech ('I' and 'me' are switched all the time), and (at least in the US) are not really taught the formal names of the different cases. ("Genitive?"). So coming up with a way that's easy for users is going to be pretty challenging.

I'd recommend %possessive% as the placeholder, and possible substitutions perhaps like $third['male']['possessive'] = 'his', $third['female']['possessive'] = 'her', to allow $first['possessive'] = 'my'.

1
On

You will have to map the whole lot of possible inflections and use matching placeholders: English Personal Pronouns In this case, even with third-person pronouns alone, there's some overlap to deal with (ie. between object and dependent possessive, etc.). For a sample array covering all cases/forms:

$pronouns['3rd']['male'] = [
    'subj' => 'he',
    'obj' => 'him',
    'poss' => 'his',
    'poss_ind' => 'his',
    'refl' => 'himself',
];

$pronouns['3rd']['female'] = [
    'subj' => 'she',
    'obj' => 'her',
    'poss' => 'her',
    'poss_ind' => 'hers',
    'refl' => 'herself',
];

Then markup placeholders as %obj%, %poss%, or with the full form as %object% etc. if you'd rather have that. Or %3rd:obj% etc. if you need to deal with all persons in your templates. But given the overlap, if you want to get this correct, there's no way around all-out grammar here.

Best of luck in educating your users on the difference between dependent/independent possessive pronouns, etc. but other than doing that, you'd have to come up with a semantic analysis algorithm that deducts the appropriate inflection from the context. You could craft together a click-to-add-tag interface with appropriate icons that illustrate dependent/independent possessive etc. :)