I built a pretty extensive rule to try to do what the title says, but it is a little hard on performance (not too bad, but a little)… but worse, it get’s really complicated to deal with second (or third) nouns. I thought I posted this somewhere before, but here it is anyway as I can’t find the post I may have shared this in before.
[rant]There’s also some stuff in here to make it work with some other extensions, like Numbered Disambiguation Choices.
[code]
Disambiguate-command is a text that varies.
Disambiguate-flag is a kind of value. Disambiguate-flag are disambiguate-yes and disambiguate-no. A thing has a disambiguate-flag. A thing is usually disambiguate-no. Understand the disambiguate-flag property as describing a thing.
text-disambiguation-applicable is a truth state that varies. text-disambiguation-applicable is true.
Understand “take/look/touch/wear/eat” as “[commands]”.
Understand “take inventory” as “[disambiguate-inapplicable-commands]”.
After reading a command while text-disambiguation-applicable is true:
if the player’s command includes “[commands]” and the player’s command does not include “[disambiguate-inapplicable-commands]”:
if the noun is nothing:
let disambiguate-command be text;
let disambiguateTextOne be “asdfjklimpossiblenever”;
let disambiguateTextTwo be “asdfjklimpossiblenever”;
let disambiguateTextThree be “asdfjklimpossiblenever”;
let command-understood be text;
let command-understood be “[the matched text]”;
now disambiguate-command is “[command-understood]”;
cut the matched text;
let original-command-nouns be text;
let original-command-nouns be the player’s command;
if the player’s command matches the regular expression “\w|\w\p|\p\w”, case insensitively:
let first-match be text;
let first-match be “[the matched text]”;
now disambiguateTextOne is “[first-match]”;
cut the matched text;
if the player’s command matches the regular expression “\w|\w\p|\p\w”:
let second-match be text;
let second-match be “[the matched text]”;
now disambiguateTextTwo is “[second-match]”;
cut the matched text;
if the player’s command matches the regular expression “\w|\w\p|\p\w”:
let third-match be text;
let third-match be “[the matched text]”;
now disambiguateTextThree is “[third-match]”;
cut the matched text;
if disambiguateTextOne is not “asdfjklimpossiblenever”:
let exact-match be a truth state;
now exact-match is false;
repeat with text-disambiguable running through visible things:
if the printed name of text-disambiguable exactly matches the regular expression “(?i)^\b[original-command-nouns]\b?”:
now text-disambiguable is disambiguate-yes;
now exact-match is true;
if text-disambiguable is held by the player and the disambiguate-command is “take”:
now text-disambiguable is disambiguate-no;
now exact-match is false;
if exact-match is false:
repeat with text-disambiguable running through visible things:
if disambiguateTextThree is not “asdfjklimpossiblenever”:
if “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextOne]\b|\b[disambiguateTextOne]\p\b|\b\p[disambiguateTextOne]\b” and “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextTwo]\b|\b[disambiguateTextTwo]\p\b|\b\p[disambiguateTextTwo]\b” and “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextThree]\b|\b[disambiguateTextThree]\p\b|\b\p[disambiguateTextThree]\b”:
now text-disambiguable is disambiguate-yes;
if disambiguateTextTwo is not “asdfjklimpossiblenever” and disambiguateTextThree is “asdfjklimpossiblenever”:
if “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextOne]\b|\b[disambiguateTextOne]\p\b|\b\p[disambiguateTextOne]\b” and “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextTwo]\b|\b[disambiguateTextTwo]\p\b|\b\p[disambiguateTextTwo]\b”:
now text-disambiguable is disambiguate-yes;
if disambiguateTextTwo is “asdfjklimpossiblenever”:
if “[the printed name of text-disambiguable]” matches the regular expression “(?i)\b[disambiguateTextOne]\b|\b[disambiguateTextOne]\p\b|\b\p[disambiguateTextOne]\b”:
now text-disambiguable is disambiguate-yes;
change the text of the player’s command to “[disambiguate-command] disambiguate-yes”;
otherwise:
change the text of the player’s command to “[disambiguate-command] [original-command-nouns]”;
now text-disambiguation-applicable is false;
First every turn:
now every thing is disambiguate-no;
now text-disambiguation-applicable is true;
follow the Numbered Disambiguation Choices reset disambiguables rule.
Rule for printing a parser error:
now every thing is disambiguate-no;
now text-disambiguation-applicable is true;
follow the Numbered Disambiguation Choices reset disambiguables rule;
continue the action;
[/code][/rant]
Anyway, that code works for a single noun, and there aren’t technically any problems with it. However, I really don’t want to deal with building out the logic into that monster for second or third nouns, and I don’t like the performance hit.
What I’m hoping is that there is a much simpler solution I just don’t know how to do myself yet. Something like this psuedo code is what I wish would work:
Understand the printed name property as describing a thing.
Understand any word in the printed name property as describing a thing.
That second bit is what I’m after. So if the printed name of an object was “sphere of unimaginable chaos”… the player should be able to type “look sphere” “look unimaginable” “look chaos” or, even “look of” for all I care, and this should put that object into the parser. Is there any way to do this without writing some monster rule with lots of regular expressions and conditionals?