6

Are there any open source tools that can generate a natural language description of a given SQL query? If not, some general pointers would be appreciated.

I don't know much about NLP, so I am not sure how difficult this is, although I saw from some previous discussion that the vice versa conversion is still an active area of research. It might help to say that the SQL tables I will be handling are not arbitrary in any sense, yet mine, which means that I know exact semantics of each table and its columns.

zpavlinovic
  • 1,507
  • 1
  • 17
  • 36
  • [Dr Codd](http://en.wikipedia.org/wiki/Edgar_F._Codd) would be turning in his grave! He designed SQL to be close to natural english :-) – Preet Sangha Jun 03 '13 at 05:58
  • I know :) However, I need a simple and succinct representation of what an SQL query does, so I can show it to non-experts. Natural language seemed appropriate. – zpavlinovic Jun 03 '13 at 06:03
  • 2
    Natural language would be VERY ambitious I'd imagine if only due to the huge number of corner cases. The best you're likely to be able to get would be the original SQL statement with business friendly column and table names (perhaps using views to hide the implementation details). – Steve Homer Jun 03 '13 at 14:03
  • Interesting. So, do you see any obstacles if I provide NL description for queries that fit some restricted format I impose. Generally, what would be those corner cases? – zpavlinovic Jun 03 '13 at 18:54
  • NLP is a broad field that deals with everything natural-language related but typically implies the source is natural language. In this case it seems this is related to natural language generation (NLG) a related field. – Josep Valls Jun 28 '15 at 21:10

2 Answers2

1

I can devise two approaches:

  • SQL was intended to be "legible" to non-technical people. A naïve and simpler way would be to perform a series of replacements right on the SQL query: "SELECT" -> "display"; "X=Y" -> "when the field X equals to value Y"... in this approach, using functions may be problematic.
  • Use a SQL parser and use a series of templates to realize the parsed structure in a textual form: "(SELECT (SUM(X)) (FROM (Y)))" -> "(display (the summation of (X)) (in the table (Y))"...

ANTLR has a grammar of SQL you can use: https://github.com/antlr/grammars-v4/blob/master/sqlite/SQLite.g4 and there are a couple SQL parsers:

Parsing is a core process for executing a SQL query, check this for more information: https://decipherinfosys.wordpress.com/2007/04/19/parsing-of-sql-statements/

Josep Valls
  • 5,483
  • 2
  • 33
  • 67
0

There is a new project (I am part of) called JustQuery.Me which intends to do just that with NLP and google's SyntaxNet. You can go to the https://github.com/justquery-me/justqueryme page for more info. Also, sign up for the mailing list at justqueryme-development@googlegroups.com and we will notify you when we have a proof of concept ready.

  • while this is an interesting project, it translates natural language to SQL, instead of SQL to natural language. – MovGP0 Sep 12 '22 at 13:25