Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL queries to their natural language description

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.

like image 641
bellpeace Avatar asked Jun 03 '13 05:06

bellpeace


1 Answers

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:

  • http://www.sqlparser.com/sql-parser-java.php
  • https://github.com/facebook/presto/tree/master/presto-parser/src/main
  • http://db.apache.org/derby/

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/

like image 176
Josep Valls Avatar answered Sep 29 '22 06:09

Josep Valls