Prolog 组合规则

发布于 2024-09-11 01:55:04 字数 451 浏览 3 评论 0原文

我需要编写一条由子规则组成的规则。

知道如何实现这一目标吗?

isloanaccept(Name, LoanAmount, LoanTenure) 
:-  customer(Name, bank(_),customertype(_),
    citizen(malaysian),age(Age),credit(C),
    income(I),property(car|house)), 
    Age >= 18,
    C > 500, 
    I > (LoanAmount / LoanTenure) / 12.
lowerinterest(Senior) :- isseniorcitizen(Senior).

例如,我需要检查客户类型。 如果客户类型是 VIP,则利息较低。 如果年龄超过60岁,利息会降低。

请帮忙。

谢谢。

i need to write a rule which consists of sub rule.

Any idea how to achieve this ?

isloanaccept(Name, LoanAmount, LoanTenure) 
:-  customer(Name, bank(_),customertype(_),
    citizen(malaysian),age(Age),credit(C),
    income(I),property(car|house)), 
    Age >= 18,
    C > 500, 
    I > (LoanAmount / LoanTenure) / 12.
lowerinterest(Senior) :- isseniorcitizen(Senior).

For instance, i need to check the customer type .
If customer type is VIP, interest lower.
If age is above 60, interest lower.

Please help.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

涫野音 2024-09-18 01:55:04

isloanaccept 添加额外的参数可能是最简单的方法。

isloanaccept(Name, LoanAmount, LoanTenure, Interest) :-
    customer(Name, bank(_), customertype(Type), citizen(malaysian), age(Age),
             credit(C), income(I), property(car|house)), 
    Age >= 18,
    C > 500,
    I > (LoanAmount / LoanTenure) / 12,
    interest(Age, Interest).

% Interest depending on age and customertype; add parameters, or pass in a list,
% to have interest determined by other factors
interest(Age,Type,Interest) :-
    (senior_citizen(Age) ->
        Interest = 0.05
    ; Type = vip ->
        Interest = 0.07
    ;
        Interest = 0.10
    ).

PS.:请尝试以这种方式格式化 Prolog 代码,这样会更容易阅读。

Adding an extra argument to isloanaccept is probably the easiest way.

isloanaccept(Name, LoanAmount, LoanTenure, Interest) :-
    customer(Name, bank(_), customertype(Type), citizen(malaysian), age(Age),
             credit(C), income(I), property(car|house)), 
    Age >= 18,
    C > 500,
    I > (LoanAmount / LoanTenure) / 12,
    interest(Age, Interest).

% Interest depending on age and customertype; add parameters, or pass in a list,
% to have interest determined by other factors
interest(Age,Type,Interest) :-
    (senior_citizen(Age) ->
        Interest = 0.05
    ; Type = vip ->
        Interest = 0.07
    ;
        Interest = 0.10
    ).

PS.: Please try to format Prolog code this way, that makes it a lot easier to read.

记忆消瘦 2024-09-18 01:55:04

这就是我要做的:

% usage: isInterestOk(+CustomerType, +Interest)
isInterestOk('VIP', Interest) :-
    Interest =< 1000.
isInterestOk('normal', Interest) :-
    Interest =< 500.

That's what I would do:

% usage: isInterestOk(+CustomerType, +Interest)
isInterestOk('VIP', Interest) :-
    Interest =< 1000.
isInterestOk('normal', Interest) :-
    Interest =< 500.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文