Prolog Or(;) 规则返回多个结果

发布于 2024-09-11 16:25:21 字数 1159 浏览 4 评论 0原文

我已经用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乞讨 2024-09-18 16:25:21

只需用 once 包围所有“或”目标即可。

例如

once(
 ispersonalloan(LoanType,LoanAmount,LoanTenure);
 ishouseloan(LoanType,LoanAmount,LoanTenure);
 isbusinessloan(LoanType,LoanAmount,LoanTenure);
 iscarloan(LoanType,LoanAmount,LoanTenure)
).

,现在,“or'ed”目标要么成功,要么失败。

Just surround all your "or'ed" goals with once.

e.g.

once(
 ispersonalloan(LoanType,LoanAmount,LoanTenure);
 ishouseloan(LoanType,LoanAmount,LoanTenure);
 isbusinessloan(LoanType,LoanAmount,LoanTenure);
 iscarloan(LoanType,LoanAmount,LoanTenure)
).

Now, the "or'ed" goals either succeed or fail.

窗影残 2024-09-18 16:25:21

首先,您应该将 () 放在目标周围,并与 ; 结合使用。因为目前它会将其解释为 customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...), ishouseloan(...)< 的析取/code>, ..., iscarloan(...)。这是因为运算符; 的优先级不同。

实际上 ; - 表示真正的“或”,而不是“互斥或”,也不是“在其他情况下”。因此,如果“ishouseloan”能够与“ispersonalloan”一起成功,那么您将有几个成功的目标。在此示例中,once/1 可能会有所帮助(以及 not(not(...))),但您可以尝试让 prolog 更深入地了解您的任务并指定 non -everlapping 目标,例如(我对重叠 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)
    )
  )

在这种情况下,当您的 LTAm 和 T 尚未绑定到特定值,这些 isXXX 可以绑定自由变量。

First of all you should put ( and ) around your target combined with ;. Because currently it interprets it like disjunction of customer(...),...,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 example once/1 may help (as well not(not(...))), but you can try to get prolog deeper with your task and specify non-everlapping targets like (I do some personal assumptions about overlapping 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)
    )
  )

In this case you should be able to generate all loans when your LT, Am and T is not yet bound to specific values and those isXXX can bind free variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文