[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
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Verb-Noun Parser

Post by josefnpat »

Image
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
Echo
Prole
Posts: 46
Joined: Fri Jul 13, 2012 4:50 pm
Location: Lucid Moon

Re: Verb-Noun Parser

Post by Echo »

josefnpat wrote:Image
do you see it?
I can't see the one you posted but I can see the one I posted, wierd...the link is not broken or anything.

O.K, I have attached it to this post directly. I think now everyone can see it...
Attachments
User Interface
User Interface
UI-simple.png (8.82 KiB) Viewed 2397 times
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Verb-Noun Parser

Post by Jasoco »

It's because you were linking to the page the image is on...

http://postimage.org/image/9usnx1m5p/

...instead of the image itself.

http://s14.postimage.org/kudv8nckv/UI_simple.png
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Verb-Noun Parser

Post by Ekamu »

NECROPOST!!!
So I am back on the same project. So far I have managed to get user input into the engine. text loads one character at a time and my code is much much much cleaner from when I started this project. Thanks to all of you for your help!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm working on a simple old school visual novel engine in Lua. Entitled LuNar (Lua Narrative)
7SWJ8.png
7SWJ8.png (5.82 KiB) Viewed 445 times
Download Link: http://www.mediafire.com/download/aa07v ... rv0.2.love
Controls:
Right = go to the next page
Left = go to previous page
Up = skip text
Down = go to title page
keys(small case letters) = input word into command prompt
backspace = delete word

Give it a little test, so far its perfect. (although a little primitive)

Basically I have most of the code set up besides one important feature. The Text Parser/Verb-Noun Parser.

Lets get into how words are generally structured. In the screenshot I input the command "my wish is for you to die"
How would a human understand this?
my = noun/object
wish = verb
is = connective_equator similar to =
for = connective_object (for all objects of ..)
you = noun/object
to = connective_action similar to do...end
die = verb

the computer can then parse this and understand it like this (pseudo example)
my = user
you = get_current_label()
you = "Lost Coatl"
wish = user_command

(therefor) user_command = for all_objects of "Lost Coatl" do die() end
execute user_command()

The parser is not yet running. I'm currently reviewing what Roland_Yonaba said a year ago (^_^)

My code for the command console is like this in love.keypressed

Code: Select all

	if text.vis then --if the text box is visible then
	--enter user input
        if key and key:match('^[%w%s]$') then --pattern to match and find all letters with key pressed
	        if text.input:len() < 31 then --limit to 31 characters (length of text box)
                text.input = text.input..key 
	        end
        end
	--delete user input
        if key == "backspace" then
            text.input = text.input:sub(1, -2) 
        end
	end
I am thinking of storing text.input in an anonymous variable user_input when the user hits enter
then later parse a database with user_input.

I think there is a table matching function like this

Code: Select all

function map(t,f)
  for i=1, #t do 
  return f(t[i])
  end
end
which iterates through all values in a table and then performs the function returning its value

I could be corrected/guided a little. I dream for this parser to work like real English and eventually have a conversation with AI
(maybe another few years later or a very very DISTANT NECROPOST in the future! \(>0<)/ )

For now though, I'm a bit stumped on matching tables with user input or if this is even the right approach at all
(seems data heavy or not you tell me)
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Verb-Noun Parser

Post by ejmr »

Ekamu wrote:Basically I have most of the code set up besides one important feature. The Text Parser/Verb-Noun Parser.

Lets get into how words are generally structured. In the screenshot I input the command "my wish is for you to die"

How would a human understand this?

my = noun/object
wish = verb
is = connective_equator similar to =
for = connective_object (for all objects of ..)
you = noun/object
to = connective_action similar to do...end
die = verb
There are two problems with this. The first is that the breakdown of the sentence is grammatically incorrect.
  • My: Possessive adjective.
  • Wish: Noun, subject.
  • Is: Copula, linking verb.
  • For: Preposition.
  • You: Pronoun, prepositional complement.
  • To die: Verb, infinitive.
The last item in the list demonstrates the second problem. We often interpret sentences by breaking them down into word phrases, not individual words. For example, English speakers hear 'my wish' as one noun. Then after hearing 'is' people will immediately assume the sentence is going to fit the mold of A is B where 'B' is a predicative nominal. The rest of the sentence follows that pattern but, again, people would not mentally parse it as four individual words. For example, since the predicative nominal requires a noun people will think of 'to die' as one unit; that 'to' is necessary for the verb to appear in the position of a noun and cannot and should not be separate. Many other languages express the infinitive as a single word, and attempting to divide the word into smaller pieces leads to nonsense. Likewise, in English we cannot meaningfully split 'to die' into two words; the fact that we write the infinitive using two words does not mean we can arbitrarily separate them, as the infinitive is an unbreakable unit.

The take away here is that the parser should be somewhat aware of the fact that we think about most sentences in terms of phrases, not individual words. This line of thinking will not only more closely reflect actual English usage, it will also help ease the challenge of the natural language processing you seem to want to do, a daunting task. Personally I would suggest building a set of grammatical patterns like Subject is Adjective, Subject is Noun, Subject Stative-Verb Dynamic-Verb-Infinitive (e.g. 'I want to run'), and then try matching the player’s input to the longest pattern it follows. That would require tagging all words the game’s lexicon with their potential grammatical purposes, e.g. 'wish' can be a noun or dynamic verb or stative verb.

Alternatively, instead of doing all that to correctly parse arbitrary English input you could instead relax the grammatical patterns so that they accept phrases which omit certain components. An example would be treating 'open door' as if it had a subject and an article, e.g. 'I open the door'. Very old adventure games would do this.

Or finally, just drop the idea of parsing English. Off the top of my head I cannot think of a visual novel which accepts arbitrary language input. I’ve been working on a visual novel engine myself and that is challenging enough. To add natural language processing on top of that sounds like too much in my opinion. So I suggest either encouraging and accepting broken sentences as input or restructure input as something like a menu choice, because trying to parse all forms of English grammar is a task which would take years to get close to correct.

All that said, good luck with your project. I enjoy this subject and would love to play more games like RPGs that allowed free-form input. But the design and implementation of such a system is the type of things people do to get a Ph.D., not to make a visual novel.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Verb-Noun Parser

Post by Ekamu »

Image
Download Link: http://www.mediafire.com/download/r444p ... rv0.3.love

I have an table user_data to catch all strings and numbers in order and store them (for later parsing)

you can not input any capitals or symbols into the command prompt so the game lexicon (wordstock) should be simpler

As you said that sort of thing is way too advanced, sometimes I like to dream about impossible things but I'm very aware that its something I cant achieve any time soon (and is also very unnecessary).

Lua tables have no limit which is a good and bad (overflow), but the command prompt is limited to 31 characters so I don't think I need to worry about it.

Thanks, good luck to you to.
about visual novel engines, is it possible to link me to your project so I can learn a few things myself?
(which as I know now are not entirely simple but doable at my level)

sorry for the crap English example. we speak English a little differently in my country (@_@)
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Verb-Noun Parser

Post by ejmr »

Ekamu wrote:As you said that sort of thing is way too advanced, sometimes I like to dream about impossible things but I'm very aware that its something I cant achieve any time soon (and is also very unnecessary).
Nothing wrong with dreaming big :)

I wanted to apologize for my last post. I wrote it before going to bed and when I look at it now I feel like I came across as blunt and rude. Sorry about that.
Ekamu wrote:Thanks, good luck to you to.
about visual novel engines, is it possible to link me to your project so I can learn a few things myself?
(which as I know now are not entirely simple but doable at my level)
https://github.com/ejmr/LNVL
Ekamu wrote:sorry for the crap English example. we speak English a little differently in my country (@_@)
No need to say ‘sorry’ for anything :)
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Verb-Noun Parser

Post by Ekamu »

You too, no need to say sorry for anything :ultrahappy: actually your advice was very clear although "straight/blunt" I don't take any offense.

Image
You project gives me this error immediately I try to run it. I think I'm missing somefile or something.

I'm done for now with mine for now
http://www.mediafire.com/download/59bd3 ... rv0.4.love
Its not entirely complete but i have all the major things I will need to make a working VN that is complete but simple.

new controls: lctrl or rctrl to input command

the user data is stored in a table, then I have a simple function to return true or false if it matches with some expected input. string_words and string_numbers are checked differently.
(I also limited the table to only store max of 4 words and 2 numbers and reset itself if the user goes to another page to avoid residual data)

Code: Select all

--lexicon comparison
function lex_txt(str,i)--compares user_data string_text
    if user_data.txt[i] == str then
    return true
    else
    return false
    end
end

function lex_num(num,j)--compares user_data string_numbers
    if user_data.num[j] == num then
	return true
	else
	return false
	end
end
So to check for a choice (or any input) you will only need to worry about what the right choice is and what action you want to happen. the rest gets thrown away and into the garbage. (not to worry, you can easily store the data in another permanent variable before its thrown away)

Code: Select all

 --used to check user input text data
if lex_txt("yes",1) then jump("label_yes",0) end --if user inputs yes then jump to the label "label_yes" at page 0

Code: Select all

 --used to store user input e.g players name
if user_data.txt[1] ~= nil then first_name = user_data.txt[1] end -- 1 == first word
if user_data.txt[2] ~= nil then second_name = user_data.txt[2] end --2 == second word
--max of 4 words at a time
Its that simple and direct.

That.s good enough for me, I was thinking of adding in a lexicon_database but its very unnecessary for simple VN games. you only need that sort of thing if keywords are limited and used at any moment in the game like in Lucas Arts style Adventure Games e.t.c where you would mainly use words like "open door" "search table" e.t.c. I could always just get Adventure Game Studios if I was so obsessed with that sort of game-play.

It's funner this way for me, since input can be much more personalized and dependent on particular events/situations rather than parsed entirely by the computer limiting the sort of events I could create on the fly.

I can even "fake" an advanced text parser although using more "brute-force" (lots of custom-multiple looping paths instead of actual computer based logic)

Oh and you/anyone can use my custom made font "LuNar Console Sans Serif" its free!
Image
invert the color in any image editor to get white text (the one I use) this one is more visible on the forums.

\(^_^)/ wow I'm finally "falling" in love with LOVE.
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Verb-Noun Parser

Post by ejmr »

Ekamu wrote:You project gives me this error immediately I try to run it. I think I'm missing somefile or something.
Yeah, you have to copy src/settings.lua.example to src/settings.lua. But even if you did that the example scripts would not run because I still haven’t added the assets they use or rewritten them to use different/free assets.
Oh and you/anyone can use my custom made font "Lunar Console Sans Serif" its free!
Image
invert the color in any image editor to get white text (the one I use) this one is more visible on the forums.
Thanks for sharing :)
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Verb-Noun Parser

Post by DaedalusYoung »

Ekamu wrote:Oh and you/anyone can use my custom made font "LuNar Console Sans Serif" its free!
Image
invert the color in any image editor to get white text (the one I use) this one is more visible on the forums.
That looks pretty good, thanks!
Post Reply

Who is online

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