LPTHW ex52, adding the parser

Hi,

I’m having issues on where exactly to begin at this stage of the project. I’ve done a word_list = lexicon.scan(action) in the /game route to capture the text the player puts in so far. But after that, I’m confused on how to actually go about actually using the parser. Maybe the problem is I don’t quite understand how it was supposed to work.

It should be a process something like this:

  1. Scan the input to get the token pairs [(‘eat’, ‘verb’), (‘the’, ‘stop’), (‘cake’, ‘noun’)]
  2. Parse the token pairs to produce a Sentence object, in the case of the #1 it’d be object=cake, verb=eat, subject=player.
  3. Using that, just look up what action that translates into in your action list. You’ll have to do some redesign but basically you can have the Room class handle this with the .go() method, but you could get more fancy. You could also have the Sentence give a method that turns it to a string (try ___unicode___), that returns a “subject:verb:object” pair, then match that in a dict of where to go next.

Try that out.

Thanks. That really helped and I managed to get it to work.

1 Like