p2pmud - Parser Tutorial

Introduction

p2pmud includes a natural language parser for interpreting the player's input. This parser supports verbs, nouns, adjectives, prepositional phrases, and ambiguous words via backtracking.

By default, the parser will pretty much handle everything for you automatically. You don't have to do a lot to customize the parsing if you don't want to when creating your own adventures. Many of the most common things you will want to do (like define your own words) can be done without any coding at all! Well explain more of this shortly.

Most commands are of the two simple forms "verb" and "verb now" For example, the user can say "look" or "look here" Lots of times verbs can accept optional nouns or "arguments" to the verb aka "command". If you use the help command, you can see exactly what the parser is looking for.

Type: help look

Usage: look [object]
   object (Thing) - The object is the item you would like to see. This will default to your current location.

Synonyms: spy see examine glance peer study read
This tells you that the look verb is expecting one noun, but that it is optional. It will default to the current room if not defined. If you create your own commands, you will supply this information to the parser so it can parse your new command for you. Also you will see that any verb can have synonyms defined. The parser knows that "spy" is a synonym for "look" but it will retain the fact that the user used the word spy and not look. In the resulting output, the synonym spy will be referenced for you automatically.

Type: spy me

You spy at admin and see: Nothing out of the ordinary. admin looks to be in perfect health! (100%) 

Special words and characters

There are two special words "here" and "me". The parser assigns special meaning to these two words to be your current room and yourself respectively. Also, there are several shortcuts the parser understands. If a line starts with a quote('), it knows you want to say something outloud, a colon(:), it will issue a emote command, for authors an exclamation mark (!)will let you evaluate any Javascript expression on the fly, and a question mark (?) is a shortcut for help.

Type: :scratches his head
Type: "hey this parser is really neat!
Type: !5
Type: ?get

Shortcuts

The parser already knows about common abbreviations players like to use, for example, nw to mean northwest. You won't have to set any of these up by hand. Also, all things in the game have a default verb attached to them. If the user double clicks the image, or just types the name of the object in, it will assume the user wanted to take this default action. For Thing objects, the default is to look, for Exit objects, the default is to travel through it, etc. You can override this for a particular object if you like!

Type: create apple Food
Type: setprop apple defaultVerb /eat
Type: get apple
Type: apple

Learning words

Also, the parser automatically knows all of words used by the name's of every item in the current room. So if there is a "red ball" in the current room, you don't have to teach the parser that "red" is an adjective and "ball" is a noun, it will infer that automatically!

However, sometimes you will want to teach the parser a new word. There is a command just for this called "bind". You specify the word, the type that it is, and optionally another word it references. Make sure you remember to snapshot your work or else the parser won't remember your new words once you restart!! Let's say you want to teach the parser a new Preposition, a new Modifier (adjective) a new Quantifier (numerical adjective) and a new Synonym.

Type: bind within Preposition
Type: bind purple Modifier
Type: bind twelve Quantifier 12
Type: bind bellow Synonym /say

The parser now recognizes that 'within' is a preposition, 'purple' is an adjective, 'twelve' is a numerical adjective, and 'bellow' is the equivalent of 'say'. Here you have to preceed say with a forward slash or use quotes around it so the parser gets the word 'say' and not the verb say. We don't give an example of making an entirely new verb here, because you have to actually create a command object for it, and that's a later tutorial. However, you can now:

Type: bellow "you fool!

It's actually pretty rare you will have to bind your own Verbs, Modifiers, or Nouns, since these are done automatically. Usually you'll just want to make up synonyms for words the parser already knows. If you want the parser to forget a word you already taught it, there is an unbind command. This takes a single argument, the word you want to unbind. Don't forget if it is a verb (or a synonym for one) you will have to put a leading slash in front of it.

Type: unbind within
Type: unbind /bellow

Abbreviations and Ambigous words

The parser handles abbreviated words, and ambiguous words for you. Try the following sequence of commands:

Type: create "red ball"
Type: look ba
Type: create "blue ball"
Type: get ba
Do: Click the 'blue ball' link

What's going on here? First, we created an item called "red ball". The object was created with 'red' as an adjective and 'ball' as a noun. When you said 'look ba' the parser realized there is only one object in the room that matches 'ba' so you look at it. Now when you created the blue ball and wanted to get it, the parser saw that two potential items could match and generated a question back to the user. You can either type in the answer, or to make it easier, you can click one of the links provided by the parser to answer the question. The parser knows that it posed a question back to the user and if the user answers it, will continue on with the action! Now try this:

Type: drop ba

You should drop the blue ball you are carrying! How come the parser didn't ask which ball this time? Commands can give contextual hints to the parser, the Drop command tells the parser that it prefers objects carried by the user over objects in the same room as the user. The parser used this knowledge to automatically decide that you must have meant to drop the blue ball since you aren't carrying the red ball! Clever, eh?

Autospawns

What's an autospawn you might ask? Well, we always thought it was annoying that you could be in the middle of a forest and type 'get leaf' and a game would come back and say either "What is leaf?" or "I don't see leaf here!" To remedy this, we created autospawns. These are used to teach the game/parser about common objects for a particular room. Everytime a player references one of these words, and there isn't already one present, it will create a new object for you automatically!! Try it out!

Type: name here "Tropical Jungle"
Type: autospawn plant
Type: autospawn coconut
Type: get coconut

Congratulations! This completes the p2pmud parser tutorial!

© Copyright 2005 TEAM CTHULHU