I haven't touched Model::World in months. I got sidetracked, but this is one of many things I need to get off my plate (along with three CPAN updates today) so I returned to it with a sense of trepidation.
One of the first things I noticed is that I left a TODO file. I started off by reading that and many of my older posts about this module and decided to see how much work it would take to implement this:
$agent->walk('north');
After writing the tests, I wrote this method:
sub walk : Verb(qw/move go/) { my ( $self, $direction ) = @_; my $room = $self->location; if ( my $destination = $room->exit($direction) ) { return $self->location($destination); } $self->_croak("You cannot go $direction"); }
It worked the first time. That's true OO joy. Decently designed classes, reasonable documentation and, of course, a full test suite have let me return to this with a minimum of pain.
The attribute, by the way, means that all of the following work the same way:
$agent->walk('north'); $agent->move('north'); $agent->go('north');
There are many other things I need to take care of, but I think the hard part will be the grammar. I need to have one built automatically so that the end user doesn't need to know about grammars unless necessary. Unfortunately, that makes for a serious problem that I don't know how to deal with just yet:
"Does a bear write neocon propoganda in the woods?" "Can Tom Delay bear the weight of accusations against him?"
The word "bear" is used as both an noun and a verb. The simplest solution is to write a tokenizer which forbids words with more than one meaning. That makes the parser relatively straight forward for a first pass:
concatenate( $subject, $verb, optional( $object ) );
Later I can expand that, but for now, it's simple.
I think, reluctantly, that I will go this route. The alternative is to simple lex every sentence into a list of WORD tokens and let the grammar figure out the parts of speech based on context. This should not be too hard, but it does complicate things and will introduce bugs. It's my understanding that this is also the reason why people claim that only perl can parse Perl: the meanings of many things are tremendously overloaded and a straight-forward lexing of programs is not possible, so much work is pushed into the parser. Pop quiz: how many different uses for curly braces are there in Perl?
Of course, even the simple version is easier said than done.
Re:Aliases?
Ovid on 2006-04-06T15:57:38
I wrote an attribute handler which would take the attributes and create aliases with them. However, it also registers them as parts of speech in the world vocabulary so that later I can build a grammar with it.