Skip to content

Sentiment is a sentiment classifier. It uses a model of words that are categorised as positive, negative or neutral, and a naive bayes algorithm to calculate sentiment. To improve accuracy, Sentiment removes 'noise' words.

License

Notifications You must be signed in to change notification settings

mitmelon/Sentiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment

Sentiment analysis library for mood detections from text.

Sentiment is a sentiment classifier. It uses a model of words that are categorised as positive, negative or neutral, and a naive bayes algorithm to calculate sentiment. To improve accuracy, Sentiment removes 'noise' words.

Install:

Use composer to install

composer require mitmelon/sentiment:dev-master@dev

Initialise :

require_once __DIR__."/vendor/autoload.php";

// Initialize library class
$sentiment = new Sentiment\Sentiment();

Check for sentiment:

//Beutifies your result
if (PHP_SAPI != 'cli') {
	echo "<pre>";
}
//List of sentences to check
$sentences = array('The boy is very bad', 'I love that girl', 'Some people said i need to take a nap');

foreach ($sentences as $sentence) {
    $scores = $sentiment->score($sentence);
    $class = $sentiment->categorise($sentence);

	// return:
	echo "Sentence : $sentence\n";
    echo "Category: $class\n";
    echo "Scores: ";
    print_r($scores);
	echo "\n";
}

Train existing model:

/**
 * You can train the existing model with new word list
 * Train existing model with word list
 * @param string $class model name to train. Anyone on the list - 'pos', 'neg', 'neu'
 * @return array $wordList training set which must be in one dimensional array
*/
$modelName = 'pos';
$wordList = array('love', 'good');// add your wordlist
$train = $sentiment->training($modelName, $wordList);
echo $train;

Future Update

  • Similey recognitions

License

Released under the MIT license.

About

Sentiment is a sentiment classifier. It uses a model of words that are categorised as positive, negative or neutral, and a naive bayes algorithm to calculate sentiment. To improve accuracy, Sentiment removes 'noise' words.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published