如何获取 Prolog 中的对象列表
当我在解决一些序言练习时,我发现自己在解决以下问题时遇到了一些困难: 考虑你有关于对象的事实基础:
object(obj1).
object(obj2).
object(obj3).
object(obj4).
object(obj5).
material(obj1,wood).
material(obj2,wood).
material(obj3, glass).
material(obj4, glass).
material(obj5, iron).
type(obj1, able).
type(obj2, chair).
type(obj3, mesa).
type(obj4, jar).
type(obj5, rattle).
weight(obj1, 10.5).
weight(obj2, 1.5).
weight(obj3, 1.6).
weight(obj4, 0.5).
weight(obj5, 1.8).
现在的想法是创建谓词 object_description(List),其中 List 是每个对象与其特征的连接,类似于:
([obj1-wood-table-10.5, obj2-wood-chair-1.5, …, obj5-iron-rattle-1.8] )
我尝试使用 bagof 和 findall 但找不到正确的答案。
提前谢谢
I was resolving some prolog exercises when I fond myself with some difficulties resolving the following one:
Consider you have this fact base about object:
object(obj1).
object(obj2).
object(obj3).
object(obj4).
object(obj5).
material(obj1,wood).
material(obj2,wood).
material(obj3, glass).
material(obj4, glass).
material(obj5, iron).
type(obj1, able).
type(obj2, chair).
type(obj3, mesa).
type(obj4, jar).
type(obj5, rattle).
weight(obj1, 10.5).
weight(obj2, 1.5).
weight(obj3, 1.6).
weight(obj4, 0.5).
weight(obj5, 1.8).
Now the idea is to make the predicate object_description(List) where List is the joining of each object with it's caracteristics, something like:
([obj1-wood-table-10.5, obj2-wood-chair-1.5, …, obj5-iron-rattle-1.8] )
I tried using bagof and findall but couldn't find the right answer.
Thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我改变了输入格式。现在搜索起来容易一些。
我希望这样就可以了。
给定这种输入格式,您现在可以将其映射到一个(列表)列表,例如:
这不会产生问题中的确切输出格式,但确实给出了类似的内容(并且可能更容易进一步处理)。
用法:
I've changed the input format. It's a little easier to search now.
I hope it's OK like this.
Given this input format you can now map it to a list (of lists) e.g. like this:
This doesn't produce the exact output format that you have in the question, but does give something similar (and maybe easier to process further).
Usage: