2010-07-21 87 views
1

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

任何想法如何实现这一目标?

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

请帮忙。

谢谢。

回答

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代码,这使得它更容易阅读。

0

这就是我会做:

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

让我来重述一下我的问题。我需要创建一个评估贷款的函数,如果贷款是可以接受的,那么我需要检查它是否有较低的利息提供给这个人。 – peterwkc 2010-07-21 07:21:28