コード例 #1
0
ファイル: initData.php プロジェクト: sdgdsffdsfff/Bayes
                $str = substr($str, 3);
            }
        } else {
            $newStr[] = substr($str, 0, 1);
            $str = substr($str, 1);
        }
    }
    return join('', $newStr);
}
$dataArray = array();
$shortDataArray = array();
$contentArray = array();
$spamSql = 'select distinct content as content from product_report_comments where status=1';
$result = $dbData->query($spamSql);
while ($row = $result->fetch()) {
    $data = array('short' => utfSubstr($row['content']), 'content' => $row['content']);
    array_push($dataArray, $data);
    array_push($shortDataArray, $data['short']);
}
echo count($shortDataArray);
$shortDataArray = array_flip(array_flip($shortDataArray));
echo "\r\n", count($shortDataArray), "\r\n";
foreach ($shortDataArray as $v) {
    foreach ($dataArray as $row) {
        if ($row['short'] == $v) {
            array_push($contentArray, $row['content']);
            break;
        }
    }
}
echo count($contentArray), "\r\n";
コード例 #2
0
            $str = substr($str, 1);
        }
    }
    return join('', $newStr);
}
$endTime = time();
$startTime = $endTime - 86400;
$allWordCounter = $redis->get(COMMENT_WORDS_COUNTER);
$sql = "select content,status,score from product_report_comments where ";
$sql .= "dateline>={$startTime} and dateline<={$endTime}";
$commentContent = $dbRW->master()->queryAll($sql);
foreach ($commentContent as $row) {
    if ($row['score'] >= 90) {
        $spamArray[utfSubstr($row['content'])] = $row;
    } else {
        $healthArray[utfSubstr($row['content'])] = $row;
    }
}
$spamArrayCounter = count($spamArray);
$allSpamWord = array();
$allHealthWord = array();
$counter = 0;
$allArray = array_merge($spamArray, $healthArray);
foreach ($allArray as $row) {
    $key = array();
    $content = $sphinx->EscapeString($row['content']);
    $words = $sphinx->BuildKeywords($content, 'reports', false);
    $num = count($words);
    if ($num) {
        for ($i = 0; $i < $num; $i++) {
            $key[$i] = $words[$i]['tokenized'];