otifsolutions / php-sentiment-analysis
Php Sentiment Analysis allows user to analyze sentiments from a text statement
v1.0.2
2020-06-04 08:59 UTC
This package is auto-updated.
Last update: 2025-03-09 13:51:17 UTC
README
Install via Composer
Using Composer (Recommended)
You can run the following command in the root directory of your project:
composer require otifsolutions/php-sentiment-analysis
Usage
-
Php Sentiment Analysis allows to analyze a text statement if it is positive or negative. e.g. comment on any post.
Sentiment::make()->analyze($value);
- Where $value is the statement to be analyzed.
-
Statement may contain labels, emojis and negators.
- Labels are words statement contains e.g.
corruption
,boycott
. - Emoji e.g.
😍
,💖
. - Negators are words that negate something e.g.
doesnt
,not
.
- Labels are words statement contains e.g.
-
We use following methods
-
getTokens
- This method separate the words from the given statement and returns all words.
-
getDataSet
- This method has dataset.
- Labels, emojis and negators already stored in the dataset, which have a positive or negative value.
- For example
"fun": 4, "funeral": -1,
-
This example demonstrates the usage of Php Sentiment Analysis
,
Sentiment::make()->analyze('She is famous, but she hates others.');
{
"score": -1,
"comparative": -0.14285714285714285,
"calculation": [
{"she": 0},{"is": 0},{"famous": 2},{"but": 0},{"she": 0},{"hates": -3},{"others": 0}
],
"tokens": [
"she","is","famous","but","she","hates","others"
],
"positive": [
"famous"
],
"negative": [
"hates"
]
}
Option | Description |
---|---|
score |
Positive or negative value after analysis of given statement. |
tokens |
Tokens are the separated words in a Statement. |
comparative |
Value received when score is divided by count of token. |
calculation |
Words in an array with a positive or negative value, if the word exists in dataset the value will be positive or negative otherwise value will be zero. |
positive |
Shows all positive words from the statement. |
negative |
shows all negative words from the statement. |