1

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

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

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 岁以上,利息会降低。

请帮忙。

谢谢。

4

2 回答 2

1

添加一个额外的参数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 代码,这样更容易阅读。

于 2010-07-21T11:06:10.263 回答
0

这就是我会做的:

% usage: isInterestOk(+CustomerType, +Interest)
isInterestOk('VIP', Interest) :-
    Interest =< 1000.
isInterestOk('normal', Interest) :-
    Interest =< 500.
于 2010-07-21T06:40:09.377 回答