[MUD-Dev] Text Parsing

Kylotan kylotan at kylotan.force9.co.uk
Fri May 28 22:03:22 CEST 1999


Albert wrote:
(details snipped...)
>
> Then say the player enter a command like: buy the biggest ball from the
3rd shopkeeper
> The convoluted pseudocode would be:
>
> void Parse(string & rhs) {
>         ParsedCommand pc;
>         string word;
> while (1) {
> word = GetNextWord(rhs); // Would magically keep pointer position
> if (word.empty()) break;
> switch (GetKind(word)) {
> case VERB:
> if (pc.IsNewClause)
> pc.verb = word;
> else
> SendToQueue(pc);
> break;
> case DIRECT_OBJECT:
> if (pc.IsNewClause) {
> pc.direct_object = word;
> pc.IsNewClause = false;
> } else
> pc.direct_object += " " += word;
> break;
> case INDIRECT_OBJECT:
> case ADJECTIVE:
> // Pretty much the same code for direct_object
> case CONJUNCTION:
> SendToQueue(pc); // Would send a copy to the queue, but pc still exists
> pc.IsNewClause = true; // Not technically true, but...
> break;
> }
> }
> }

How can you tell, out of context, whether a noun is the direct object or the
indirect object? (eg. in "get the bag" and "put the ball in the bag" the
word "bag" is direct in the first instance, and indirect in the second.) I
would think you'd need to be looking for other clues, such as
prepositions/prepositional phrases to indicate that you are now expecting an
indirect object.

If you make it so that all noun phrases contain X adjectives and 1 noun,
that is easy - If this is a noun, and if we have no direct object, this word
is (probably) the direct object. If we have a direct object already, this is
the indirect object instead. However, it looks like you were allowing for
multiple-word nouns...

A simple (but by no means totally sufficient) way to represent this would
obviously be a variable to say whether you are expecting direct or indirect
next, initialised to direct. This could change when you come across a
preposition/prepositional phrase. If you want prepositions to be optional
(so that "get axe bag" works), it would also have to be changed when the
noun you read in doesn't resolve to the same object as the noun you have
already.

Also, bear in mind the order of the two objects is not always fixed
(contrast "give the guard 10 coins" with "give 10 coins to the guard").
However, given that you know the verb/command, it is probably trivial to be
able to swap your objects when necessary.

(By the way, feel free to correct any misuse of linguistic terms - it's been
a while.)

Kylotan.



_______________________________________________
MUD-Dev maillist  -  MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev




More information about the mud-dev-archive mailing list