/** * Destructor */ function __destruct() { if (self::$destroyed == true) { return; } // Avoid cleaning the cache multiple times if (1 == rand(1, 5)) { $this->cleanCache(); } // 1 in 5 chance self::$destroyed = true; }
/** * @param string $document_id document id, must be unique * @return bool */ protected function removeDocument($document_id) { /* Override parent */ $tid = suxDB::requestTransaction(); $this->inTransaction = true; // Remove any links to category documents in associated link tables $links = $this->link->getLinkTables('bayes_documents'); foreach ($links as $tmp) { $this->link->deleteLink($tmp, 'bayes_documents', $document_id); } $_bool = parent::removeDocument($document_id); suxDB::commitTransaction($tid); $this->inTransaction = false; return $_bool; }
<?php // Ajax // Echo the content of a bayesian document if (isset($_POST['id']) && filter_var($_POST['id'], FILTER_VALIDATE_INT)) { require_once dirname(__FILE__) . '/../../config.php'; require_once dirname(__FILE__) . '/../../initialize.php'; $nb = new suxNaiveBayesian(); $doc = $nb->getDocument($_POST['id']); if ($doc) { $text = suxFunct::gtext('bayes'); $tmp = null; $link = new suxLink(); foreach ($link->getLinkTables('bayes_documents') as $table) { $links = $link->getLinks($table, 'bayes_documents', $_POST['id']); if ($links && count($links)) { $table = str_replace('link__', '', $table); $table = str_replace('bayes_documents', '', $table); $table = str_replace('__', '', $table); $tmp .= "[ {$text['to']} {$table}_id -> "; foreach ($links as $val) { $tmp .= " {$val},"; } $tmp = rtrim($tmp, ', '); $tmp .= ' ]'; } } echo '<em>bayes_document_id: ', $_POST['id'], '</em><br />'; if ($tmp) { echo "<em><strong>{$text['is_linked']}</strong></em> "; echo $tmp;
// Echo the categorization of a document // --------------------------------------------------------------------------- // Require // --------------------------------------------------------------------------- require_once dirname(__FILE__) . '/../../config.php'; require_once dirname(__FILE__) . '/../../initialize.php'; $text = suxFunct::gtext('bayes'); // --------------------------------------------------------------------------- // Error checking // --------------------------------------------------------------------------- if (!filter_var(@$_POST['id'], FILTER_VALIDATE_INT)) { echo "<p>{$text['error']}: {$text['form_error_1']}</p>"; exit; } if (!trim(@$_POST['document'])) { echo "<p>{$text['error']}: {$text['form_error_7']}</p>"; exit; } // --------------------------------------------------------------------------- // Generate HTML // --------------------------------------------------------------------------- $nb = new suxNaiveBayesian(); $scores = $nb->categorize($_POST['document'], $_POST['id']); $html = '<p><table border="1">'; $html .= '<thead><tr><th>' . $text['categories'] . '</th><th>' . $text['scores'] . '</th></tr></thead><tbody>' . "\n"; foreach ($scores as $k => $v) { $html .= "<tr><td>{$v['category']}</td><td>" . round($v['score'] * 100, 2) . " %</td></tr>\n"; } $html .= '</tbody></table></p>' . "\n"; $html .= '<p><em>' . $text['categorized_on'] . ' : ' . date('D M j, G:i:s') . '</em></p>'; echo $html;