2010-07-28 60 views
5

我必須定義一個或運營商的規則,但它返回多個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個真/假而不是多個語句。

每個或規則返回1布爾值,這不是我想要檢查了在命令行中的規則後。我需要像這樣(通用規則&(Multiple或Rule))。

怎麼把幾個或規則,返回1個布爾值相結合?

請幫忙。

謝謝。

回答

3

剛好圍繞所有「或」運算與once目標。

例如

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

現在,「or'ed」目標要麼成功要麼失敗。

+1

謝謝。問題解決了。 – peterwkc 2010-07-29 06:01:43

0

首先,你應該把()圍繞你的目標與;相結合。因爲目前它解釋它像customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...)ishouseloan(...),...,iscarloan(...)的分離。這是因爲運營商,;的優先級不同。

其實; - 意味着真正的「或」,「在其他情況下,」不「互斥或」不。因此,如果「房屋」可以與「個人貸款」一起成功,那麼你將擁有多個成功的目標。在這個例子中once/1可以幫助(以及not(not(...))),但你可以嘗試用你的任務更深入的得到序言和指定像非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) 
    ) 
) 

在這如果您的LTAmT尚未綁定到特定值並且這些isXXX可以綁定自由變量,則應該能夠生成所有貸款。