英文:
Souffle query returning zero results
问题
我正在编写一个在家庭关系上操作的[Souffle](https://souffle-lang.github.io/)查询:
.decl Parent(x: symbol, y: symbol)
.input Parent
.decl Descendant(x: symbol, y: symbol)
.output Descendant
.printsize Descendant
Descendant(x, y) :- Parent(x, y).
Descendant(x, y) :- Parent(z, y), Descendant(x, z).
.decl Qslow(x: symbol)
.output Qslow
.printsize Qslow
Qslow(x) :- Descendant("Alice", x).
我有一些事实在一个TSV文件`Parent.facts`中:
"Alice" "john"
"john" "mary"
"mary" "elizabeth"
"Bob" "charles"
运行`souffle`似乎为`Descendant`关系生成了正确的输出(对于"Alice"有三个后代):
hickory% souffle -F. -D. descendants.dl
Descendant 7
Qslow 0
hickory%
然而,`Qslow`产生了**零**结果。我本来希望有**三**个结果。这让我怀疑`Qslow`的定义,但我不确定问题是什么。我是否在符号语法上做了一些奇怪的事情?看起来我使用的语法与[文档中的](https://souffle-lang.github.io/types#float-type)相同。
如果我尝试在连接中添加另一个子句,仍然会得到零结果:
Qslow(x) :- Descendant(y, x), y="Alice".
<details>
<summary>英文:</summary>
I am writing a [Souffle](https://souffle-lang.github.io/) query that operates on family relationships:
.decl Parent(x: symbol, y: symbol)
.input Parent
.decl Descendant(x: symbol, y: symbol)
.output Descendant
.printsize Descendant
Descendant(x, y) :- Parent(x, y).
Descendant(x, y) :- Parent(z, y), Descendant(x, z).
.decl Qslow(x: symbol)
.output Qslow
.printsize Qslow
Qslow(x) :- Descendant("Alice", x).
I have some facts in a TSV file `Parent.facts`:
"Alice" "john"
"john" "mary"
"mary" "elizabeth"
"Bob" "charles"
And running `souffle` seems to generate the right output for the `Descendant` relation (three descendants for "Alice"):
hickory% souffle -F. -D. descendants.dl
Descendant 7
Qslow 0
hickory%
However, `Qslow` produces **zero** results. I would instead expect **three** results. This makes me suspicious of the definition of `Qslow`, but I am not sure what the issue is. Am I doing something weird with symbol syntax? It looks like I am using the same syntax as [in the docs](https://souffle-lang.github.io/types#float-type).
If I try adding another clause to the conjunction, I still get zero results:
Qslow(x) :- Descendant(y, x), y="Alice".
</details>
# 答案1
**得分**: 2
您已经在错误的数据格式中指定了文件 `Parent.facts`。它应该是
```Alice john
john mary
mary elizabeth
Bob charles
不带双引号,并且使用制表符来分隔元组的元素。程序中只有事实使用双引号。
英文:
You have specified the file Parent.facts
in the wrong data format. It should be
john mary
mary elizabeth
Bob charles
without double quotes and tabs to separate elements of tuples. Only facts in the program use double-quotes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论