Ejemplo n.º 1
0
<h1>example b8 interface</h1>


END;
$postedText = "";
if (isset($_POST['action']) and $_POST['text'] == "") {
    echo "<p style=\"color:red;\"><b>Please type in a text!</b></p>\n\n";
} elseif (isset($_POST['action']) and $_POST['text'] != "") {
    $time_start = microtimeFloat();
    # Include the b8 code
    require dirname(__FILE__) . "/../b8/b8.php";
    # Create a new b8 instance
    $b8 = new b8($config_b8, $config_database);
    # Check if everything worked smoothly
    $started_up = $b8->validate();
    if ($started_up !== TRUE) {
        echo "<b>example:</b> Could not initialize b8. error code: {$started_up}";
        exit;
    }
    $text = stripslashes($_POST['text']);
    $postedText = htmlentities($text, ENT_QUOTES, 'UTF-8');
    switch ($_POST['action']) {
        case "Classify":
            echo "<p><b>Spaminess: " . formatRating($b8->classify($text)) . "</b></p>\n";
            break;
        case "Save as Spam":
            $ratingBefore = $b8->classify($text);
            $b8->learn($text, b8::SPAM);
            $ratingAfter = $b8->classify($text);
            echo "<p>Saved the text as Spam</p>\n\n";