public function guess($text)
{
$scores = array();
$words = $this->parse($text);
$labels = $this->getStorage()->getDistinctLabels();
foreach ($labels as $label) {
$logSum = 0;
foreach ($words as $word) {
$wordTotalCount = $this->getStorage()->getWordCount($word);
if ($wordTotalCount == 0) {
continue;
} else {
$wordProbability = $this->getStorage()->getWordProbabilityWithLabel($word, $label);
$wordInverseProbability = $this->getStorage()->getInverseWordProbabilityWithLabel($word, $label);
/**
* Prevent division with zero
*/
if ($wordProbability + $wordInverseProbability == 0) {
continue;
}
$wordicity = $this->getWordicity($wordTotalCount, $wordProbability, $wordInverseProbability);
}
/**
* logs to avoid "floating point underflow",
*/
$logSum += log(1 - $wordicity) - log($wordicity);
}
/**
* undo the log function and get back to 0-1 range
*/
$scores[$label] = 1 / (1 + exp($logSum));
}
return $scores;
}