Up to Main Index                           Up to Journal for January, 2019

                   JOURNAL FOR WEDNESDAY 16TH JANUARY, 2019
______________________________________________________________________________

SUBJECT: It’s all about the context
   DATE: Wed 16 Jan 18:59:43 GMT 2019

While waiting for feedback and comments on the proposed crafting system for
WolfMUD I’ve been taking a look at enhancing the parser. Only the enhancements
won’t actually be in the parser but in the Inventory attribute. Confused?

The problem is the parser has no context. So for now the ‘parser’ will remain
relegated to just splitting the player’s input into words and stripping out
stop words. All of the fun stuff will take place in the inventory search
functionality.

The reason for this is, as I said, all about context. When you drop an item
your inventory is checked for the item to be dropped. When you get an item the
location’s inventory is checked for the item to get. If you try to examine
something then your inventory is checked first, then the location’s inventory.
So the decision of which inventories to search and in what order depends on
the command being invoked which provides the context for making sense of a
player’s input.

The context also provides a clue as to how specific a player needs to be. For
example if there is only one ball then ‘GET BALL’ is quite adequate. However,
if there is a small green ball and large green ball then ‘GET BALL’ or even
‘GET GREEN BALL’ is not enough. However ‘GET SMALL BALL’ or ‘GET LARGE BALL’
would be unambiguous. If you expand the context by adding a large red ball,
then ‘GET LARGE BALL’ is no longer sufficient — do we mean the large red ball
or the large green ball?

To experiment with some ideas I’ve created a ‘#TEST’ command. It simply tries
to identify the correct items in the current location based on input.

Here is a test run for what I have working so far:


  Fireplace
  You are in the corner of the common room in the dragon's breath tavern. A
  fire burns merrily in an ornate fireplace, giving comfort to weary
  travellers. The fire causes shadows to flicker and dance around the room,
  changing darkness to light and back again. To the south the common room
  continues and east the common room leads to the tavern entrance.

  You see a small orange here.
  You see a small sack here.
  You see a curious brass lattice here.
  You see an orange box here.
  You see an iron bound chest here.
  You see a large red ball here.
  You see a large green ball here.
  You see a large orange here.
  You see a small bag here.
  You see a small green ball here.

  You can see exits east, southeast and south.
  >#test ball
  Hrm, there is more than one 'BALL' here.
  >#test green ball
  Hrm, there is more than one 'GREEN BALL' here.
  >#test red ball
  You test a large red ball.
  >#test large green ball
  You test a large green ball.
  >#test large green ball small green ball
  You test a large green ball.
  You test a small green ball.
  >#test small green ball red ball chest
  You test a small green ball.
  You test a large red ball.
  You test an iron bound chest.
  >#test small green ball ball chest
  Hrm, there is more than one 'BALL' here.
  >#test orange orange box
  Hrm, there is more than one 'ORANGE' here.
  >#test small orange orange box
  You test a small orange.
  You test an orange box.
  >#test frog
  You see no 'FROG' here.
  >#test chest frog red ball
  Hrm, what is 'FROG' after 'CHEST'?
  >#test frog chest
  Hrm, what is 'FROG' before 'CHEST'?
  >#test red chest
  Hrm, what is 'RED' before 'CHEST'?
  >


Not too shabby for a prototype. The final response to ‘#test red chest’ might
be questionable — there is a chest but it isn’t red. Other than the #TEST
command for experimenting the only other change is to aliases in the zone
files. For example the large red ball is defined as:


  %%
        Ref: O99
       Name: a large red ball
    Aliases: +RED +LARGE BALL
      Reset: AFTER→0s JITTER→0s
    OnReset: There is a bright flash and a large red ball appears.
    Cleanup: AFTER→1m JITTER→1m
  OnCleanup: There is a bright flash and the large red ball disappears.
   Location: L1

  This is a large, green, rubber ball.
  %%


Notice that some of the aliases have a leading ‘+’ symbol. These are
qualifying aliases. You can think of them as additional aliases, hence the
plus symbol. Qualifying aliases are only used in addition to a main alias. For
example you could ‘#TEST BALL’ or ‘#TEST RED BALL’ but ‘#TEST RED’ would not
be understood.

One interesting example is with the orange (as in the fruit) and the orange
box - as in a box for storing oranges (fruit) in, although it might also be
coloured orange, who knows?


  >#test small orange orange box
  You test a small orange.
  You test an orange box.


Here we need to recognise that we have ‘small orange’ and ‘orange box’ and not
to consume too many oranges :) That is, we need to be able to tell when a word
is a qualifier and when it isn’t. We don’t want to end up with ‘small orange
orange’ and ‘box’ or ‘small’ and ‘orange orange box’.

This is why I process the words backwards. In this case box, orange, orange,
small. We know that the last word will not be a qualifying alias — qualifying
aliases always have to come first. So we have ‘box’. Next we see if ‘orange’
is a qualifying alias for ‘box’, which it is. Then we have the second
‘orange’. As it would be a duplicate we stop here and have ‘orange box’. This
makes the first ‘orange’ the new ending non-qualifying alias. Finally we find
that ‘small’ is a qualifying alias for ‘orange’ resulting in ‘small orange’.

What about:


  >#test small orange small green ball
  You test a small orange.
  You test a small green ball.


Here we find ‘ball’, ‘green’ then ‘small’ but orange is not a qualifying alias
for any small, green balls. So we end up with ‘small green ball’ and ‘orange’
as the next non-qualifying alias. This leads us to ‘orange’ and ‘small’.
Finally we have identified ‘small green ball’ and ‘small orange’.

So far this scheme seems to be working out quite well. Next step is to take
the #TEST command code and turn it into a new, easy to use Inventory Search
method that can be called from any command that needs to identify items.

Now if only I could get it to understand ‘put the cat in the hat on the
table’. Is the cat in the hat and you want to take it out of the hat and put
it (the cat) on the table instead? Maybe you want to put the cat into the hat
and the hat is on the table? Or is the cat in the hat and you want to put both
onto the table? Gah! Need more context :P

--
Diddymus


  Up to Main Index                           Up to Journal for January, 2019