2017-04-13 328 views
9

免责声明:以前可能会被问到,但找不到可以适合账单的东西。我最接近的是Automatic SQL query formulation from natural language input自然语言转换为sql(来自示例),从示例学习sql

我解决问题的方式稍有不同。

我有一个非常大的自然语言语句和它涉及到的(sql)查询字典。所有这些都在我的“域名”中。 例如,下面的(虚拟)语句可以作为一个例子:

("How many managers on the first floor?") -> 
     SELECT count(*) from tbl.managers where desk_floor = 1; 

("How many people in today?", 
"What is the attendance today?", 
"How many people walked in the door today") -> 
     SELECT count(*) from tbl.checkins where date={today}; 

("When is the next bank holiday?" 
    "When will the office be closed for the next bank holiday") -> 
     SELECT top 1 holiday_on from tbl.holidays where holiday_on > {today} order by 1; 

等。现在,我可以坐下来喝一杯非常大的咖啡,并开始设置语法,查找和域方法(如quepy中所做的),以允许变化或尝试回答不属于训练集的查询,但可以从部分现有的数据集。所以鉴于上面的数据集可以问,有些东西是这样的:

"How many managers on the first floor are in today?" 

我们不能训练一个“解释器”来为我们做这个。有没有任何例子或出版物暗示这一点?

ps:如果它帮助我使用python的任何人,但我不是特别寻找代码。

回答

2