I have some code (mostly borrowed from an example in the Punctuation that will automatically make “Tom’s shirt” refer to a shirt worn by Tom, and similarly for anything that’s part of Tom or held by Tom (this is the enclosure relation). I’m pasting an unnecessarily long bit under a spoiler tag:
[spoiler][code]“possessions” by Matt Weiner
Section 1 - Of Hats
clothing is kind of thing.
a hat is kind of clothing.
clothing is always wearable.
understand “hat” as a hat.
The fuschia hat is a hat. The bright red hat is a hat. The bright blue hat is a hat. The purple hat is a hat.
The indefinite article of a hat is usually “a”. The description of a hat is usually “It’s [indefinite article of the noun] [printed name of the noun].”.
Section 2 - Of Sticks
The swagger stick is a thing. The description is “It seems confident, if not arrogant.” The walking stick is a thing. The description is “Sturdy and mostly straight, it looks like it might help you walk.”
Section 3 - Of Noses
A nose is a kind of thing. Every person incorporates a nose.
The description of a nose is usually “[Random person incorporating the item described][’]s nose is noselike.”
Section 4 - Of Enclosures
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;
say “[line break]”.
Understand “[something related by reversed enclosure] 's” as a thing.
Understand “my” as a thing when the player encloses the item described.
Enclosure-querying is an action applying to one thing. Understand “scan [something]” as enclosure-querying. [This is for debugging; you don’t want to include it]
Carry out enclosure-querying: say “[list of things enclosed by the noun].”
Section 5 - Scenario
Starter is a room.
Bob and Mike are men in Starter.
Understand “Robert” as Bob.
Barbie and Sandie are women in Starter.
Bob wears the red hat. Mike wears the blue hat. Barbie wears the fuschia hat. Sandie wears the purple hat. Sandie carries the swagger stick. Mike carries the walking stick.
Persuasion rule: persuasion succeeds.
Test me with “x bob’s hat/x bob’s nose/x sandie’s stick/bob, drop hat/mike, doff hat/x mike’s hat/mike, take hat/x mike’s hat/bright blue hat/x mike’s blue hat/mike, wear red hat/mike, drop blue hat/take hat/x my hat”.
[/code][/spoiler]
I think this works, though there may be some bugs in it and disambiguation might be hinky. However, it probably won’t suit your purposes, because I suspect you want “Tom’s shirt” to refer to the shirt Tom was wearing even when he’s taken it off. To do that, you might try something like the ideas discussed here (unfortunately there’s a lot of fairly irrelevant back-and-forth in that thread), particularly the “embodiment” relation set with the When play begins rule. (Though you probably want to call it “ownership” and certainly want to set it to anything that the person encloses rather than anything that is part of the person.)
Of course, at this point a simpler way might just be to manually declare the items as “Tom’s shirt” etc.