2010-09-18 11:11:44 -04:00
|
|
|
<?php
|
|
|
|
namespace Moserware\Skills\FactorGraphs;
|
|
|
|
|
|
|
|
class Variable
|
|
|
|
{
|
|
|
|
private $_name;
|
|
|
|
private $_prior;
|
|
|
|
private $_value;
|
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
public function __construct($name, &$prior)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
$this->_name = "Variable[" . $name . "]";
|
|
|
|
$this->_prior = $prior;
|
|
|
|
$this->resetToPrior();
|
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
public function &getValue()
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-03 19:21:55 -04:00
|
|
|
$value = &$this->_value;
|
2010-09-30 08:25:31 -04:00
|
|
|
return $value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2010-09-25 15:46:23 -04:00
|
|
|
public function setValue(&$value)
|
2010-10-03 19:21:55 -04:00
|
|
|
{
|
2010-10-02 21:15:47 -04:00
|
|
|
$this->_value = &$value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function resetToPrior()
|
|
|
|
{
|
|
|
|
$this->_value = $this->_prior;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DefaultVariable extends Variable
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct("Default", null);
|
|
|
|
}
|
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
public function &getValue()
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-09-30 08:25:31 -04:00
|
|
|
public function setValue(&$value)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class KeyedVariable extends Variable
|
|
|
|
{
|
|
|
|
private $_key;
|
2010-10-02 21:15:47 -04:00
|
|
|
public function __construct(&$key, $name, &$prior)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
parent::__construct($name, $prior);
|
2010-10-02 21:15:47 -04:00
|
|
|
$this->_key = &$key;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2010-10-02 21:15:47 -04:00
|
|
|
public function &getKey()
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2010-10-02 21:15:47 -04:00
|
|
|
$key = &$this->_key;
|
|
|
|
return $key;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|