Что ж, класс Opinion
уже достаточно гибкий для добавления новых "классов настроений".Просто в методе classify
реализован расчет «прежней» статики.Но его можно легко заменить на foreach
:
private $classes = array('pos', 'neg', 'neutr');
private $classTokCounts = array('pos' => 0, 'neg' => 0, 'neutr' => 0);
private $classDocCounts = array('pos' => 0, 'neg' => 0, 'neutr' => 0);
private $prior = array('pos' => 1.0/3.0, 'neg' => 1.0/3.0, 'neutr' => 1.0/3.0);
public function classify($document) {
// remove those:
//$this->prior['pos'] = $this->classDocCounts['pos'] / $this->docCount;
//$this->prior['neg'] = $this->classDocCounts['neg'] / $this->docCount;
// add this:
foreach($this->classes as $class) {
$this->prior[$class] = $this->classDocCounts[$class] / $this->docCount;
}
// the rest is fine