Ending with a period causes disambiguation?

Here’s a curiosity:

[code]Test is a room.

There is a green apple in Test. It is edible.

There is a green ball in Test.

Does the player mean eating something edible: It is very likely.

test period with “eat green.”

test normal with “eat green”[/code]

One of my testers came up with this. If you end the command with a period, you get a disambiguation question. Otherwise, you don’t. Why is that?

That’s some kind of bug in the parser, but I can’t tell what.

Also interesting: order of commands matters. If you try “x green” then “x green.”, you get different results. If you restart and try “x green.” then “x green”, both commands disambiguate.

(I changed “eating” to “examining” in the example, because I got tired of undoing the action. It doesn’t change the bug.)

The ordering dependency looks like bug 860 (inform7.com/mantis/view.php?id=860), but I don’t know if that’s the original problem, or just a side issue.

When I turn on extra ChooseObjects debugging, I see that one case prints “[choosing a cobj strategy: nothing interesting]”; the other prints “[choosing a cobj strategy: 0 possible second nouns]”. So the appearance of extra words on the line causes it to run the DTPM rules differently? If so, the bug is in failing to recognize “.” (THEN1__WD) as the end of the command.

I gave this a try.

[code]Include Punctuation Removal by Emily Short.

After reading a command: remove periods.

The Testing Room is A Room.

There is a green apple in the testing room. It is edible.

There is a green ball in the testing room.

Does the player mean eating something edible: it is very likely.

Test period with “eat green.”.

Test normal with “eat green”.[/code]

Strangely enough, this gives “You can’t see any such thing.” in Z Code and crashes in Glulx. However, after a few tweaks to the extension, it works. Here’s the tweaked version of the extension.

[spoiler][code]Version 5 of Punctuation Removal by Emily Short begins here.

Use authorial modesty.

Section 1 - Wrappers

To remove stray punctuation:
(- PunctuationStripping(); players_command = 100 + WordCount(); -)

To remove quotes:
(- Quotestripping(); players_command = 100 + WordCount(); -)

To remove apostrophes:
(- SingleQuotestripping(); players_command = 100 + WordCount(); -)

To remove question marks:
(- Questionstripping(); players_command = 100 + WordCount(); -)

To remove exclamation points:
(- ExclamationStripping(); players_command = 100 + WordCount(); -)

To remove periods:
(- PeriodStripping(); players_command = 100 + WordCount(); -)

To resolve punctuated titles:
(- DeTitler(); players_command = 100 + WordCount(); -)

Include (-

[ Detitler i j buffer_length flag;
#ifdef TARGET_ZCODE;
buffer_length=buffer->1+(WORDSIZE-1);
#endif;
#ifdef TARGET_GLULX;
buffer_length=(buffer–>0)+(WORDSIZE-1);
#endif;
for (i=WORDSIZE : i<=buffer_length: i++) {
if ((buffer->i)==’.’ && (i > WORDSIZE+1)) {
! flag if the period follows Mr,Mrs,Dr,prof,rev,or st
!
! This is hackish,but our hearts are pure
if ((buffer->(i-1)==‘r’) && (buffer->(i-2)==‘m’) && ((buffer->(i-3)==’ ‘) || ((i-3) < WORDSIZE))) flag=1;
if ((buffer->(i-1)==‘r’) && (buffer->(i-2)==‘d’) && ((buffer->(i-3)==’ ‘) || ((i-3) < WORDSIZE))) flag=1;
if ((buffer->(i-1)==‘t’) && (buffer->(i-2)==‘s’) && ((buffer->(i-3)==’ ‘) || ((i-3) < WORDSIZE))) flag=1;
if ((buffer->(i-1)==‘s’) && (buffer->(i-2)==‘r’) && (buffer->(i-3)==‘m’) && ((buffer->(i-4)==’ ‘) || ((i-4) < WORDSIZE))) flag=1;
if ((buffer->(i-1)==‘v’) && (buffer->(i-2)==‘e’) && (buffer->(i-3)==‘r’) && ((buffer->(i-4)==’ ‘) || ((i-4) < WORDSIZE))) flag=1;
if ((buffer->(i-1)==‘f’) && (buffer->(i-2)==‘o’) && (buffer->(i-3)==‘r’) && (buffer->(i-4)==‘p’) && ((buffer->(i-5)==’ ‘) || ((i-5) < WORDSIZE))) flag=1;
if (flag) buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

-)

Section 2 (for Z-machine only)

Include (-

[ PunctuationStripping i;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i) ==’"’ or ‘?’ or ‘!’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ SingleQuoteStripping i;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i)==39) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ QuoteStripping i;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i) ==’"’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ Questionstripping i;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i)==’?’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ ExclamationStripping i;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i)==’!’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ PeriodStripping i j;
for (i=2 : i<=(buffer->1)+1 : i++) {
if ((buffer->i)==’.’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

-)

Section 3 (for Glulx only)

Include (-

[ BufferOut i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
print(char)(buffer->i);
}
];

[ PunctuationStripping i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i) ==’"’ or ‘?’ or ‘!’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ SingleQuoteStripping i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i)==39) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ QuoteStripping i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i) ==’"’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ Questionstripping i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i)==’?’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ ExclamationStripping i;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i)==’!’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

[ PeriodStripping i j;
for (i=WORDSIZE : i<=(buffer–>0)+(WORDSIZE-1) : i++) {
if ((buffer->i)==’.’) {
buffer->i=’ ';
}
}
VM_Tokenise(buffer,parse);
];

-)

Punctuation Removal ends here.

---- DOCUMENTATION ----

Punctuation Removal provides phrases for removing unwanted punctuation marks from the player’s command before attempting to interpret it. These are

remove exclamation points
remove question marks
remove quotes

and, to do all three of these things at once,

remove stray punctuation.

Also provided, but not included in “remove stray punctuation”, is

remove periods

which we should use sparingly, since the player’s command might reasonably include multiple actions separated by full stops. Similarly dangerous is

remove apostrophes

A more common need is to be able to parse titles such as “mr.” and “mrs.” sensibly. Inform reads any full stop as the end of the sentence, which leads to such exchanges as

>x mr. sinister.
You see nothing special about Mr. Sinister.

That's not a verb I recognise.

because Inform has interpreted as though the player had typed

>x mr.
You see nothing special about Mr. Sinister.

>sinister
That's not a verb I recognise.

To get around this, we want to remove full stops only when they appear as parts of standard titles. “Punctuation Removal” provides the phrase

resolve punctuated titles

which turns all instances in the player’s command of “mr.”, “mrs.”, “prof.”, “st.”, “dr.”, and “rev.” into “mr”, “mrs”, “prof”, “st”, “dr”, and “rev” respectively. Now (assuming Inform understands “mr” as referring to the correct character) we get such output as

>x me. x mr. sinister. 
As good-looking as ever.

You see nothing special about Mr. Sinister.

These phrases should be used during the After reading a command activity, so for instance in a game designed to be very patient with the player’s quirks:

After reading a command:
	remove stray punctuation.

Or, if we have titled characters,

After reading a command:
	resolve punctuated titles.

Example: * Patience - In which question and exclamation marks are pulled from the player’s input.

*: "Patience"

Include Punctuation Removal by Emily Short.

The Overpunctuation Arena is a room. "It's madness in here!! Fortunately, you have a lot of patience, right???"

Understand "who is/are [text]" as inquiring about. Inquiring about is an action applying to one topic. Carry out inquiring about a topic listed in the Table of Answers: say "[reply entry][paragraph break]". Understand the command "what" as "who".

Table of Answers
topic	reply
"patience"	"A virtue."
"virtue" or "a virtue"	"A grace."
"Grace" or "a grace"	"A little girl who doesn't wash her face."

After reading a command:
	remove stray punctuation;
	if the player's command includes "&", replace the matched text with "and".

Test me with "what is patience? / what is a virtue?! / what is grace???"

Example: * Abbreviation - In which titles such as Mr. and Dr. are correctly parsed.

*: "Abbreviation"

Include Punctuation Removal by Emily Short.

Test me with "x me / x me. x mr. Sinister. / x rev. carl / x mrs. grey / x st. thomas / x prof. green / rev. carl, hello / rev., hello / specialist, hello / x specialist. x st. Aquinas. /  x st. x me"

The Ecumenical Rod & Gun Club of Seventh Saint is a room. Mr Sinister is a man in Club. The printed name of Mr Sinister is "Mr. Sinister". 

Reverend Carl is a man in Club. The printed name of Reverend Carl is "Rev. Carl". Understand "rev" as Reverend Carl. 

St Thomas Aquinas is a man in Club. Understand "saint" as Thomas. The printed name of Aquinas is "St. Thomas Aquinas". 

Mrs Grey is a woman in Club. The printed name of Grey is "Mrs. Grey".

Professor Green is a man in Club. The printed name of Green is "Prof. Green". Understand "prof" as professor.

Specialist Joan is a woman in the Club.

After reading a command: resolve punctuated titles.

Example: ** Ownership - In which commands like EXAMINE JACK’S TIE are understood if Jack is wearing a tie, and otherwise not.

The trick here is that we want to write

Understand "[something related by reversed possession]'s" as a thing.

but this won’t work, because Inform can’t glue a token to an additional following set of characters. If, however, we make the apostrophe go away, we can match “[something related by reversed possession] s” – an odd phrase, but one which the player is unlikely to type on his own in any other context:

*: "Ownership"

Include Punctuation Removal by Emily Short.

Understand "[something related by reversed possession] s" as a thing.

Jack wears a tie. Jack is in the Turret. The Turret is a room.

After reading a command:
	remove apostrophes.

Note, though, that this kind of gambit should really be used cautiously and with awareness of what else the game is doing. If there are cases where the player should be using apostrophes, we’ll want to write more restrictive rules about when to strip them away.[/code][/spoiler]

However, you’d need to change the full stops that separate commands into “then” so that multiple commands work.

Hope this helps.

This appears to be vaguely similar to this, where the parser completely bypasses DPMR when it shouldn’t and then asks the player for disambiguation instead.

I looked at that (bug inform7.com/mantis/view.php?id=633) but it doesn’t appear to be the same thing. In that case the parser is running the DTPM phase, but for the wrong action.

Yeah, I don’t see this reported anywhere. It’s interacting with 860, but you can get around that by slipping a ``z’’ between the commands, leaving the core bug behind. Zarf’s diagnosis,

looks right to me.

Hmm. climbingstars, that bug in Punctuation Removal is also worth reporting; we don’t have it either.

So what exactly should I report, if anything?

If you could report what you had in your original post, maybe adding Zarf’s comment, that would be great.

Here’s the report.

inform7.com/mantis/view.php?id=1002

Thanks.

Yes, thanks for the report! It’s confirmed now.