[I7] Implementing "shake [someone]'s hand"

How would this be done? I’ve gotten this far:

Understand the command “shake” as something new. Understand “shake hands with [someone]” as handshaking. Handshaking is an action applying to one thing. Report handshaking: say “You don’t think that would be called for.”
Understand “shake [something]” as pushing.

But that doesn’t account for the phrasing, say, “shake Kara’s hand,” which is the first I would come up with. I’ve fiddled with “replace the player’s command with” type things but am not sure how to redirect that to the specific NPC. I also suspect regular expressions could be used here but I am basically shit with those.

Considerations:

  • There will be scenes where multiple NPCs are in a room and the player might shake hands with any of them. (For instance, an intern being shown around the office by her boss and introduced to various people there.)
  • I want to keep “shake [someone]” as a viable command. (It’s redirected to “push” because the default response fits, but, say, I want to avoid a situation where “shake Kara” defaults to shaking her hand.)
  • “Shake” by itself should probably not do anything weird.
  • I would prefer implementing body parts to be a last resort.

Thanks in advance!

Understand “Kara’s hand” as Kara, then check ‘shaking a person’ to see if the player’s command includes ‘hand’, and if it does, redirect to the handshaking action?

A hand is a kind of thing.
A hand is a part of every person.

Instead of shaking a hand:
    Try shaking hands with (a random person who encloses the noun).

Or something like that.

Maybe try using Punctuation Removal by Emily Short to get rid of the apostrophe

After reading a command: remove apostrophes.

and then you can try:

Understand "shake [someone] s hand" as handshaking.

This only works if you never need to use apostrophes. But even if you do need to use apostrophes, if it’s OK to zap apostrophes whenever they’re followed by an s I think you can do this (which doesn’t require Punctuation Removal):

After reading a command: let X be indexed text; let X be the player's command; replace the text "[']s" in X with " s"; change the text of the player's command to X.

If you sometimes need to do apostrophe-s (for instance if you wind up implementing noses as assemblies so you want to allow “x Kara’s nose” where the object is actually named “Kara’s nose”) then things would probably get hairier.

Ran into a problem with the same concept.

While the approach of, replace the text "[']s" in X with " s"; does work, I like to avoid it because it only replaces the first instance and not every apostrophe in the string (not that this is very likely to occur, but…) So naturally we turn to regular expressions, and try something like this:

Removing Apostrophes is an activity.
Rule for Removing Apostrophes:
	let T be "[the player's command]"; 
	replace the regular expression "\B\[']s\b" in T with " s"; [removes possessive apostrophes -- *plural*]
	change the text of the player's command to T.

I’m crap at the regular expression game, but my thinking is \B means something that’s going to be part of a word, \b means a word break, and [’]s is of course the standard English expression of possession. So if the apostrophe-s is sandwiched between a letter/word and a space then you’re pretty much golden, as meeting all three criteria any other way should be very, very rare.

As a side note, I know [’] is generally required for handling apostrophes, but it seems like the syntax for regular expressions should allow ’ to work, yet it does not.

“\char – If char is other than a-z, A-Z, 0-9 or space, matches that literal char”

Or at least that’s what the manual claims. So many limits to my I7 understanding :frowning:

P.S. The Understand "[something related by reversed possession] s" as a thing. hack is a lovely, lovely trick.

You could give everyone a hand. “A hand is a kind of thing. Understand “hand/hands” as a hand. One hand is part of every woman. One hand is part of every man.”

Then you’d automatically get “Jane’s hand” “Joe’s hand” as objects which then absolves you of dealing with the apostrophe.

You would still need to use the split-and-reversed-possessions idiom if you want to catch synonyms of the person’s name.