I'm trying to develop a Natural Language Interfaces to Database, and I'm just wondering if there is a library or an API (Java) that I can use to convert a question (interrogative sentence) to a command (imperative sentence).
Ex : from "Which employees were born before 1970?" to "Get employees born before 1970."
This is a rather complex and non-trivial issue. However if your domain is limited (employee database queries, etc.) and you only expect a limited set of utterances as an input you could build a simple rule-based system.
The simpliest solution would be to develop a set of regular expression-based transformation rules. E.g. assume that the word appearing after (was|were) is the verb. You could keep a dictionary of all frequent verbs and their mappings to your database fields. Here "born" would be mapped to a field that could be called DATE_OF_BIRTH for instance.
A more sophisticated rule-based solution would be to find or build a parser for the language of your choice and perform the conversion based on the parser output and your rule base. E.g. The parser would output what is the sentence predicate, subject, etc. You would have a set of rules that would rearrange those parts of sentences to produce an imperative structure.
If you hate the idea of developing a rule base manually you could always try the machine learning approach and train a statistical system. Here you need to develop a question database that covers most question types you could be expecting) and train a statistical model on it.
If I was to suggest a single library/tool for experimenting with any of the above approaches I would say OpenNLP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With