Source for file Ruleelement.php

Documentation is available at Ruleelement.php

  1. <?php  if defined('BASEPATH')) exit('No direct script access allowed');
  2. /** 
  3.  * Ruleelement.php
  4.  * @author Greg Swindle <greg@swindle.net>
  5.  * @version 0.2
  6.  * @package Phprules
  7.  */
  8.  
  9. /**
  10.  * Represents an element of a Rule or RuleContext.
  11.  * @package Phprules
  12.  */
  13. abstract class RuleElement {
  14.  /**
  15.  * The name of the RuleElement.
  16.  * @access public
  17.  * @var string 
  18.  */ 
  19.     public $name;
  20. /**
  21.  * Constructor initializes {@link $name}.
  22.  * @access public
  23.  */ 
  24.     public function RuleElement$name {
  25.         $this->name = $name;
  26.     }
  27. /**
  28.  * Constructor initializes {@link $name}.
  29.  * @access public
  30.  */     
  31.     public function __construct$name {
  32.         $this->name = $name;
  33.     }
  34. /**
  35.  * Returns the type of RuleElement.
  36.  * @access public
  37.  * @return string 
  38.  */ 
  39.     public function getType({}
  40. /**
  41.  * Returns the name of the RuleElement.
  42.  * @access public
  43.  * @return string 
  44.  */ 
  45.     public function toString({
  46.         return $this->name;
  47.     }
  48. }
  49.  /**
  50.  * Represents a Boolean operator or a quantifier operator.
  51.  * @package Phprules
  52.  */
  53. class Operator extends RuleElement {
  54. /**
  55.  * The name of the RuleElement.
  56.  * @access private
  57.  * @var array 
  58.  */
  59.     private $operators;
  60.     
  61.     const LOGICAL_OR               = 'OR';
  62.     const LOGICAL_AND              = 'AND';
  63.     const LOGICAL_NOT              = 'NOT';
  64.     const LOGICAL_XOR              = 'XOR';
  65.     const EQUAL_TO                 = 'EQUALTO';
  66.     const NOT_EQUAL_TO             = 'NOTEQUALTO';
  67.     const LESS_THAN                = 'LESSTHAN';
  68.     const LESS_THAN_OR_EQUAL_TO    = 'LESSTHANOREQUALTO';
  69.     const GREATER_THAN             = 'GREATERTHAN';
  70.     const GREATER_THAN_OR_EQUAL_TO = 'GREATERTHANOREQUALTO';
  71.     
  72. /**
  73.  * Constructor initializes {@link $name}, i.e., the operator.
  74.  * @access public
  75.  */     
  76.     function Operator$operator {
  77.         $this->operators array"AND""OR""NOT""XOR""EQUALTO""NOTEQUALTO""LESSTHAN""GREATERTHAN""LESSTHANOREQUALTO""GREATERTHANOREQUALTO" );
  78.         ifin_array$operator$this->operators ) ) {
  79.             parent::Operator$operator );
  80.         }
  81.         else {
  82.             throw new Exception$operator " is not a valid operator." );
  83.         }
  84.     }
  85. /**
  86.  * Constructor initializes {@link $name}, i.e., the operator.
  87.  * @access public
  88.  */ 
  89.     function __construct$operator {
  90.         $this->operators array"AND""OR""NOT""XOR""EQUALTO""NOTEQUALTO""LESSTHAN""GREATERTHAN""LESSTHANOREQUALTO""GREATERTHANOREQUALTO" );
  91.         ifin_array$operator$this->operators ) ) {
  92.             parent::__construct$operator );
  93.         }
  94.         else {
  95.             throw new Exception$operator " is not a valid operator." );
  96.         }
  97.     }
  98. /**
  99.  * Returns "Operator."
  100.  * @access public
  101.  * @return string 
  102.  */
  103.     function getType({
  104.         return "Operator";
  105.     }
  106. }
  107.  /**
  108.  * Represents a Proposition in formal logic, a statement with at truth value.
  109.  * @package Phprules
  110.  */
  111. class Proposition extends RuleElement {
  112. /**
  113.  * The Boolean truth value of the Proposition.
  114.  * @access public
  115.  * @var boolean 
  116.  */
  117.     public $value;
  118. /**
  119.  * Constructor initializes {@link $name}, and the {@link $value}.
  120.  * @access public
  121.  */ 
  122.     function Proposition$name$truthValue {
  123.         $this->value = $truthValue;
  124.         parent::RuleElement$name );
  125.     }
  126. /**
  127.  * Constructor initializes {@link $name}, and the {@link $value}.
  128.  * @access public
  129.  */ 
  130.     function __construct$name$truthValue {
  131.         $this->value = $truthValue;
  132.         parent::RuleElement$name );
  133.     }
  134. /**
  135.  * Returns &quot;Proposition.&quot;
  136.  * @access public
  137.  * @return string 
  138.  */ 
  139.     function getType({
  140.         return "Proposition";
  141.     }
  142. /**
  143.  * Returns a human-readable statement and value.
  144.  * @access public
  145.  * @return string 
  146.  */
  147.     function toString({
  148.         $truthValue "FALSE";
  149.         if$this->value == true {
  150.             $truthValue "TRUE";
  151.         }
  152.         return "Proposition statement = " $this->name . ", value = " $truthValue;
  153.     }
  154. /**
  155.  * Performs a Boolean AND operation on another {@link Proposition}
  156.  * @access public
  157.  * @param Proposition $proposition 
  158.  * @return Proposition 
  159.  */ 
  160.     function logicalAnd$proposition {
  161.         $resultName  "( " $this->name . " AND " $proposition->name " )";
  162.         $resultValue $this->value and $proposition->value );
  163.         return new Proposition$resultName$resultValue );
  164.     }
  165. /**
  166.  * Performs a Boolean OR operation on another {@link Proposition}
  167.  * @access public
  168.  * @param Proposition $proposition 
  169.  * @return Proposition 
  170.  */ 
  171.     function logicalOr$proposition {
  172.         $resultName  "( " $this->name . " OR " $proposition->name " )";
  173.         $resultValue $this->value or $proposition->value );
  174.         return new Proposition$resultName$resultValue );
  175.     }
  176. /**
  177.  * Performs a Boolean NOT operation its own value
  178.  * @access public
  179.  * @return Proposition 
  180.  */  
  181.     function logicalNot({
  182.         $resultName  "( NOT " $this->name . " )";
  183.         $resultValue !$this->value );
  184.         return new Proposition$resultName$resultValue );
  185.     }
  186. /**
  187.  * Performs a Boolean XOR operation on another {@link Proposition}
  188.  * @access public
  189.  * @param Proposition $proposition 
  190.  * @return Proposition 
  191.  */ 
  192.     function logicalXor$proposition {
  193.         $resultName  "( " $this->name . " XOR " $proposition->name " )";
  194.         $resultValue $this->value xor $proposition->value );
  195.         return new Proposition$resultName$resultValue );
  196.     }
  197. }
  198.  /**
  199.  * A symbol that represents a value.
  200.  * @package Phprules
  201.  */
  202. class Variable extends RuleElement {
  203.     var $value;
  204. /**
  205.  * Constructor initializes {@link $name}, and the {@link $value}.
  206.  * @access public
  207.  */     
  208.     function Variable$name$value {
  209.         $this->value = $value;
  210.         parent::RuleElement$name );
  211.     }
  212. /**
  213.  * Constructor initializes {@link $name}, and the {@link $value}.
  214.  * @access public
  215.  */     
  216.     function __construct$name$value {
  217.         $this->value = $value;
  218.         parent::__construct$name );
  219.     }
  220. /**
  221.  * Returns &quot;Variable.&quot;
  222.  * @access public
  223.  * @return string 
  224.  */     
  225.     function getType({
  226.         return "Variable";
  227.     }
  228. /**
  229.  * Returns a human-readable statement and value.
  230.  * @access public
  231.  * @return string 
  232.  */    
  233.     function toString({
  234.         return "Variable name = " $this->name . ", value = " $this->value;
  235.     }
  236. /**
  237.  * Determines whether another Variable's value is equal to its own value.
  238.  * @public
  239.  * @param Variable $variable 
  240.  * @return Proposition 
  241.  */    
  242.     function equalTo$variable {
  243.         $statement "( " $this->name . " == " $variable->name " )";
  244.         $truthValue $this->value == $variable->value );
  245.         return new Proposition$statement$truthValue );
  246.     }
  247. /**
  248.  * Determines whether another Variable's value is <em>not</em> equal to its own value.
  249.  * @public
  250.  * @param Variable $variable 
  251.  * @return Proposition 
  252.  */    
  253.     function notEqualTo$variable {
  254.         $statement "( " $this->name . " != " $variable->name " )";
  255.         $truthValue $this->value != $variable->value );
  256.         return new Proposition$statement$truthValue );
  257.     }
  258. /**
  259.  * Determines whether another Variable's value is less than to its own value.
  260.  * @public
  261.  * @param Variable $variable 
  262.  * @return Proposition 
  263.  */    
  264.     function lessThan$variable {
  265.         $statement "( " $this->name . " < " $variable->name " )";
  266.         $truthValue $this->value < $variable->value );
  267.         return new Proposition$statement$truthValue );
  268.     }
  269. /**
  270.  * Determines whether another Variable's value is less than or equal to to its own value.
  271.  * @public
  272.  * @param Variable $variable 
  273.  * @return Proposition 
  274.  */   
  275.     function lessThanOrEqualTo$variable {
  276.         $statement "( " $this->name . " <= " $variable->name " )";
  277.         $truthValue $this->value <= $variable->value );
  278.         return new Proposition$statement$truthValue );
  279.     }
  280. /**
  281.  * Determines whether another Variable's value is greater than to its own value.
  282.  * @public
  283.  * @param Variable $variable 
  284.  * @return Proposition 
  285.  */
  286.     function greaterThan$variable {
  287.         $statement "( " $this->name . " > " $variable->name " )";
  288.         $truthValue $this->value > $variable->value );
  289.         return new Proposition$statement$truthValue );
  290.     }
  291. /**
  292.  * Determines whether another Variable's value is greater than or equal to its own value.
  293.  * @public
  294.  * @param Variable $variable 
  295.  * @return Proposition 
  296.  */    
  297.     function greaterThanOrEqualTo$variable {
  298.         $statement "( " $this->name . " >= " $variable->name " )";
  299.         $truthValue $this->value >= $variable->value );
  300.         return new Proposition$statement$truthValue );
  301.     }
  302. }
  303.  
  304. /* End of file Ruleelement.php */
  305. /* Location: ./system/application/libraries/Phprules/Ruleelement.php */

Documentation generated on Thu, 24 Mar 2011 21:27:41 -0500 by phpDocumentor 1.4.1