[DGD] parse_string question
bart at wotf.org
bart at wotf.org
Sun Dec 30 23:03:42 CET 2007
On Sun, 30 Dec 2007 22:36:41 +0100, Felix A. Croes wrote
> bart at wotf.org wrote:
>
> >[...]
> > At any rate, my first example can easily handle the following phrase and
> > result in a correct interpretation in 2 different cases:
> >
> > phrase: open box
> >
> > This could be a verb + object or an adjective + object.
> >
> > If there is a closed box that could be opened, verb + object is very likely
> > what the player meant, but if there is an open box, the second is very likely
> > what the player intended. Obviously, in the second case there has to be
> > another verb also, so it is possible to see if this was the correct parsing on
> > hindsight at least.
> >
> > What I am looking at is a way to handle those, and make a guess at what the
> > player intended. In the first example I gave, I can deal with that on-the-fly,
> > ie, WHILE parsing. I see no way to do that when adding the verbs to the
> > grammar, except for changing the grammar each time. This is because once I
> > have a verb=/open/ in there and it is matched, then it won't be matched by
> > anything else, hence I cannot use the alternative where it is an adjective.
>
> You can have 'open' as an adjective too, of course. Much nicer to
> have the alternate parse trees represent alternate meanings directly.
>
Definitely, but:
The parser doc says:
--------
If a string matches more than token, the token for which the rule appears first
in the grammar is selected. If a string does not match any token, it is
rejected and parsing fails.
--------
Which suggests that when writing
verb=/open/
adjective=/open/
verb is matched but not adjective.
and indeed:
whitespace=/[ ]+/
verb=/open/\n
adjective=/open/\n
word=/[^ ]+/\n
part: adjective word\n
part: verb word
returns one parse tree.
Ok, so the alternative would be:
adjverb=/open/\n
word=/[^ ]+/\n
part: adjective word\n
part: verb word\n
verb: adjverb\n
adjective: adjverb\n
That indeed returns 2 parse trees one of which I can invalidate.
In other words, making tokens for everything that could be used as a verb and
an adjective, and then making production rules for both meanings it could have.
That would work for preventing having to change the grammar in quite a few
cases, I'm not sure if I like it better then the very first example I came up
with, will experiment some more with it on 'real' input.
Bart.
--
Created with Open WebMail at http://www.bartsplace.net/
Read my weblog at http://soapbox.bartsplace.net/
More information about the DGD
mailing list