Prolog:简单的日期范围选择规则 [英] Prolog: Simple date range selection rule
问题描述
我对这个问题有点困惑 - 编写一个规则,其中给定两个人 A
和 B
和一个日期 D
返回列表A
和 B
交换消息到 D
的所有日期.
I am a bit stuck on this question - Write a rule where given two people A
and B
and a date D
returns the list of all dates of when A
and B
have exchanged messages until date D
.
到目前为止我有这个,但我不知道我哪里出错了.
I have this so far but I don't know where I am going wrong.
mexchanged(A,B,D) :- message(A,B,D1), D > D1.
其次,我完全坚持这一点 - 编写一个规则,计算事实数据库中每个人发送的消息数量.
And secondly, I am completely stuck on this - Write a rule that counts the number of messages sent for each person in a database of facts.
我该如何编写这些规则?
How do I write these rules?
对不起,我之前忘记发布这些了;这些只是一些事实.
edit: sorry I forgot to post these before;, these are few of the facts.
message(ben, tom, '20-03-2011').
message(kim, james, '17-11-2011').
message(ben, kim, '06-12-2011').
message(harry, jacky, '29-09-2011').
message(barry, chin, '06-01-2011').
推荐答案
你其实并没有那么远,只是我不知道 G
在这里代表什么:
You are actually not that far off, except I have no idea what G
is representing here:
message(hunter, user3147584, '12-30-2013').
message(hunter, mom, '12-29-2013').
message(hunter, user3147584, '12-28-2013').
% predicate to test for exchanged messages
mexchanged(A,B,D) :- message(A,B,D1), D @> D1 ;
message(B,A,D1), D @> D1 .
% example
mexchanged(hunter, user3147584, '12-29-2013').
% output = true
这篇关于Prolog:简单的日期范围选择规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!