Prolog Or(;) Rule Return Multiple Result

nicholas picture nicholas · Jul 28, 2010 · Viewed 14.1k times · Source

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.

Answer

Michael Eichberg picture Michael Eichberg · Jul 28, 2010

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.