Esempio n. 1
0
function countWordFreq($dataset_file, $wordbank_file = null)
{
    if (!$wordbank_file) {
        $wordbank_file = "w." . $dataset_file;
    }
    readWordBankFromJSON($wordbank_file);
    $fp = fopen($dataset_file . ".csv", "r");
    while (!feof($fp)) {
        $tweet = fgetcsv($fp, 256);
        if ($tweet) {
            $tweet_words = featureExtractor($tweet[1]);
            if ($tweet_words) {
                updatewordBank($tweet_words, $tweet[0]);
            }
        }
    }
    writeWordBankToJSON($wordbank_file);
}
Esempio n. 2
0
function classify($tweet)
{
    //readWordBankFromJSON();
    $tweet_words = featureExtractor($tweet);
    $tweetWord_freq = getTweetWordFreq($tweet_words);
    $result["positive"] = 1;
    $result["negative"] = 1;
    foreach ($tweetWord_freq as $word => $word_freq) {
        //if($word_freq["positive"]!=0)
        $result["positive"] *= $word_freq["positive"] / $word_freq["total"];
        //if($word_freq["negative"]!=0)
        $result["negative"] *= $word_freq["negative"] / $word_freq["total"];
        //$result["positive"]*=10;
        //$result["negative"]*=10;
        //print($result["positive"]." : ".$result["negative"].", ");
    }
    //print("\n");
    return $result;
}