用于从模型中查找相同属性值的数据日志
我是数据记录新手,想要解决以下问题:
我有一个学生模型
student(name, rollno, city)
现在我想编写一个数据记录程序来查找来自同一城市的一对学生。如果我这样写程序是否正确?
result(n1, r1, c1, n2, r2, c2) :- student(n1, r1,c1) AND student(n2,r2,c2) AND c1= c2
由于 r1
和 r2
在这里并不重要,我可以在头部和主体中用 _
替换它吗?
欢迎任何反馈!
I am new to datalog and want to solve the following:
I have a student
model
student(name, rollno, city)
Now I want to write a datalog program for finding the pair of students that are from the same city. Is it correct if I write the program as following?
result(n1, r1, c1, n2, r2, c2) :- student(n1, r1,c1) AND student(n2,r2,c2) AND c1= c2
As r1
and r2
are not of much importance here can i replace it by _
in the both head and the body?
Any feedback is welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在逻辑右侧使用下划线代替 rollno 是正确的。
我会选择稍微不同的谓词样式来保存结果。我在工作中使用 Datalog 的 LogicBlox 变体进行编写,我认为我们的符号与您的略有不同,但我将这样做......
It is correct to use underscore in place of the rollno in the right-hand side of your logic.
I would have picked a slightly different predicate style to hold the results. I write in the LogicBlox variant of Datalog for work and I think our notation varies from yours a bit, but here is how I would do it...