Skip to main content

Logicform 简介

Logicform 是一个 JSON 格式的数据库查询中间表达。用于架起自然语言和各数据库查询语言的桥梁。

BI 所有的问答都是先由文字转化成 Logicform。然后再由 Logicform 转化成相应的数据库语言。

开发者可以通过 Ask API 来将自然语言转化成 Logicform,然后使用 Logicform API 来执行 Logicform,得到数据结果。

一个简单的 Logicform 的结构如下:

{
"schema": "xxx",
"query": {
"key": "value"
}
}

以上 Logicform 翻译成 SQL 的话,如下:

SELECT * from xxx where key = 'value'

一个略微复杂的 Logicform 如下:

{
"schema": "xxx",
"query": {
"key": {
"$gte": 2
},
"key2": {
"schema": "xxx2",
"operator": "$sum",
"pred": "pred1"
}
},
"groupby": ["group1", "group2"],
"preds": [
{ "operator": "$sum", "pred": "p", "name": "p" },
{ "operator": "$count", "name": "c" }
],
"sort": { "c": -1 },
"limit": 3
}

以上 Logicform 翻译成 SQL 的话,如下:

SELECT
sum(p) AS p,
count(0) AS c
FROM xxx
WHERE
key >= 2 AND
key2 = (SELECT sum(pred1) FROM xxx2)
GROUP BY group1, group2
ORDER BY c DESC
LIMIT 3

详细的 Logicform 教程,请看各子章节。