Page 3 of 3

Re: Verb-Noun Parser

Posted: Wed Nov 13, 2013 2:33 pm
by miko
Echo wrote:I want to make a verb-noun parser for my visual novel game engine. A verb-noun parser is used to recognize input made as strings by the player. For example you could type in "open door", then the computer will use the verb-noun parser to recognize the word open as a verb, you are telling the computer that you want to open something but what? then it looks for a noun to attach this verb to, door is a noun, it is an object, then using the computers programmed logic it will link the two, open + door, it then recognizes this as a valid action and performs the task.
I know how this works in my mind but I have no idea how to code this from scratch in Lua, I have a hint that it involves something to do with converting variables into strings and vice versa, could be wrong though.
Interesting idea. There are many ways of doing this, of course. Here is one simplified way (for example, it assumes that objects names and action names do not collide). First tokenize the user string to find objects (by name), then find actions (functions) for this objects. I have just pushed an example here (and in the attachment).

Re: Verb-Noun Parser

Posted: Thu Nov 14, 2013 9:54 am
by Ekamu
Wow thanks, this example is great but looking through the code I see some meta table stuff and objects so I would need to learn a bit about meta methods and OOP before I can fully implement this into my own code but thanks alot!

Re: Verb-Noun Parser

Posted: Thu Nov 14, 2013 11:43 am
by miko
Ekamu wrote:Wow thanks, this example is great but looking through the code I see some meta table stuff and objects so I would need to learn a bit about meta methods and OOP before I can fully implement this into my own code but thanks alot!
The most important is the concept to tokenize the input, and - for each lowercased word - find an "object" and then its "methods". All the other code is just to show you how it could work (and to actually make it playable). You probably do not need all that.

So, you are welcome, alot, and have fun!

Re: [SOLVED] Verb-Noun Parser

Posted: Thu Nov 14, 2013 2:03 pm
by Ekamu
Image
haha thanks a lot!