Prolog Or(;) 规则返回多个结果
我已经用 or 运算符定义了一个规则,但它返回多个 true 或 false。
isloanaccept(Name,Guarantor,LoanType,LoanAmount,LoanTenure)
:- customer(Name,bank(_),customertype(_),
citizen(Ci),age(Age),credit(C),
income(I),property(_),bankemployee(_)),
Ci == 'malaysian',
Age >= 18,
C > 500,
I > (LoanAmount / LoanTenure) / 12,
isguarantor(Guarantor,Name),
ispersonalloan(LoanType,LoanAmount,LoanTenure);
ishouseloan(LoanType,LoanAmount,LoanTenure);
isbusinessloan(LoanType,LoanAmount,LoanTenure);
iscarloan(LoanType,LoanAmount,LoanTenure).
实际上,我需要检查贷款类型是否满足特定的贷款要求并结合一般规则。
换句话说,我需要像这样定义上面的规则。
Ci == 'malaysian', Age >= 18,C > 500,
I > (LoanAmount / LoanTenure) / 12,
isguarantor(Guarantor,Name)
Or with (ispersonalloan(LoanType,LoanAmount,LoanTenure);
ishouseloan(LoanType,LoanAmount,LoanTenure);
isbusinessloan(LoanType,LoanAmount,LoanTenure);
iscarloan(LoanType,LoanAmount,LoanTenur)
它应该返回 1 个真/假,而不是命令行中的多个语句。
每个 or 规则返回 1 个布尔值,这在检查命令行中的规则后不是我想要的。我需要这样(一般规则和(多个或规则))。
如何组合多个返回 1 布尔值的规则?
请帮忙。
谢谢。
i have define a rule with or operator but it return multiple true or false.
isloanaccept(Name,Guarantor,LoanType,LoanAmount,LoanTenure)
:- customer(Name,bank(_),customertype(_),
citizen(Ci),age(Age),credit(C),
income(I),property(_),bankemployee(_)),
Ci == 'malaysian',
Age >= 18,
C > 500,
I > (LoanAmount / LoanTenure) / 12,
isguarantor(Guarantor,Name),
ispersonalloan(LoanType,LoanAmount,LoanTenure);
ishouseloan(LoanType,LoanAmount,LoanTenure);
isbusinessloan(LoanType,LoanAmount,LoanTenure);
iscarloan(LoanType,LoanAmount,LoanTenure).
Actually, i need to check whether the loan type is fulfill the particular loan requirement and combine with general rule.
In other words, i need to define the rule above like this.
Ci == 'malaysian', Age >= 18,C > 500,
I > (LoanAmount / LoanTenure) / 12,
isguarantor(Guarantor,Name)
Or with (ispersonalloan(LoanType,LoanAmount,LoanTenure);
ishouseloan(LoanType,LoanAmount,LoanTenure);
isbusinessloan(LoanType,LoanAmount,LoanTenure);
iscarloan(LoanType,LoanAmount,LoanTenur)
It should return 1 true/false rather than multiple statement in the command line.
Each of the or rule return 1 boolean value which is not i want after have checked the rule in command line. I need to have like this (General Rule & (Multiple Or Rule) ).
How to combine several or rule which return 1 boolean value ?
Please help.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需用
once
包围所有“或”目标即可。例如
,现在,“or'ed”目标要么成功,要么失败。
Just surround all your "or'ed" goals with
once
.e.g.
Now, the "or'ed" goals either succeed or fail.
首先,您应该将
(
和)
放在目标周围,并与;
结合使用。因为目前它会将其解释为customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...)
,ishouseloan(...)< 的析取/code>, ...,
iscarloan(...)
。这是因为运算符、
和;
的优先级不同。实际上
;
- 表示真正的“或”,而不是“互斥或”,也不是“在其他情况下”。因此,如果“ishouseloan”能够与“ispersonalloan”一起成功,那么您将有几个成功的目标。在此示例中,once/1
可能会有所帮助(以及not(not(...))
),但您可以尝试让 prolog 更深入地了解您的任务并指定 non -everlapping 目标,例如(我对重叠isXXX
做了一些个人假设):在这种情况下,当您的
LT
、Am 和
T
尚未绑定到特定值,这些isXXX
可以绑定自由变量。First of all you should put
(
and)
around your target combined with;
. Because currently it interprets it like disjunction ofcustomer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...)
,ishouseloan(...)
, ...,iscarloan(...)
. That's because different priorities of operators,
and;
.Actually
;
- means real "or", not "mutual exclusive or" and not "in other case". So if "ishouseloan" can' succeed together with "ispersonalloan" than you'll have several successful targets. In this exampleonce/1
may help (as wellnot(not(...))
), but you can try to get prolog deeper with your task and specify non-everlapping targets like (I do some personal assumptions about overlappingisXXX
):In this case you should be able to generate all loans when your
LT
,Am
andT
is not yet bound to specific values and thoseisXXX
can bind free variables.