Sentiment Analysis
Analyze text to identify sentiment as negative, neutral, or positive using natural language processing.
Identifying sentiment expressed in text whether they’re negative, neutral, or positive.
| Group |
|---|
| Negative |
| Neutral |
| Positive |
Identifying sentiment expressed in text
POST https://api.aigen.online/ainlp/sentiment/v1
Request Body
| Name | Type | Description |
|---|---|---|
| text* | String |
- 200: OK Successful response
- 400: Bad Request
{
"group_count": 1,
"group_detail": [
{
"group_name": "Positive",
"rank": 1,
"score": 0.82
}
],
"status": "success"
}
{
"status": "fail"
}
Example code
- Python
- Nodejs
- PHP
- cURL
import requests
import json
api = "https://api.aigen.online/ainlp/sentiment/v1"
headers = {"x-aigen-key": "<key>", "content-type": "application/json"}
data = json.dumps({"text": "ai สามารถช่วยแก้ปัญหาต่าง ๆ ได้"})
res = requests.post(api, data=data, headers=headers)
print(res.json())
const axios = require("axios");
const api = "https://api.aigen.online/ainlp/sentiment/v1";
const headers = {
"x-aigen-key": "<key>",
};
const data = { text: "ai สามารถช่วยแก้ปัญหาต่าง ๆ ได้" };
axios
.post(api, data, { headers: headers })
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.error(err.response.data);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.aigen.online/ainlp/sentiment/v1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'text' => 'ai สามารถช่วยแก้ปัญหาต่าง ๆ ได้'
]),
CURLOPT_HTTPHEADER => array(
'X-AIGEN-KEY: <aigen-key>',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
curl --location 'https://api.aigen.online/ainlp/sentiment/v1' \
--header 'X-AIGEN-KEY: <aigen-key>' \
--header 'Content-Type: application/json' \
--data '{
"text": "ai สามารถช่วยแก้ปัญหาต่าง ๆ ได้"
}'