【发布时间】:2019-05-21 15:21:35
【问题描述】:
我知道 Prolog 不是一种面向对象的语言,在阅读了一些 StackOverflow 帖子后,我并不清楚这是否可行,但我想我还是会问:
如果Customer 有并且只有name(原子字符串)和age(整数),是否可以要求Prolog 给出一些Customer 字典的示例,给出可能的列表names 和 age 范围?实际使用将对字典值有广泛的限制。
例如,理想情况下我想要这样的东西
between(18, 60, Customer.age),
member(Customer.name, [jodie, tengyu, adiche, tomoyo, wolfgang]),
Customer = whatisthis{age: What, name: Wot}.
给我类似的东西
Customer = whatisthis{age: 24, name: tomoyo} ;
Customer = whatisthis{age: 55, name: tengyu} ;
...
...
【问题讨论】:
-
通常情况下,只需使用
customer(tomoyo, 24). customer(tengyu, 55).填充数据库,然后使用customer(Name, Age).进行查询。 SWI 确实有 dictionaries,如果你需要面向对象的 Prolog,总是有 Logtalk。 -
@DanielLyons 问题是我没有像数据库那样有限的基本事实。换句话说,这些
Customers 实际上并不存在,所以customer(tomoyo, 24)在逻辑上不会是一个基本事实。相反,我正在生成所有可能的Customers。 -
customer(Name, Age) :- member(Name, [jodie, tengyu, adiche...]), between(18, 60, Age).不是随机的,而是给你一堆东西。 -
所以基本上把神经网络的用例放在一边,你想要生成大量数据,但要在给定的约束范围内,并且对 Prolog 是否可以做到这一点感兴趣。答案是肯定的,使用 Prolog 的方式是真正的问题。使用 Daniel 指出的自定义编写生成器,使用 Prolog 单元测试 forall ,使用 constraints 和/或 Markov chains 只是我能想到的。
-
Constraints 抱歉之前评论中的链接错误。 5 分钟后无法更换 cmets。
标签: functional-programming prolog swi-prolog data-generation