用于从模型中查找相同属性值的数据日志

发布于 2024-12-20 10:13:49 字数 361 浏览 1 评论 0原文

我是数据记录新手,想要解决以下问题:

我有一个学生模型

student(name, rollno, city)

现在我想编写一个数据记录程序来查找来自同一城市的一对学生。如果我这样写程序是否正确?

result(n1, r1, c1, n2, r2, c2) :- student(n1, r1,c1) AND student(n2,r2,c2) AND c1= c2

由于 r1r2 在这里并不重要,我可以在头部和主体中用 _ 替换它吗?

欢迎任何反馈!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2024-12-27 10:13:49

在逻辑右侧使用下划线代替 rollno 是正确的。

我会选择稍微不同的谓词样式来保存结果。我在工作中使用 Datalog 的 LogicBlox 变体进行编写,我认为我们的符号与您的略有不同,但我将这样做......

student(name, rollno, city) -> string(name), string(rollno), string(city).

studentsPairsFromSameCity(nameA, nameB, city) -> string(nameA), string(nameB), string(city).

studentPairsFromSameCity(nameA, nameB, city)
<-
   student(nameA, _, cityA),
   student(nameB, _, cityB),
   nameA != nameB,
   cityA = cityB.

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...

student(name, rollno, city) -> string(name), string(rollno), string(city).

studentsPairsFromSameCity(nameA, nameB, city) -> string(nameA), string(nameB), string(city).

studentPairsFromSameCity(nameA, nameB, city)
<-
   student(nameA, _, cityA),
   student(nameB, _, cityB),
   nameA != nameB,
   cityA = cityB.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文