function showTab() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0)); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $ticket = DAO_Ticket::getTicket($ticket_id); $tpl->assign('ticket_id', $ticket_id); $tpl->assign('ticket', $ticket); // Receate the original spam decision $words = DevblocksPlatform::parseCsvString($ticket->interesting_words); $words = DAO_Bayes::lookupWordIds($words); // Calculate word probabilities foreach ($words as $idx => $word) { /* @var $word CerberusBayesWord */ $word->probability = CerberusBayes::calculateWordProbability($word); } $tpl->assign('words', $words); // Determine what the spam probability would be if the decision was made right now $analysis = CerberusBayes::calculateTicketSpamProbability($ticket_id, true); $tpl->assign('analysis', $analysis); $tpl->display('file:' . $tpl_path . 'ticket_tab/index.tpl'); }
/** * @param CerberusBayesWord $word * @return float The probability of the word being spammy. */ public static function calculateWordProbability(CerberusBayesWord $word) { static $stats = null; // [JAS]: [TODO] Keep an eye on this. if (is_null($stats)) { $stats = DAO_Bayes::getStatistics(); } $ngood = max($stats['nonspam'], 1); $nbad = max($stats['spam'], 1); $g = intval($word->nonspam * 1); $b = intval($word->spam); // [JAS]: If less than 5 occurrences total if ($g * 1 + $b < 5) { $prob = self::PROBABILITY_UNKNOWN; } else { $prob = max(self::PROBABILITY_FLOOR, min(self::PROBABILITY_CEILING, floatval(min(1, $b / $nbad) / ($g / $ngood + $b / $nbad)))); } return number_format($prob, 4); }