How to process natural language queries? I'm curious about natural language querying.  Stanford has what looks to be a strong set of software for processing natural language.  I've also seen the Apache OpenNLP library, and the General Architecture for Text Engineering.

There are an incredible amount of uses for natural language processing and that makes the documentation of these projects difficult to quickly absorb.

Can you simplify things for me a bit and at a high level outline the tasks necessary for performing a basic translation of simple questions into SQL?

The first rectangle on my flow chart is a bit of a mystery.

  

For example, I might want to know:

How many books were sold last month?


And I'd want that translated into

Select count(*) 
  from sales 
  where 
   item_type='book' and 
   sales_date &gt;= '5/1/2014' and 
   sales_date &lt;= '5/31/2014'
Natural language querying poses very many intricacies which can be very difficult to generalize.  From a high level, I would start with trying to think of things in terms of nouns and verbs.

So for the sentence: How many books were sold last month?

You would start by breaking the sentence down with a parser which will return a tree format similar to this:



You can see that there is a subject books, a compound verbal phrase indicating the past action of sell, and then a noun phrase where you have the time focus of a month.

We can further break down the subject for modifiers: "how many" for books, and "last" for month.

Once you have broken the sentence down you need to map those elements to sql language e.g.: how many => count, books => book, sold => sales, month => sales_date (interval), and so on.  

Finally, once you have the elements of the language you just need to come up with a set of rules for how different entities interact with each other, which leaves you with:

Select count(*) 
  from sales 
  where 
   item_type='book' and 
   sales_date >= '5/1/2014' and 
   sales_date &lt;= '5/31/2014'

This is at a high level how I would begin, while almost every step I have mentioned is non-trivial and really the rabbit hole can be endless, this should give you many of the dots to connect.