Textrics API Stack


All in one Analysis API Implementation

Using this API one can perform different types of analysis on open end data e.g. a customer review, magazine article, comment or a sentence. The analysis accomplished using this API are Sentiment, Intent, Emotion, Tagging, Offence Check and NER (Named Entity Recognition).

Endpoint

https://api.textrics.ai/sentence_analysis_api.php

We support POST method to communicate with API.

Parameters

1. user_text - This parameter is required
This is the text (sentence) which you wish to send to application to analyse.

2. api_key - This parameter is required
This is used to identify the user and the active subscription plan.

3. api_token - This parameter is required
This is used to authenticate the above user account.

API Script

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $text = trim($_POST['user_text']);			// input variable containing text //
    if($text!='' && is_numeric($text)!=1){
	$apiUrl = 'https://api.textrics.ai/sentence_analysis_api.php';		// API URL //
    $args['user_text'] = $text;
	$args['api_key'] = 'A32NBK55K3'; 		// user specific key to validate the account //
	$args['api_token'] = 'P4lwpqT0YZYSVefSh44ADkvlJ8pesZDI';   // respective token to validate user credentials //

    $options=[
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POSTFIELDS => $args,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_HTTPHEADER => ['Content-Type: multipart/form-data']
      ];
    $ch = curl_init($apiUrl);
    curl_setopt_array($ch, $options);
    $response1 = curl_exec($ch);
    echo $err = curl_error($ch); 
    curl_close($ch);	
    $response =  json_decode($response1,true);		// API output is stored in $response variable //
	}
	else
	{
        $message= 'Error: Input Text is incorrect.';
	}
}

?>

Sample of retrieving the output

<?php
if(!empty($response))
{
	echo "Input Text - ".$text;
	echo "<pre style='text-align:left;'>"; 
	print_r($response);		// Printing the $response output on page //
	echo "</pre>"; 
}
if(!empty($message))
{
	echo $message;
}
?>

Response Format

The response is structured in JSON as follows:

Array
(
    [response] => 1
    [data] => Array
        (
            [0] => Array
                (
                    [Confidence] => 75.3804855347
                    [Module] => Sentiments
                    [Prediction] => Positive
                )
            [1] => Array
                (
                    [Confidence] => 100
                    [Module] => Tags
                    [Prediction] => Array
                        (
                            [0] => happy
                        )
                )
            [2] => Array
                (
                    [Confidence] => 87.893699646
                    [Module] => Emotions
                    [Prediction] => Happy
                )
            [3] => Array
                (
                    [Confidence] => 78.2465057373
                    [Module] => Abusive or non Abuisve
                    [Prediction] => Abusive
                )
            [4] => Array
                (
                    [Confidence] => 55.1882820129
                    [Module] => Intent
                    [Prediction] => Feedback
                )
            [5] => Array
                (
                    [Confidence] => NA
                    [Module] => NER
                    [Prediction] => 
i am happy
[]
                )
        )
    [message] => success
)

API Response Codes

Code Interpretation
1 Success
Exception Codes
10 Authentication Exception
11 Invalid Input Exception
12 Language Exception
13 File Format Error
14 Request Timeout
15 Column Name Mismatch
99 Other Exception