tags:

views:

37

answers:

2

Hello to all, 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.

A: 

Just surround all your "ored" 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.

Michael Eichberg
Thanks. Problem solved.
peterwkc
A: 

First of all you should put ( and ) around your target combined with ;. Because currently it interprets it like disjunction of customer(...),...,isguarantor(Guarantor,Name), ispersonalloan(...), ishouseloan(...), ..., iscarloan(...). That's because different priorities of operators , and ;.

Actually ; - means real "or", not "mutual exclusive or" and not "in other case". So if "ishouseloan" can' succeed together with "ispersonalloan" than you'll have several successful targets. In this example once/1 may help (as well not(not(...))), but you can try to get prolog deeper with your task and specify non-everlapping targets like (I do some personal assumptions about overlapping 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)
    )
  )

In this case you should be able to generate all loans when your LT, Am and T is not yet bound to specific values and those isXXX can bind free variables.

ony