command : verb verbLiteral? freeText?
| verb freeText (verbLiteral freeText)?
noun : article? (adjective (conjunction adjective)*)? noun (nounPrep nounDescriptor (conjunction nounDescriptor)*)?
noun: king [
prep: with [
descriptor: beard ]
prep: with [
descriptor: axe ]
]
noun1: king
noun2: beard [
prep: with [
descriptor: axe ]
]
noun1: king [
prep: with [
descriptor: beard ]
]
noun2: axe
Right now, the parser uses a very basic expression-based command table and substring-based object binder that works something like this:
Obviously, that was a quick and dirty hack for getting something I could play around with. Now that I've come back to the parser, I've been exploring some more complex parsing options. I'd like to end up with a parser that can successfully bind expressions like:
"hit the king with the third rock"
"take five monkies from the cage"
"put the sword of ice into my backpack"
"dance with the monkey from madagascar"
I've gotten very close by using a vocabulary that auto-generates from my entities' name and adjective fields to parse the input lines into a tree structure that holds information about the part of speech that each token in the input stream maps to. My problem is that I keep running down rabbit holes when I try and resolve ambiguity introduced by allowing prepositions to modify the nouns as well as the verbs. "the king with a beard", for example, causes massive issues with a command like "hit <living> with <weapon>". If the player types "hit the king with a beard with my sword", should we hit "the king" with "a beard with my sword", or should we hit "the king with a beard" with "my sword"?
So, finally to my question: Has anyone here played with NLP-style parsers in their own work, and if so, where do you draw the line on the breadth of the grammar that's accepted by your parser? Should I discard the idea of allowing arbitrary prepositional phrases in the input, and restrict the grammar to only allowing prepositions to be part of a command definition, or is there a middle ground that is generally accepted? Or am I completely missing the boat somewhere along the line and just don't see it?
Any ideas or commentary would be appreciated. Thanks!
(EDIT: Added example of why "king with a beard" poses a parsing problem for me.)