Example #1
0
File: test.php Project: 0-php/AI
 *
 */
$spam = new spam("handler");
/**/
$sql = mysql_query("select * from examples", $db);
echo "<h1>Spam test</h1>";
print '<table cellpadding="5" cellspacing="0" width="100%">';
echo "<tr align='center'>";
echo "<td><h1>Text</h1></td>";
echo "<td><h1>Expected</h1></td>";
echo "<td><h1>New Algorithm</h1></td>";
echo "<td><h1>Old Algorithm</h1></td>";
echo "</tr>";
$i = 0;
while ($text = mysql_fetch_array($sql)) {
    $score1 = number_format($spam->isItSpam_v2($text[0], 'spam'), 2);
    $score2 = number_format($spam->isItSpam($text[0], 'spam'), 2);
    echo "<tr bgcolor='" . (++$i % 2 == 0 ? 'white' : '#c0c0c0') . "'>";
    echo "<td width=50%><em><strong>{$text['0']}</strong></em></td>";
    echo "<td width=10%>" . ($text[1] == 1 ? "ham" : "spam") . "</td>";
    echo "<td width=10%>" . ($score1 > 60 ? "spam" : "ham") . " ({$score1} of spam)%</td>";
    echo "<td width=10%>" . ($score2 > 60 ? "spam" : "ham") . " ({$score2}  of spam)%</td>";
    echo "</tr>";
}
print "</table>";
/**
 *  Callback function
 *
 *  This is function is called by the classifier class, and it must 
 *  return all the n-grams.
 *  
Example #2
0
File: example.php Project: 0-php/AI
*/
require "../spam.php";
require "config.php";
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
mysql_select_db(MYSQL_DB, $db);
/**
 *    Because the system do not manage a method where you can save the data, you must define a function which recives
 *    the wanted "n-grams" and return and array which is "n-grams" and percent of accuracy (what its learn with example_trainer).
 *    In this example those datas are loaded from mysql.
 */
$spam = new spam("handler");
/**/
$texts = array("Phentermine", "Buy cheap xxx", "Really nice post", "Viagra", "This a large text, it is not spam, but because the training set\nare small sentenses, it may be marked as spam. You can solve this problem with a largest sentences on the training set.");
echo "<h1>Spam test</h1>";
foreach ($texts as $text) {
    echo "<em><strong>{$text}</strong></em> has an accuraccy of <b>" . $spam->isItSpam_v2($text, 'spam') . "%</b> spam<hr>";
}
echo "<h1>Ham test</h1>";
foreach ($texts as $text) {
    echo "<em><strong>{$text}</strong></em> has an accuraccy of <b>" . $spam->isItSpam_v2($text, '1') . "%</b> ham<hr>";
}
/**
 *  Callback function
 *
 *  This is function is called by the classifier class, and it must return all the n-grams.
 *
 *  @param Array $ngrams N-grams.
 *  @param String $type Type of set to compare
 */
function handler($ngrams, $type)
{