Some pointers about name conflicts:
-
When parsing nouns, the way the parser works is essentially to ask objects whether they match to words, then to decide that the object that matched the most words is the one that the player intended. (EDIT: As zarf points out below, this sentence is misleading. I should have said “the most words in a row” instead. There is a lot of detail being skipped here.)
-
In cases where more than one object matches the same maximum number of words, it attempts to automatically disambiguate between them based on various rules. Among those rules are checks to see whether objects are carried or in the location, which creates preference over other objects, though which location is better depends on the current action. Invoked by the rules for automatic disambiguation are the does the player mean
rules (which have more weight than the automatic scoring rules), but these are used only if there is a tie in word matches. If automatic disambiguation succeeds, the clarifying the parser's choice
activity runs to show which object was chosen.
-
If automatic disambiguation fails, then it uses the asking which do you mean
activity to prompt the player for more words and returns to step 1. When asking which do you mean
, all previous information about scoring is disregarded.
If you have coffee
, a coffee table
, and a coffee table book
available at the same time, then all three score one point on the word “coffee”. Trying to guess which is the right object is a really difficult situation for the parser, because it lacks context about which objects are suitable for which actions. You can try to give it that context with does the player mean
rules, but for certain actions (such as examining
) it’s not really possible to craft rules that make sense universally.
There is a use option:
Use unabbreviated object names.
which is described in WWI 3.2 Rooms and the map. It will make the I7 compiler assume that only complete names of objects can be used. This can help when writing your code, but it doesn’t affect the parsing of player commands.
Given the code:
Use unabbreviated object names.
Chapter - Coffee Clash
The Living Room is a room. "Your typical living room. The exit is south."
Section - Coffee Table
The coffee table is a supporter in the Living Room.
Section - Cup
The cup is a container on the coffee table.
Rule for printing the name of the cup while not inserting or removing:
if the cup contains coffee, say "cup of coffee";
otherwise say "empty cup";
omit contents in listing.
Understand "cup of [something related by containment]" as the cup.
Check inserting something into the cup: instead say "That won't fit in the cup."
Before drinking the cup: instead try drinking the coffee.
Section - Coffee
The coffee is in the cup. The indefinite article is "some".
Check taking the coffee: instead say "You can't hold that."
The block drinking rule does nothing when the noun is the coffee.
Carry out drinking the coffee:
now the noun is nowhere;
Report drinking the coffee:
say "You gulp down the coffee.";
Check drinking the coffee:
if the cup is not carried:
carry out the implicitly taking activity with the cup;
if the cup is not carried, stop the action.
Section - Coffee Table Book
The coffee table book is on the coffee table. The description is "You leaf through the book but find nothing interesting."
Test coffee with "x coffee / get book / x coffee / drop book / x coffee / coffee / cup" in Living Room.
Test table with "x table / get book / x table / drop book / x table" in Living Room.
Here’s the room description:
Living Room
Your typical living room. The exit is south.
You can see a coffee table (on which are a cup of coffee and a coffee table book) here.
and here’s what you get for >TEST COFFEE:
(Testing.)
>[1] x coffee [coffee table gets preference because it is in the "second best location" (the room) per automatic disambiguation]
(the coffee table)
On the coffee table are a cup of coffee and a coffee table book.
>[2] get book [only one object matching the word "book"]
Taken.
>[3] x coffee [coffee table book gets preference because it is in the "best location" (PC's hands) per automatic disambiguation]
(the coffee table book)
You leaf through the book but find nothing interesting.
>[4] drop book [only one object matching the word "book"]
Dropped.
>[5] x coffee [three objects match the word, and two have the same automatic disambiguation score (table and book, both in the "second best location"), so player is asked which one they mean]
Which do you mean, the coffee table book, the coffee table or the coffee?
>[6] coffee [since all three objects match this word, it does not help to disambiguate]
Which do you mean, the coffee table book, the coffee table or the coffee?
>[7] cup [a little trickier to understand, see below]
I only understood you as far as wanting to examine the cup of coffee.
When the asking which do you mean
activity runs, it produces a non-standard prompt state. Any new words entered will be preferentially added to the previous command and another parsing attempt of it will be made, unless the new input looks like a new command by virtue of starting with a recognized verb word. Importantly, the new words are added before the others in the previous command, so given the interaction:
>X SANTA
Which do you mean, the santa hat or Santa Claus?
>HAT
then the parsing will be attempted as though the player had entered >X HAT SANTA.
In your example, the comparable revised command is >X CUP COFFEE COFFEE, which the parser can’t understand as the cup. Although it can understand “cup” as meaning the cup
, it needs the word “of” in order to recognize the word “coffee” as being relevant to it.
Similarly for the test table
output:
(Testing.)
>[1] x table [both coffee table and coffee table book match the word "table", but only table is in "second best location"]
(the coffee table)
On the coffee table are a cup of coffee and a coffee table book.
>[2] get book [only one object matching the word "book"]
Taken.
>[3] x table [both coffee table and coffee table book match the word "table", but only book is in "best location"]
(the coffee table book)
You leaf through the book but find nothing interesting.
>[4] drop book [only one object matching the word "book"]
Dropped.
>[5] x table [same situation as test coffee command 5]
Which do you mean, the coffee table book or the coffee table?
EDIT: Another helpful feature is the use of Understand...
lines with optional words in them:
The coffee table is a privately-named supporter in Living Room. Understand "coffee/-- table" as the coffee table.
This makes it so >X TABLE or >X COFFEE TABLE will match the table, but >X COFFEE will not.
Even more helpful can be making your own tokens (see WWI 17.13 New tokens):
Use unabbreviated object names.
...
The coffee table is a privately-named supporter in Living Room. Understand "coffee/-- table" as "[table designation]". Understand "[table designation]" as the coffee table.
...
The coffee table book is a privately-named thing on the coffee table. The description is "You leaf through the book but find nothing interesting." Understand "book" or "[table designation] book" as the coffee table book.
With that in place your test coffee
and test table
scenarios might be working the way that you want.