[SOLVED] Verb-Noun Parser

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Verb-Noun Parser

Post 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).
Attachments
VerbNounParser.love
(4.29 KiB) Downloaded 100 times
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Verb-Noun Parser

Post 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!
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Verb-Noun Parser

Post 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!
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: [SOLVED] Verb-Noun Parser

Post by Ekamu »

Image
haha thanks a lot!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests