Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog Or(;) Rule Return Multiple Result

Tags:

prolog

rule

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.

like image 325
nicholas Avatar asked Jul 28 '10 03:07

nicholas


People also ask

What are rules in Prolog give example?

A rule in Prolog is a clause, normally with one or more variables in it. Normally, rules have a head, neck and body, as in: eats(Person, Thing) :- likes(Person, Thing), food(Thing). This says that a Person eats a Thing if the Person likes the Thing , and the Thing is food .


1 Answers

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.

like image 141
Michael Eichberg Avatar answered Oct 12 '22 23:10

Michael Eichberg