mitmelon / sentiment
Sentiment 是一个情感分类器。它使用被分类为积极、消极或中立的词语模型,以及朴素贝叶斯算法来计算情感。为了提高准确性,Sentiment 会移除 '噪声' 词语。
dev-master
2020-10-15 14:16 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-15 22:47:24 UTC
README
用于从文本中检测情绪的情感分析库。
Sentiment 是一个情感分类器。它使用被分类为积极、消极或中立的词语模型,以及朴素贝叶斯算法来计算情感。为了提高准确性,Sentiment 会移除 '噪声' 词语。
安装
使用 composer 安装
composer require mitmelon/sentiment:dev-master@dev
初始化
require_once __DIR__."/vendor/autoload.php"; // Initialize library class $sentiment = new Sentiment\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"; }
训练现有模型
/** * 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;
未来更新
- 表情识别
许可证
在 MIT 许可证下发布。