PHP Rules

Rule Example: Determine whether an Airline Passenger is Suitable for Upgrade

In this example, we determine whether a given airline passenger is eligible to be upgraded from their coach seat to a first-class seat. To be eligible, a passenger must:

To determine this, we must compare a passenger's facts with our rule.

The Rule

We fetch the rule from our RuleBase, which, for simplicity's sake, is merely a text file with a .rul extension. Its contents are in Reverse Polish Notation (to handle precedence):

# Rule establishing when an airline passenger may be
# allowed to upgrade his/her seat.

passengerIsEconomy IS true      
passengerIsGoldCardHolder IS true
passengerIsSilverCardHolder IS true 
OR
AND
passengerCarryOnBaggageAllowance EQUALS 15.0        
passengerCarryOnBaggageWeight EQUALS 10.0
LESSTHANOREQUALTO       
AND

The Rule Context:

We get facts pertaining to a Rule from our FactBase, which again is simply a text file. Note the difference between a sql.con file and a txt.con file.

passengerIsEconomy IS true      
passengerIsGoldCardHolder IS true
passengerIsSilverCardHolder IS false    
passengerCarryOnBaggageWeight EQUALS 10.0
passengerCarryOnBaggageAllowance EQUALS 15.0        

The Resulting Proposition:

Proposition statement = ( ( passengerCarryOnBaggageWeight <= passengerCarryOnBaggageAllowance ) AND ( ( passengerIsSilverCardHolder OR passengerIsGoldCardHolder ) AND passengerIsEconomy ) ), value = TRUE

Page executed in 0.0210 seconds.