我用或运算符定义了一个规则,但它返回多个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个true / false而不是多个语句。
在命令行中检查规则后,每个或者规则返回1布尔值,这是我想要的。我需要这样(一般规则&(多重或规则))。
如何组合返回1个布尔值的几个或规则?
请帮忙。
感谢。
答案 0 :(得分:3)
用once
围绕所有“或”目标。
e.g。
once(
ispersonalloan(LoanType,LoanAmount,LoanTenure);
ishouseloan(LoanType,LoanAmount,LoanTenure);
isbusinessloan(LoanType,LoanAmount,LoanTenure);
iscarloan(LoanType,LoanAmount,LoanTenure)
).
现在,“或”目标成功或失败。
答案 1 :(得分:0)
首先,您应该将(
和)
放在目标上并与;
结合使用。因为它目前将其解释为customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...)
,ishouseloan(...)
,...,iscarloan(...)
的分离。这是因为运营商,
和;
的优先级不同。
实际上;
- 意味着真实的“或”,而不是“相互排斥或”,而不是“在其他情况下”。因此,如果“ishouseloan”可以“与'ispersonalloan'一起成功”,那么你将拥有几个成功的目标。在此示例中,once/1
可能有所帮助(以及not(not(...))
),但您可以尝试更深入地了解您的任务并指定非常规目标,例如(我对重叠{{1}做一些个人假设}):
isXXX
在这种情况下,当isloan(LT, Am, T):-
(ishouseloan(LT,Am,T)
;iscarloan(LT,AM,T)
;not((ishouseloan(LT,Am,T);iscarloan(LT,AM,T))),
(ispersonalloan(LT,Am,T)
;isbusinessloan(LT,Am,T)
)
)
,LT
和Am
尚未绑定到特定值并且T
可以免费绑定时,您应该能够生成所有贷款变量