Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Game Commands Parsing?

Tags:

python

nlp

I'm interested in writing a parsing engine such as the ones in Inform, which is very robust.

I've tried a couple of different approach:

  • regex. For regex, I can only match {verb} {noun1 optional-noun2} {optional-preposition} {indirect-noun1 optional-indirect-noun2} This doesn't work that well.
  • list of predefined verbs and their matched preposition and nouns. This approach is too complex, since there has to be A LOT of predefined data.
  • splitting into different words and run them through a dictionary maps. Again this is too complex and not practical due to the amiguity of certain words such as "look" or "put (on, out)"

I know about language processing though I have actually no idea how to start and some of the stuff are too complicated. (No CS background, I'm just learning on my own right now).

Some ideas I have:

  • As I've said, natural language processing.
  • Design a parser that parses something similar to SQL.

Is there any other ideas? How would I go about design and implementing them?

Note I'm using Python as my language. and in case you missed it, I'm not design a programming language, I'm just parsing user command such as "go north" or complex stuff, like "put the fire out with the blanket"

like image 201
Pwnna Avatar asked Jan 29 '26 07:01

Pwnna


1 Answers

Besides the mentioned pyparsing, which looks very appropriate (I've only used it a tiny bit), you should look into using nltk. It's a great collection of tools for natural language processing, and there's even a book.

like image 80
zeekay Avatar answered Jan 30 '26 21:01

zeekay